From 6dd45df6bb701912877744d02c78bde214b35b90 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 4 Apr 2016 16:25:21 +1000 Subject: [PATCH] Bug 1264778 - Merge some XPConnect js::Class instances. r=mrbkap. XPC_WN_WithCall_ObjectOps and XPC_WN_NoCall_ObjectOps are both equal to JS_NULL_OBJECT_OPS. As a result, XPC_WN_ModsAllowed_{With,No}Call_Proto_JSClass are identical, as are XPC_WN_NoMods_{With,No}Call_Proto_JSClass. (In both cases, modulo the class name.) This patch merges those identical-except-for-their-name pairs, resulting in XPC_WN_ModsAllowed_Proto_JSClass and XPC_WN_NoMods_Proto_JSClass. --HG-- extra : rebase_source : 64c5990fa5dd09418466ee25a24300bb9cfd3596 --- js/xpconnect/src/XPCWrappedNativeJSOps.cpp | 45 ++++++---------------- js/xpconnect/src/XPCWrappedNativeProto.cpp | 22 +++-------- js/xpconnect/src/xpcprivate.h | 16 ++------ 3 files changed, 20 insertions(+), 63 deletions(-) diff --git a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp index f03cea471203..6c148ed920d3 100644 --- a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp +++ b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp @@ -1169,10 +1169,8 @@ XPC_WN_GetterSetter(JSContext* cx, unsigned argc, Value* vp) static bool XPC_WN_Shared_Proto_Enumerate(JSContext* cx, HandleObject obj) { - MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_ModsAllowed_WithCall_Proto_JSClass || - js::GetObjectClass(obj) == &XPC_WN_ModsAllowed_NoCall_Proto_JSClass || - js::GetObjectClass(obj) == &XPC_WN_NoMods_WithCall_Proto_JSClass || - js::GetObjectClass(obj) == &XPC_WN_NoMods_NoCall_Proto_JSClass, + MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_ModsAllowed_Proto_JSClass || + js::GetObjectClass(obj) == &XPC_WN_NoMods_Proto_JSClass, "bad proto"); XPCWrappedNativeProto* self = (XPCWrappedNativeProto*) xpc_GetJSPrivate(obj); @@ -1235,8 +1233,7 @@ XPC_WN_Shared_Proto_Trace(JSTracer* trc, JSObject* obj) static bool XPC_WN_ModsAllowed_Proto_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvep) { - MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_ModsAllowed_WithCall_Proto_JSClass || - js::GetObjectClass(obj) == &XPC_WN_ModsAllowed_NoCall_Proto_JSClass, + MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_ModsAllowed_Proto_JSClass, "bad proto"); XPCWrappedNativeProto* self = @@ -1276,22 +1273,13 @@ static const js::ClassExtension XPC_WN_Shared_Proto_ClassExtension = { XPC_WN_Shared_Proto_ObjectMoved }; -const js::Class XPC_WN_ModsAllowed_WithCall_Proto_JSClass = { - "XPC_WN_ModsAllowed_WithCall_Proto_JSClass", +const js::Class XPC_WN_ModsAllowed_Proto_JSClass = { + "XPC_WN_ModsAllowed_Proto_JSClass", WRAPPER_FLAGS, &XPC_WN_ModsAllowed_Proto_JSClassOps, JS_NULL_CLASS_SPEC, &XPC_WN_Shared_Proto_ClassExtension, - XPC_WN_WithCall_ObjectOps -}; - -const js::Class XPC_WN_ModsAllowed_NoCall_Proto_JSClass = { - "XPC_WN_ModsAllowed_NoCall_Proto_JSClass", - WRAPPER_FLAGS, - &XPC_WN_ModsAllowed_Proto_JSClassOps, - JS_NULL_CLASS_SPEC, - &XPC_WN_Shared_Proto_ClassExtension, - XPC_WN_NoCall_ObjectOps + JS_NULL_OBJECT_OPS }; /***************************************************************************/ @@ -1300,8 +1288,7 @@ static bool XPC_WN_OnlyIWrite_Proto_AddPropertyStub(JSContext* cx, HandleObject obj, HandleId id, HandleValue v) { - MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_NoMods_WithCall_Proto_JSClass || - js::GetObjectClass(obj) == &XPC_WN_NoMods_NoCall_Proto_JSClass, + MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_NoMods_Proto_JSClass, "bad proto"); XPCWrappedNativeProto* self = @@ -1323,8 +1310,7 @@ XPC_WN_OnlyIWrite_Proto_AddPropertyStub(JSContext* cx, HandleObject obj, HandleI static bool XPC_WN_NoMods_Proto_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvedp) { - MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_NoMods_WithCall_Proto_JSClass || - js::GetObjectClass(obj) == &XPC_WN_NoMods_NoCall_Proto_JSClass, + MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_NoMods_Proto_JSClass, "bad proto"); XPCWrappedNativeProto* self = @@ -1362,22 +1348,13 @@ static const js::ClassOps XPC_WN_NoMods_Proto_JSClassOps = { XPC_WN_Shared_Proto_Trace, // trace }; -const js::Class XPC_WN_NoMods_WithCall_Proto_JSClass = { - "XPC_WN_NoMods_WithCall_Proto_JSClass", +const js::Class XPC_WN_NoMods_Proto_JSClass = { + "XPC_WN_NoMods_Proto_JSClass", WRAPPER_FLAGS, &XPC_WN_NoMods_Proto_JSClassOps, JS_NULL_CLASS_SPEC, &XPC_WN_Shared_Proto_ClassExtension, - XPC_WN_WithCall_ObjectOps -}; - -const js::Class XPC_WN_NoMods_NoCall_Proto_JSClass = { - "XPC_WN_NoMods_NoCall_Proto_JSClass", - WRAPPER_FLAGS, - &XPC_WN_NoMods_Proto_JSClassOps, - JS_NULL_CLASS_SPEC, - &XPC_WN_Shared_Proto_ClassExtension, - XPC_WN_NoCall_ObjectOps + JS_NULL_OBJECT_OPS }; /***************************************************************************/ diff --git a/js/xpconnect/src/XPCWrappedNativeProto.cpp b/js/xpconnect/src/XPCWrappedNativeProto.cpp index ee6655824f4b..8f9e70424297 100644 --- a/js/xpconnect/src/XPCWrappedNativeProto.cpp +++ b/js/xpconnect/src/XPCWrappedNativeProto.cpp @@ -69,23 +69,11 @@ XPCWrappedNativeProto::Init(const XPCNativeScriptableCreateInfo* scriptableCreat return false; } - const js::Class* jsclazz; - - if (mScriptableInfo) { - const XPCNativeScriptableFlags& flags(mScriptableInfo->GetFlags()); - - if (flags.AllowPropModsToPrototype()) { - jsclazz = flags.WantCall() ? - &XPC_WN_ModsAllowed_WithCall_Proto_JSClass : - &XPC_WN_ModsAllowed_NoCall_Proto_JSClass; - } else { - jsclazz = flags.WantCall() ? - &XPC_WN_NoMods_WithCall_Proto_JSClass : - &XPC_WN_NoMods_NoCall_Proto_JSClass; - } - } else { - jsclazz = &XPC_WN_NoMods_NoCall_Proto_JSClass; - } + const js::Class* jsclazz = + (mScriptableInfo && + mScriptableInfo->GetFlags().AllowPropModsToPrototype()) + ? &XPC_WN_ModsAllowed_Proto_JSClass + : &XPC_WN_NoMods_Proto_JSClass; JS::RootedObject global(cx, mScope->GetGlobalJSObject()); JS::RootedObject proto(cx, JS_GetObjectPrototype(cx, global)); diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 852a5b59fdc9..90d1401f7d73 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -926,10 +926,8 @@ private: // visibility from more than one .cpp file. extern const js::Class XPC_WN_NoHelper_JSClass; -extern const js::Class XPC_WN_NoMods_WithCall_Proto_JSClass; -extern const js::Class XPC_WN_NoMods_NoCall_Proto_JSClass; -extern const js::Class XPC_WN_ModsAllowed_WithCall_Proto_JSClass; -extern const js::Class XPC_WN_ModsAllowed_NoCall_Proto_JSClass; +extern const js::Class XPC_WN_NoMods_Proto_JSClass; +extern const js::Class XPC_WN_ModsAllowed_Proto_JSClass; extern const js::Class XPC_WN_Tearoff_JSClass; #define XPC_WN_TEAROFF_RESERVED_SLOTS 1 #define XPC_WN_TEAROFF_FLAT_OBJECT_SLOT 0 @@ -941,19 +939,13 @@ XPC_WN_CallMethod(JSContext* cx, unsigned argc, JS::Value* vp); extern bool XPC_WN_GetterSetter(JSContext* cx, unsigned argc, JS::Value* vp); -// Macros to initialize Object or Function like XPC_WN classes -#define XPC_WN_WithCall_ObjectOps JS_NULL_OBJECT_OPS -#define XPC_WN_NoCall_ObjectOps JS_NULL_OBJECT_OPS - // Maybe this macro should check for class->enumerate == // XPC_WN_Shared_Proto_Enumerate or something rather than checking for // 4 classes? static inline bool IS_PROTO_CLASS(const js::Class* clazz) { - return clazz == &XPC_WN_NoMods_WithCall_Proto_JSClass || - clazz == &XPC_WN_NoMods_NoCall_Proto_JSClass || - clazz == &XPC_WN_ModsAllowed_WithCall_Proto_JSClass || - clazz == &XPC_WN_ModsAllowed_NoCall_Proto_JSClass; + return clazz == &XPC_WN_NoMods_Proto_JSClass || + clazz == &XPC_WN_ModsAllowed_Proto_JSClass; } typedef js::HashSet