From f43e9eb936f887ccf64e68b0d5233ce8b969850b Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Mon, 5 Mar 2012 15:22:44 -0800 Subject: [PATCH] Bug 720580 - Introduce a flag for global natives and assert that we have it. r=mrbkap --- dom/base/nsDOMClassInfo.cpp | 3 ++- js/xpconnect/idl/nsIXPCScriptable.idl | 2 +- js/xpconnect/src/XPCRuntimeService.cpp | 1 + js/xpconnect/src/nsXPConnect.cpp | 1 + js/xpconnect/src/xpcprivate.h | 23 +++++++++++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index ab005304e85..d671508d33f 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -548,6 +548,7 @@ static const char kDOMStringBundleURL[] = nsIXPCScriptable::WANT_ENUMERATE | \ nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE | \ nsIXPCScriptable::USE_STUB_EQUALITY_HOOK | \ + nsIXPCScriptable::IS_GLOBAL_OBJECT | \ nsIXPCScriptable::WANT_OUTER_OBJECT) #define NODE_SCRIPTABLE_FLAGS \ @@ -1549,7 +1550,7 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(AnimationEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(ContentFrameMessageManager, nsEventTargetSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::IS_GLOBAL_OBJECT) NS_DEFINE_CLASSINFO_DATA(FormData, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) diff --git a/js/xpconnect/idl/nsIXPCScriptable.idl b/js/xpconnect/idl/nsIXPCScriptable.idl index aacc8ba603d..eac8f4e9ffb 100644 --- a/js/xpconnect/idl/nsIXPCScriptable.idl +++ b/js/xpconnect/idl/nsIXPCScriptable.idl @@ -102,7 +102,7 @@ interface nsIXPCScriptable : nsISupports const PRUint32 CLASSINFO_INTERFACES_ONLY = 1 << 23; const PRUint32 ALLOW_PROP_MODS_DURING_RESOLVE = 1 << 24; const PRUint32 ALLOW_PROP_MODS_TO_PROTOTYPE = 1 << 25; - // Unused bit here! + const PRUint32 IS_GLOBAL_OBJECT = 1 << 26; const PRUint32 DONT_REFLECT_INTERFACE_NAMES = 1 << 27; const PRUint32 WANT_EQUALITY = 1 << 28; const PRUint32 WANT_OUTER_OBJECT = 1 << 29; diff --git a/js/xpconnect/src/XPCRuntimeService.cpp b/js/xpconnect/src/XPCRuntimeService.cpp index 33b5572ec96..0ff7dc4ff78 100644 --- a/js/xpconnect/src/XPCRuntimeService.cpp +++ b/js/xpconnect/src/XPCRuntimeService.cpp @@ -63,6 +63,7 @@ NS_IMPL_THREADSAFE_RELEASE(BackstagePass) nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY | \ nsIXPCScriptable::DONT_ENUM_STATIC_PROPS | \ nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE | \ + nsIXPCScriptable::IS_GLOBAL_OBJECT | \ nsIXPCScriptable::DONT_REFLECT_INTERFACE_NAMES #include "xpc_map_end.h" /* This will #undef the above */ diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 82fff2e41af..0d923935fe0 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -1266,6 +1266,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext, nsresult rv; xpcObjectHelper helper(aCOMObj); + MOZ_ASSERT(helper.GetScriptableFlags() & nsIXPCScriptable::IS_GLOBAL_OBJECT); if (!XPCConvert::NativeInterface2JSObject(ccx, &v, getter_AddRefs(holder), helper, &aIID, nsnull, diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 76a9d11a0d8..02a0b34719c 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -48,6 +48,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" +#include "mozilla/Util.h" #include #include @@ -2021,6 +2022,7 @@ public: JSBool ClassInfoInterfacesOnly() GET_IT(CLASSINFO_INTERFACES_ONLY) JSBool AllowPropModsDuringResolve() GET_IT(ALLOW_PROP_MODS_DURING_RESOLVE) JSBool AllowPropModsToPrototype() GET_IT(ALLOW_PROP_MODS_TO_PROTOTYPE) + JSBool IsGlobalObject() GET_IT(IS_GLOBAL_OBJECT) JSBool DontReflectInterfaceNames() GET_IT(DONT_REFLECT_INTERFACE_NAMES) JSBool UseStubEqualityHook() GET_IT(USE_STUB_EQUALITY_HOOK) @@ -3179,6 +3181,27 @@ public: return mXPCClassInfo.forget(); } + // We assert that we can reach an nsIXPCScriptable somehow. + PRUint32 GetScriptableFlags() + { + // Try getting an nsXPCClassInfo - this handles DOM scriptable helpers. + nsCOMPtr sinfo = GetXPCClassInfo(); + + // If that didn't work, try just QI-ing. This handles BackstagePass. + if (!sinfo) + sinfo = do_QueryInterface(GetCanonical()); + + // We should have something by now. + MOZ_ASSERT(sinfo); + + // Grab the flags. This should not fail. + PRUint32 flags; + mozilla::DebugOnly rv = sinfo->GetScriptableFlags(&flags); + MOZ_ASSERT(NS_SUCCEEDED(rv)); + + return flags; + } + nsWrapperCache *GetWrapperCache() { return mCache;