mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-22 02:09:28 +00:00
Bug 855582 part 2. Make the bindings' various spec arrays const, and make the jitinfo structs static. r=khuey
This commit is contained in:
parent
186178f280
commit
203cd29378
@ -156,7 +156,7 @@ ErrorResult::ReportJSException(JSContext* cx)
|
||||
namespace dom {
|
||||
|
||||
bool
|
||||
DefineConstants(JSContext* cx, JSObject* obj, ConstantSpec* cs)
|
||||
DefineConstants(JSContext* cx, JSObject* obj, const ConstantSpec* cs)
|
||||
{
|
||||
for (; cs->name; ++cs) {
|
||||
JSBool ok =
|
||||
@ -170,21 +170,21 @@ DefineConstants(JSContext* cx, JSObject* obj, ConstantSpec* cs)
|
||||
}
|
||||
|
||||
static inline bool
|
||||
Define(JSContext* cx, JSObject* obj, JSFunctionSpec* spec) {
|
||||
Define(JSContext* cx, JSObject* obj, const JSFunctionSpec* spec) {
|
||||
return JS_DefineFunctions(cx, obj, spec);
|
||||
}
|
||||
static inline bool
|
||||
Define(JSContext* cx, JSObject* obj, JSPropertySpec* spec) {
|
||||
Define(JSContext* cx, JSObject* obj, const JSPropertySpec* spec) {
|
||||
return JS_DefineProperties(cx, obj, spec);
|
||||
}
|
||||
static inline bool
|
||||
Define(JSContext* cx, JSObject* obj, ConstantSpec* spec) {
|
||||
Define(JSContext* cx, JSObject* obj, const ConstantSpec* spec) {
|
||||
return DefineConstants(cx, obj, spec);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool
|
||||
DefinePrefable(JSContext* cx, JSObject* obj, Prefable<T>* props)
|
||||
DefinePrefable(JSContext* cx, JSObject* obj, const Prefable<T>* props)
|
||||
{
|
||||
MOZ_ASSERT(props);
|
||||
MOZ_ASSERT(props->specs);
|
||||
@ -201,7 +201,7 @@ DefinePrefable(JSContext* cx, JSObject* obj, Prefable<T>* props)
|
||||
|
||||
bool
|
||||
DefineUnforgeableAttributes(JSContext* cx, JSObject* obj,
|
||||
Prefable<JSPropertySpec>* props)
|
||||
const Prefable<const JSPropertySpec>* props)
|
||||
{
|
||||
return DefinePrefable(cx, obj, props);
|
||||
}
|
||||
@ -745,8 +745,8 @@ XrayResolveOwnProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||
|
||||
static bool
|
||||
XrayResolveAttribute(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||
Prefable<JSPropertySpec>* attributes, jsid* attributeIds,
|
||||
JSPropertySpec* attributeSpecs, JSPropertyDescriptor* desc)
|
||||
const Prefable<const JSPropertySpec>* attributes, jsid* attributeIds,
|
||||
const JSPropertySpec* attributeSpecs, JSPropertyDescriptor* desc)
|
||||
{
|
||||
for (; attributes->specs; ++attributes) {
|
||||
if (attributes->isEnabled(cx, obj)) {
|
||||
@ -755,7 +755,7 @@ XrayResolveAttribute(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||
size_t i = attributes->specs - attributeSpecs;
|
||||
for ( ; attributeIds[i] != JSID_VOID; ++i) {
|
||||
if (id == attributeIds[i]) {
|
||||
JSPropertySpec& attrSpec = attributeSpecs[i];
|
||||
const JSPropertySpec& attrSpec = attributeSpecs[i];
|
||||
// Because of centralization, we need to make sure we fault in the
|
||||
// JitInfos as well. At present, until the JSAPI changes, the easiest
|
||||
// way to do this is wrap them up as functions ourselves.
|
||||
@ -797,9 +797,9 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||
JSPropertyDescriptor* desc, DOMObjectType type,
|
||||
const NativeProperties* nativeProperties)
|
||||
{
|
||||
Prefable<JSFunctionSpec>* methods;
|
||||
const Prefable<const JSFunctionSpec>* methods;
|
||||
jsid* methodIds;
|
||||
JSFunctionSpec* methodsSpecs;
|
||||
const JSFunctionSpec* methodsSpecs;
|
||||
if (type == eInterface) {
|
||||
methods = nativeProperties->staticMethods;
|
||||
methodIds = nativeProperties->staticMethodIds;
|
||||
@ -810,7 +810,7 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||
methodsSpecs = nativeProperties->methodsSpecs;
|
||||
}
|
||||
if (methods) {
|
||||
Prefable<JSFunctionSpec>* method;
|
||||
const Prefable<const JSFunctionSpec>* method;
|
||||
for (method = methods; method->specs; ++method) {
|
||||
if (method->isEnabled(cx, obj)) {
|
||||
// Set i to be the index into our full list of ids/specs that we're
|
||||
@ -818,7 +818,7 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||
size_t i = method->specs - methodsSpecs;
|
||||
for ( ; methodIds[i] != JSID_VOID; ++i) {
|
||||
if (id == methodIds[i]) {
|
||||
JSFunctionSpec& methodSpec = methodsSpecs[i];
|
||||
const JSFunctionSpec& methodSpec = methodsSpecs[i];
|
||||
JSFunction *fun = JS_NewFunctionById(cx, methodSpec.call.op,
|
||||
methodSpec.nargs, 0,
|
||||
wrapper, id);
|
||||
@ -878,7 +878,7 @@ XrayResolveProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
||||
}
|
||||
|
||||
if (nativeProperties->constants) {
|
||||
Prefable<ConstantSpec>* constant;
|
||||
const Prefable<const ConstantSpec>* constant;
|
||||
for (constant = nativeProperties->constants; constant->specs; ++constant) {
|
||||
if (constant->isEnabled(cx, obj)) {
|
||||
// Set i to be the index into our full list of ids/specs that we're
|
||||
@ -998,8 +998,8 @@ XrayResolveNativeProperty(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
||||
|
||||
bool
|
||||
XrayEnumerateAttributes(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
||||
Prefable<JSPropertySpec>* attributes,
|
||||
jsid* attributeIds, JSPropertySpec* attributeSpecs,
|
||||
const Prefable<const JSPropertySpec>* attributes,
|
||||
jsid* attributeIds, const JSPropertySpec* attributeSpecs,
|
||||
unsigned flags, JS::AutoIdVector& props)
|
||||
{
|
||||
for (; attributes->specs; ++attributes) {
|
||||
@ -1025,9 +1025,9 @@ XrayEnumerateProperties(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
||||
DOMObjectType type,
|
||||
const NativeProperties* nativeProperties)
|
||||
{
|
||||
Prefable<JSFunctionSpec>* methods;
|
||||
const Prefable<const JSFunctionSpec>* methods;
|
||||
jsid* methodIds;
|
||||
JSFunctionSpec* methodsSpecs;
|
||||
const JSFunctionSpec* methodsSpecs;
|
||||
if (type == eInterface) {
|
||||
methods = nativeProperties->staticMethods;
|
||||
methodIds = nativeProperties->staticMethodIds;
|
||||
@ -1038,7 +1038,7 @@ XrayEnumerateProperties(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
||||
methodsSpecs = nativeProperties->methodsSpecs;
|
||||
}
|
||||
if (methods) {
|
||||
Prefable<JSFunctionSpec>* method;
|
||||
const Prefable<const JSFunctionSpec>* method;
|
||||
for (method = methods; method->specs; ++method) {
|
||||
if (method->isEnabled(cx, obj)) {
|
||||
// Set i to be the index into our full list of ids/specs that we're
|
||||
@ -1084,7 +1084,7 @@ XrayEnumerateProperties(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
||||
}
|
||||
|
||||
if (nativeProperties->constants) {
|
||||
Prefable<ConstantSpec>* constant;
|
||||
const Prefable<const ConstantSpec>* constant;
|
||||
for (constant = nativeProperties->constants; constant->specs; ++constant) {
|
||||
if (constant->isEnabled(cx, obj)) {
|
||||
// Set i to be the index into our full list of ids/specs that we're
|
||||
|
@ -277,7 +277,7 @@ DestroyProtoAndIfaceCache(JSObject* obj)
|
||||
* Add constants to an object.
|
||||
*/
|
||||
bool
|
||||
DefineConstants(JSContext* cx, JSObject* obj, ConstantSpec* cs);
|
||||
DefineConstants(JSContext* cx, JSObject* obj, const ConstantSpec* cs);
|
||||
|
||||
struct JSNativeHolder
|
||||
{
|
||||
@ -345,7 +345,7 @@ CreateInterfaceObjects(JSContext* cx, JSObject* global, JSObject* protoProto,
|
||||
*/
|
||||
bool
|
||||
DefineUnforgeableAttributes(JSContext* cx, JSObject* obj,
|
||||
Prefable<JSPropertySpec>* props);
|
||||
const Prefable<const JSPropertySpec>* props);
|
||||
|
||||
bool
|
||||
DefineWebIDLBindingPropertiesOnXPCProto(JSContext* cx, JSObject* proto, const NativeProperties* properties);
|
||||
@ -1185,7 +1185,7 @@ InternJSString(JSContext* cx, jsid& id, const char* chars)
|
||||
// Spec needs a name property
|
||||
template <typename Spec>
|
||||
static bool
|
||||
InitIds(JSContext* cx, Prefable<Spec>* prefableSpecs, jsid* ids)
|
||||
InitIds(JSContext* cx, const Prefable<Spec>* prefableSpecs, jsid* ids)
|
||||
{
|
||||
MOZ_ASSERT(prefableSpecs);
|
||||
MOZ_ASSERT(prefableSpecs->specs);
|
||||
|
@ -1261,9 +1261,11 @@ class PropertyDefiner:
|
||||
specs.append(specTerminator)
|
||||
prefableSpecs.append(" { false, NULL }");
|
||||
|
||||
specType = "const " + specType
|
||||
arrays = (("static %s %s_specs[] = {\n" +
|
||||
',\n'.join(specs) + "\n" +
|
||||
"};\n\n" +
|
||||
"// Can't be const because the pref-enabled boolean needs to be writable\n"
|
||||
"static Prefable<%s> %s[] = {\n" +
|
||||
',\n'.join(prefableSpecs) + "\n" +
|
||||
"};\n\n") % (specType, name, specType, name))
|
||||
@ -4769,7 +4771,7 @@ class CGMemberJITInfo(CGThing):
|
||||
returnType = reduce(CGMemberJITInfo.getSingleReturnType, returnTypes,
|
||||
"")
|
||||
return ("\n"
|
||||
"const JSJitInfo %s = {\n"
|
||||
"static const JSJitInfo %s = {\n"
|
||||
" %s,\n"
|
||||
" %s,\n"
|
||||
" %s,\n"
|
||||
|
@ -70,7 +70,7 @@ typedef bool (*PropertyEnabled)(JSContext* cx, JSObject* global);
|
||||
|
||||
template<typename T>
|
||||
struct Prefable {
|
||||
inline bool isEnabled(JSContext* cx, JSObject* obj) {
|
||||
inline bool isEnabled(JSContext* cx, JSObject* obj) const {
|
||||
return enabled &&
|
||||
(!enabledFunc ||
|
||||
enabledFunc(cx, js::GetGlobalForObjectCrossCompartment(obj)));
|
||||
@ -85,29 +85,29 @@ struct Prefable {
|
||||
// Array of specs, terminated in whatever way is customary for T.
|
||||
// Null to indicate a end-of-array for Prefable, when such an
|
||||
// indicator is needed.
|
||||
T* specs;
|
||||
const T* specs;
|
||||
};
|
||||
|
||||
struct NativeProperties
|
||||
{
|
||||
Prefable<JSFunctionSpec>* staticMethods;
|
||||
const Prefable<const JSFunctionSpec>* staticMethods;
|
||||
jsid* staticMethodIds;
|
||||
JSFunctionSpec* staticMethodsSpecs;
|
||||
Prefable<JSPropertySpec>* staticAttributes;
|
||||
const JSFunctionSpec* staticMethodsSpecs;
|
||||
const Prefable<const JSPropertySpec>* staticAttributes;
|
||||
jsid* staticAttributeIds;
|
||||
JSPropertySpec* staticAttributeSpecs;
|
||||
Prefable<JSFunctionSpec>* methods;
|
||||
const JSPropertySpec* staticAttributeSpecs;
|
||||
const Prefable<const JSFunctionSpec>* methods;
|
||||
jsid* methodIds;
|
||||
JSFunctionSpec* methodsSpecs;
|
||||
Prefable<JSPropertySpec>* attributes;
|
||||
const JSFunctionSpec* methodsSpecs;
|
||||
const Prefable<const JSPropertySpec>* attributes;
|
||||
jsid* attributeIds;
|
||||
JSPropertySpec* attributeSpecs;
|
||||
Prefable<JSPropertySpec>* unforgeableAttributes;
|
||||
const JSPropertySpec* attributeSpecs;
|
||||
const Prefable<const JSPropertySpec>* unforgeableAttributes;
|
||||
jsid* unforgeableAttributeIds;
|
||||
JSPropertySpec* unforgeableAttributeSpecs;
|
||||
Prefable<ConstantSpec>* constants;
|
||||
const JSPropertySpec* unforgeableAttributeSpecs;
|
||||
const Prefable<const ConstantSpec>* constants;
|
||||
jsid* constantIds;
|
||||
ConstantSpec* constantSpecs;
|
||||
const ConstantSpec* constantSpecs;
|
||||
};
|
||||
|
||||
struct NativePropertiesHolder
|
||||
|
@ -301,6 +301,8 @@ customMethodCalls = {
|
||||
}
|
||||
|
||||
newBindingProperties = {
|
||||
# Once the last entry here goes away, we can make the sNativePropertyHooks
|
||||
# of bindings static.
|
||||
'nsIDOMNode': 'mozilla::dom::NodeBinding::sNativePropertyHooks.mNativeProperties.regular',
|
||||
'nsIDOMElement': 'mozilla::dom::ElementBinding::sNativePropertyHooks.mNativeProperties.regular',
|
||||
'nsIDOMHTMLElement': 'mozilla::dom::HTMLElementBinding::sNativePropertyHooks.mNativeProperties.regular',
|
||||
|
Loading…
x
Reference in New Issue
Block a user