mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 838691 part 1. Add support in Prefable for calling a function to determine whether a property should be exposed in a WebIDL binding. r=peterv
This commit is contained in:
parent
0ae0788482
commit
e6e9097009
@ -185,7 +185,7 @@ DefinePrefable(JSContext* cx, JSObject* obj, Prefable<T>* props)
|
|||||||
MOZ_ASSERT(props->specs);
|
MOZ_ASSERT(props->specs);
|
||||||
do {
|
do {
|
||||||
// Define if enabled
|
// Define if enabled
|
||||||
if (props->enabled) {
|
if (props->isEnabled(cx, obj)) {
|
||||||
if (!Define(cx, obj, props->specs)) {
|
if (!Define(cx, obj, props->specs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -698,12 +698,12 @@ XrayResolveOwnProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
XrayResolveAttribute(JSContext* cx, JSObject* wrapper, jsid id,
|
XrayResolveAttribute(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||||
Prefable<JSPropertySpec>* attributes, jsid* attributeIds,
|
Prefable<JSPropertySpec>* attributes, jsid* attributeIds,
|
||||||
JSPropertySpec* attributeSpecs, JSPropertyDescriptor* desc)
|
JSPropertySpec* attributeSpecs, JSPropertyDescriptor* desc)
|
||||||
{
|
{
|
||||||
for (; attributes->specs; ++attributes) {
|
for (; attributes->specs; ++attributes) {
|
||||||
if (attributes->enabled) {
|
if (attributes->isEnabled(cx, obj)) {
|
||||||
// Set i to be the index into our full list of ids/specs that we're
|
// Set i to be the index into our full list of ids/specs that we're
|
||||||
// looking at now.
|
// looking at now.
|
||||||
size_t i = attributes->specs - attributeSpecs;
|
size_t i = attributes->specs - attributeSpecs;
|
||||||
@ -747,7 +747,7 @@ XrayResolveAttribute(JSContext* cx, JSObject* wrapper, jsid id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
XrayResolveProperty(JSContext* cx, JSObject* wrapper, jsid id,
|
XrayResolveProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||||
JSPropertyDescriptor* desc, DOMObjectType type,
|
JSPropertyDescriptor* desc, DOMObjectType type,
|
||||||
const NativeProperties* nativeProperties)
|
const NativeProperties* nativeProperties)
|
||||||
{
|
{
|
||||||
@ -766,7 +766,7 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, jsid id,
|
|||||||
if (methods) {
|
if (methods) {
|
||||||
Prefable<JSFunctionSpec>* method;
|
Prefable<JSFunctionSpec>* method;
|
||||||
for (method = methods; method->specs; ++method) {
|
for (method = methods; method->specs; ++method) {
|
||||||
if (method->enabled) {
|
if (method->isEnabled(cx, obj)) {
|
||||||
// Set i to be the index into our full list of ids/specs that we're
|
// Set i to be the index into our full list of ids/specs that we're
|
||||||
// looking at now.
|
// looking at now.
|
||||||
size_t i = method->specs - methodsSpecs;
|
size_t i = method->specs - methodsSpecs;
|
||||||
@ -795,7 +795,7 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, jsid id,
|
|||||||
|
|
||||||
if (type == eInterface) {
|
if (type == eInterface) {
|
||||||
if (nativeProperties->staticAttributes) {
|
if (nativeProperties->staticAttributes) {
|
||||||
if (!XrayResolveAttribute(cx, wrapper, id,
|
if (!XrayResolveAttribute(cx, wrapper, obj, id,
|
||||||
nativeProperties->staticAttributes,
|
nativeProperties->staticAttributes,
|
||||||
nativeProperties->staticAttributeIds,
|
nativeProperties->staticAttributeIds,
|
||||||
nativeProperties->staticAttributeSpecs, desc)) {
|
nativeProperties->staticAttributeSpecs, desc)) {
|
||||||
@ -807,7 +807,7 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, jsid id,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (nativeProperties->attributes) {
|
if (nativeProperties->attributes) {
|
||||||
if (!XrayResolveAttribute(cx, wrapper, id,
|
if (!XrayResolveAttribute(cx, wrapper, obj, id,
|
||||||
nativeProperties->attributes,
|
nativeProperties->attributes,
|
||||||
nativeProperties->attributeIds,
|
nativeProperties->attributeIds,
|
||||||
nativeProperties->attributeSpecs, desc)) {
|
nativeProperties->attributeSpecs, desc)) {
|
||||||
@ -818,7 +818,7 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, jsid id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nativeProperties->unforgeableAttributes) {
|
if (nativeProperties->unforgeableAttributes) {
|
||||||
if (!XrayResolveAttribute(cx, wrapper, id,
|
if (!XrayResolveAttribute(cx, wrapper, obj, id,
|
||||||
nativeProperties->unforgeableAttributes,
|
nativeProperties->unforgeableAttributes,
|
||||||
nativeProperties->unforgeableAttributeIds,
|
nativeProperties->unforgeableAttributeIds,
|
||||||
nativeProperties->unforgeableAttributeSpecs,
|
nativeProperties->unforgeableAttributeSpecs,
|
||||||
@ -834,7 +834,7 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, jsid id,
|
|||||||
if (nativeProperties->constants) {
|
if (nativeProperties->constants) {
|
||||||
Prefable<ConstantSpec>* constant;
|
Prefable<ConstantSpec>* constant;
|
||||||
for (constant = nativeProperties->constants; constant->specs; ++constant) {
|
for (constant = nativeProperties->constants; constant->specs; ++constant) {
|
||||||
if (constant->enabled) {
|
if (constant->isEnabled(cx, obj)) {
|
||||||
// Set i to be the index into our full list of ids/specs that we're
|
// Set i to be the index into our full list of ids/specs that we're
|
||||||
// looking at now.
|
// looking at now.
|
||||||
size_t i = constant->specs - nativeProperties->constantSpecs;
|
size_t i = constant->specs - nativeProperties->constantSpecs;
|
||||||
@ -901,7 +901,7 @@ XrayResolveNativeProperty(JSContext* cx, JSObject* wrapper,
|
|||||||
nativePropertyHooks->mNativeProperties;
|
nativePropertyHooks->mNativeProperties;
|
||||||
|
|
||||||
if (nativeProperties.regular &&
|
if (nativeProperties.regular &&
|
||||||
!XrayResolveProperty(cx, wrapper, id, desc, type,
|
!XrayResolveProperty(cx, wrapper, obj, id, desc, type,
|
||||||
nativeProperties.regular)) {
|
nativeProperties.regular)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -909,7 +909,7 @@ XrayResolveNativeProperty(JSContext* cx, JSObject* wrapper,
|
|||||||
if (!desc->obj &&
|
if (!desc->obj &&
|
||||||
nativeProperties.chromeOnly &&
|
nativeProperties.chromeOnly &&
|
||||||
xpc::AccessCheck::isChrome(js::GetObjectCompartment(wrapper)) &&
|
xpc::AccessCheck::isChrome(js::GetObjectCompartment(wrapper)) &&
|
||||||
!XrayResolveProperty(cx, wrapper, id, desc, type,
|
!XrayResolveProperty(cx, wrapper, obj, id, desc, type,
|
||||||
nativeProperties.chromeOnly)) {
|
nativeProperties.chromeOnly)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -951,12 +951,13 @@ XrayResolveNativeProperty(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
XrayEnumerateAttributes(Prefable<JSPropertySpec>* attributes,
|
XrayEnumerateAttributes(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
||||||
|
Prefable<JSPropertySpec>* attributes,
|
||||||
jsid* attributeIds, JSPropertySpec* attributeSpecs,
|
jsid* attributeIds, JSPropertySpec* attributeSpecs,
|
||||||
unsigned flags, JS::AutoIdVector& props)
|
unsigned flags, JS::AutoIdVector& props)
|
||||||
{
|
{
|
||||||
for (; attributes->specs; ++attributes) {
|
for (; attributes->specs; ++attributes) {
|
||||||
if (attributes->enabled) {
|
if (attributes->isEnabled(cx, obj)) {
|
||||||
// Set i to be the index into our full list of ids/specs that we're
|
// Set i to be the index into our full list of ids/specs that we're
|
||||||
// looking at now.
|
// looking at now.
|
||||||
size_t i = attributes->specs - attributeSpecs;
|
size_t i = attributes->specs - attributeSpecs;
|
||||||
@ -973,7 +974,8 @@ XrayEnumerateAttributes(Prefable<JSPropertySpec>* attributes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
XrayEnumerateProperties(unsigned flags, JS::AutoIdVector& props,
|
XrayEnumerateProperties(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
||||||
|
unsigned flags, JS::AutoIdVector& props,
|
||||||
DOMObjectType type,
|
DOMObjectType type,
|
||||||
const NativeProperties* nativeProperties)
|
const NativeProperties* nativeProperties)
|
||||||
{
|
{
|
||||||
@ -992,7 +994,7 @@ XrayEnumerateProperties(unsigned flags, JS::AutoIdVector& props,
|
|||||||
if (methods) {
|
if (methods) {
|
||||||
Prefable<JSFunctionSpec>* method;
|
Prefable<JSFunctionSpec>* method;
|
||||||
for (method = methods; method->specs; ++method) {
|
for (method = methods; method->specs; ++method) {
|
||||||
if (method->enabled) {
|
if (method->isEnabled(cx, obj)) {
|
||||||
// Set i to be the index into our full list of ids/specs that we're
|
// Set i to be the index into our full list of ids/specs that we're
|
||||||
// looking at now.
|
// looking at now.
|
||||||
size_t i = method->specs - methodsSpecs;
|
size_t i = method->specs - methodsSpecs;
|
||||||
@ -1009,7 +1011,8 @@ XrayEnumerateProperties(unsigned flags, JS::AutoIdVector& props,
|
|||||||
|
|
||||||
if (type == eInterface) {
|
if (type == eInterface) {
|
||||||
if (nativeProperties->staticAttributes &&
|
if (nativeProperties->staticAttributes &&
|
||||||
!XrayEnumerateAttributes(nativeProperties->staticAttributes,
|
!XrayEnumerateAttributes(cx, wrapper, obj,
|
||||||
|
nativeProperties->staticAttributes,
|
||||||
nativeProperties->staticAttributeIds,
|
nativeProperties->staticAttributeIds,
|
||||||
nativeProperties->staticAttributeSpecs,
|
nativeProperties->staticAttributeSpecs,
|
||||||
flags, props)) {
|
flags, props)) {
|
||||||
@ -1017,14 +1020,16 @@ XrayEnumerateProperties(unsigned flags, JS::AutoIdVector& props,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (nativeProperties->attributes &&
|
if (nativeProperties->attributes &&
|
||||||
!XrayEnumerateAttributes(nativeProperties->attributes,
|
!XrayEnumerateAttributes(cx, wrapper, obj,
|
||||||
|
nativeProperties->attributes,
|
||||||
nativeProperties->attributeIds,
|
nativeProperties->attributeIds,
|
||||||
nativeProperties->attributeSpecs,
|
nativeProperties->attributeSpecs,
|
||||||
flags, props)) {
|
flags, props)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (nativeProperties->unforgeableAttributes &&
|
if (nativeProperties->unforgeableAttributes &&
|
||||||
!XrayEnumerateAttributes(nativeProperties->unforgeableAttributes,
|
!XrayEnumerateAttributes(cx, wrapper, obj,
|
||||||
|
nativeProperties->unforgeableAttributes,
|
||||||
nativeProperties->unforgeableAttributeIds,
|
nativeProperties->unforgeableAttributeIds,
|
||||||
nativeProperties->unforgeableAttributeSpecs,
|
nativeProperties->unforgeableAttributeSpecs,
|
||||||
flags, props)) {
|
flags, props)) {
|
||||||
@ -1035,7 +1040,7 @@ XrayEnumerateProperties(unsigned flags, JS::AutoIdVector& props,
|
|||||||
if (nativeProperties->constants) {
|
if (nativeProperties->constants) {
|
||||||
Prefable<ConstantSpec>* constant;
|
Prefable<ConstantSpec>* constant;
|
||||||
for (constant = nativeProperties->constants; constant->specs; ++constant) {
|
for (constant = nativeProperties->constants; constant->specs; ++constant) {
|
||||||
if (constant->enabled) {
|
if (constant->isEnabled(cx, obj)) {
|
||||||
// Set i to be the index into our full list of ids/specs that we're
|
// Set i to be the index into our full list of ids/specs that we're
|
||||||
// looking at now.
|
// looking at now.
|
||||||
size_t i = constant->specs - nativeProperties->constantSpecs;
|
size_t i = constant->specs - nativeProperties->constantSpecs;
|
||||||
@ -1074,13 +1079,15 @@ XrayEnumerateNativeProperties(JSContext* cx, JSObject* wrapper,
|
|||||||
nativePropertyHooks->mNativeProperties;
|
nativePropertyHooks->mNativeProperties;
|
||||||
|
|
||||||
if (nativeProperties.regular &&
|
if (nativeProperties.regular &&
|
||||||
!XrayEnumerateProperties(flags, props, type, nativeProperties.regular)) {
|
!XrayEnumerateProperties(cx, wrapper, obj, flags, props, type,
|
||||||
|
nativeProperties.regular)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nativeProperties.chromeOnly &&
|
if (nativeProperties.chromeOnly &&
|
||||||
xpc::AccessCheck::isChrome(js::GetObjectCompartment(wrapper)) &&
|
xpc::AccessCheck::isChrome(js::GetObjectCompartment(wrapper)) &&
|
||||||
!XrayEnumerateProperties(flags, props, type, nativeProperties.chromeOnly)) {
|
!XrayEnumerateProperties(cx, wrapper, obj, flags, props, type,
|
||||||
|
nativeProperties.chromeOnly)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1086,7 +1086,7 @@ class PropertyDefiner:
|
|||||||
specs = []
|
specs = []
|
||||||
prefableSpecs = []
|
prefableSpecs = []
|
||||||
|
|
||||||
prefableTemplate = ' { true, &%s[%d] }'
|
prefableTemplate = ' { true, nullptr, &%s[%d] }'
|
||||||
prefCacheTemplate = '&%s[%d].enabled'
|
prefCacheTemplate = '&%s[%d].enabled'
|
||||||
def switchToPref(props, pref):
|
def switchToPref(props, pref):
|
||||||
# Remember the info about where our pref-controlled
|
# Remember the info about where our pref-controlled
|
||||||
|
@ -62,10 +62,22 @@ struct ConstantSpec
|
|||||||
JS::Value value;
|
JS::Value value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef bool (*PropertyEnabled)(JSContext* cx, JSObject* global);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Prefable {
|
struct Prefable {
|
||||||
|
inline bool isEnabled(JSContext* cx, JSObject* obj) {
|
||||||
|
return enabled &&
|
||||||
|
(!enabledFunc ||
|
||||||
|
enabledFunc(cx, js::GetGlobalForObjectCrossCompartment(obj)));
|
||||||
|
}
|
||||||
|
|
||||||
// A boolean indicating whether this set of specs is enabled
|
// A boolean indicating whether this set of specs is enabled
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
// A function pointer to a function that can say the property is disabled
|
||||||
|
// even if "enabled" is set to true. If the pointer is null the value of
|
||||||
|
// "enabled" is used as-is.
|
||||||
|
PropertyEnabled enabledFunc;
|
||||||
// Array of specs, terminated in whatever way is customary for T.
|
// Array of specs, terminated in whatever way is customary for T.
|
||||||
// Null to indicate a end-of-array for Prefable, when such an
|
// Null to indicate a end-of-array for Prefable, when such an
|
||||||
// indicator is needed.
|
// indicator is needed.
|
||||||
|
Loading…
Reference in New Issue
Block a user