diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 9f6b5c70962f..75e09b1385ec 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2048,8 +2048,9 @@ nsGlobalWindow::SetOuterObject(JSContext* aCx, JS::Handle aOuterObjec { JSAutoCompartment ac(aCx, aOuterObject); - // Indicate the default compartment object associated with this cx. - js::SetDefaultObjectForContext(aCx, aOuterObject); + // Inform the nsJSContext, which is the canonical holder of the outer. + MOZ_ASSERT(IsOuterWindow()); + mContext->SetWindowProxy(aOuterObject); // Set up the prototype for the outer object. JS::Rooted inner(aCx, JS_GetParent(aOuterObject)); @@ -2445,11 +2446,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, newInnerWindow->FastGetGlobalJSObject()); #endif - // Now that we're connecting the outer global to the inner one, - // we must have transplanted it. The JS engine tries to maintain - // the global object's compartment as its default compartment, - // so update that now since it might have changed. - js::SetDefaultObjectForContext(cx, mJSObject); + MOZ_ASSERT(mContext->GetWindowProxy() == mJSObject); #ifdef DEBUG JS::Rooted rootedJSObject(cx, mJSObject); JS::Rooted proto1(cx), proto2(cx); diff --git a/dom/base/nsIScriptContext.h b/dom/base/nsIScriptContext.h index 5c72e4781526..2b7e0c53cbe4 100644 --- a/dom/base/nsIScriptContext.h +++ b/dom/base/nsIScriptContext.h @@ -27,8 +27,8 @@ class nsIDOMWindow; class nsIURI; #define NS_ISCRIPTCONTEXT_IID \ -{ 0x1d931a17, 0x453a, 0x47fb, \ - { 0x94, 0x66, 0x2d, 0x3e, 0xd1, 0xef, 0x7a, 0xc5 } } +{ 0x03c0874e, 0xcb49, 0x41c8, \ + { 0xa3, 0x0b, 0xef, 0x3e, 0xc1, 0x88, 0xb1, 0x1f } } /* This MUST match JSVERSION_DEFAULT. This version stuff if we don't know what language we have is a little silly... */ @@ -165,6 +165,12 @@ public: * Tell the context we're done reinitializing it. */ virtual void DidInitializeContext() = 0; + + /** + * Access the Window Proxy. The setter should only be called by nsGlobalWindow. + */ + virtual void SetWindowProxy(JS::Handle aWindowProxy) = 0; + virtual JSObject* GetWindowProxy() = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContext, NS_ISCRIPTCONTEXT_IID) diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index e66aa0d16237..488ef3d96002 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -1137,7 +1137,7 @@ nsJSContext::GetGlobalObject() JSObject* nsJSContext::GetNativeGlobal() { - return js::DefaultObjectForContextOrNull(mContext); + return GetWindowProxy(); } JSContext* @@ -2581,6 +2581,18 @@ nsJSContext::ReportPendingException() } } +void +nsJSContext::SetWindowProxy(JS::Handle aWindowProxy) +{ + js::SetDefaultObjectForContext(mContext, aWindowProxy); +} + +JSObject* +nsJSContext::GetWindowProxy() +{ + return xpc_UnmarkGrayObject(js::DefaultObjectForContextOrNull(mContext)); +} + void nsJSContext::LikelyShortLivingObjectCreated() { diff --git a/dom/base/nsJSEnvironment.h b/dom/base/nsJSEnvironment.h index 8cc9971e9761..3c95b5f977c8 100644 --- a/dom/base/nsJSEnvironment.h +++ b/dom/base/nsJSEnvironment.h @@ -80,6 +80,9 @@ public: virtual void WillInitializeContext() MOZ_OVERRIDE; virtual void DidInitializeContext() MOZ_OVERRIDE; + virtual void SetWindowProxy(JS::Handle aWindowProxy) MOZ_OVERRIDE; + virtual JSObject* GetWindowProxy() MOZ_OVERRIDE; + static void LoadStart(); static void LoadEnd();