diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index b80737f35947..b921ab1be940 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -906,53 +906,14 @@ AtomIsEventHandlerName(nsIAtom *aName) nsIScriptGlobalObject * nsJSContext::GetGlobalObject() { - AutoJSContext cx; - JS::Rooted global(mContext, GetWindowProxy()); - if (!global) { + // Note: this could probably be simplified somewhat more; see bug 974327 + // comments 1 and 3. + if (!mWindowProxy) { return nullptr; } - if (mGlobalObjectRef) - return mGlobalObjectRef; - -#ifdef DEBUG - { - JSObject *inner = JS_ObjectToInnerObject(cx, global); - - // If this assertion hits then it means that we have a window object as - // our global, but we never called CreateOuterObject. - NS_ASSERTION(inner == global, "Shouldn't be able to innerize here"); - } -#endif - - const JSClass *c = JS_GetClass(global); - - nsCOMPtr sgo; - if (IsDOMClass(c)) { - sgo = do_QueryInterface(UnwrapDOMObjectToISupports(global)); - } else { - if ((~c->flags) & (JSCLASS_HAS_PRIVATE | - JSCLASS_PRIVATE_IS_NSISUPPORTS)) { - return nullptr; - } - - nsISupports *priv = static_cast(js::GetObjectPrivate(global)); - - nsCOMPtr wrapped_native = - do_QueryInterface(priv); - if (wrapped_native) { - // The global object is a XPConnect wrapped native, the native in - // the wrapper might be the nsIScriptGlobalObject - - sgo = do_QueryWrappedNative(wrapped_native); - } else { - sgo = do_QueryInterface(priv); - } - } - - // This'll return a pointer to something we're about to release, but - // that's ok, the JS object will hold it alive long enough. - return sgo; + MOZ_ASSERT(mGlobalObjectRef); + return mGlobalObjectRef; } JSContext*