From 676be5224245839e8246685041d3a88d7283cb2f Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 8 Mar 2012 09:33:30 -0800 Subject: [PATCH] Bug 733606 - Only call FinishInitForWrappedGlobal when we just created a global. r=mrbkap Without this patch, we call the above when restoring things out of the bfcache, which is bad. It must be called exactly once. --- dom/base/nsGlobalWindow.cpp | 15 +++++++++++++++ dom/base/nsJSEnvironment.cpp | 12 ++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 7b4193bf1db..674c1040b58 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -1950,6 +1950,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal(); nsRefPtr newInnerWindow; + bool createdInnerWindow = false; bool thisChrome = IsChromeWindow(); @@ -2028,6 +2029,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, "Failed to get script global and holder"); mCreatingInnerWindow = false; + createdInnerWindow = true; Thaw(); NS_ENSURE_SUCCESS(rv, rv); @@ -2108,6 +2110,19 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, } } + // If we created a new inner window above, we need to do the last little bit + // of initialization now that the dust has settled. + if (createdInnerWindow) { + nsIXPConnect *xpc = nsContentUtils::XPConnect(); + nsCOMPtr wrapper; + nsresult rv = xpc->GetWrappedNativeOfJSObject(cx, newInnerWindow->mJSObject, + getter_AddRefs(wrapper)); + NS_ENSURE_SUCCESS(rv, rv); + NS_ABORT_IF_FALSE(wrapper, "bad wrapper"); + rv = wrapper->FinishInitForWrappedGlobal(); + NS_ENSURE_SUCCESS(rv, rv); + } + JSAutoEnterCompartment ac; if (!ac.enter(cx, mJSObject)) { NS_ERROR("unable to enter a compartment"); diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 495e5658654..d8111c3aef1 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2314,19 +2314,11 @@ nsresult nsJSContext::SetOuterObject(JSObject* aOuterObject) { // Force our context's global object to be the outer. + // NB: JS_SetGlobalObject sets mContext->compartment. JS_SetGlobalObject(mContext, aOuterObject); - // NB: JS_SetGlobalObject sets mContext->compartment. + // Set up the prototype for the outer object. JSObject *inner = JS_GetParent(aOuterObject); - - nsIXPConnect *xpc = nsContentUtils::XPConnect(); - nsCOMPtr wrapper; - nsresult rv = xpc->GetWrappedNativeOfJSObject(mContext, inner, - getter_AddRefs(wrapper)); - NS_ENSURE_SUCCESS(rv, rv); - NS_ABORT_IF_FALSE(wrapper, "bad wrapper"); - - wrapper->FinishInitForWrappedGlobal(); JS_SetPrototype(mContext, aOuterObject, JS_GetPrototype(inner)); return NS_OK;