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.
This commit is contained in:
Bobby Holley 2012-03-08 09:33:30 -08:00
parent 243c25adb7
commit 676be52242
2 changed files with 17 additions and 10 deletions

View File

@ -1950,6 +1950,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal();
nsRefPtr<nsGlobalWindow> 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<nsIXPConnectWrappedNative> 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");

View File

@ -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<nsIXPConnectWrappedNative> 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;