mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 22:37:50 +00:00
Bug 899367 - Have nsGlobalWindow go through nsJSContext to access the outer. r=mccr8
This commit is contained in:
parent
921c772767
commit
c8fbffcb9d
@ -2049,8 +2049,9 @@ nsGlobalWindow::SetOuterObject(JSContext* aCx, JS::Handle<JSObject*> 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<JSObject*> inner(aCx, JS_GetParent(aOuterObject));
|
||||
@ -2446,11 +2447,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<JSObject*> rootedJSObject(cx, mJSObject);
|
||||
JS::Rooted<JSObject*> proto1(cx), proto2(cx);
|
||||
|
@ -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,13 @@ 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<JSObject*> aWindowProxy) = 0;
|
||||
virtual JSObject* GetWindowProxy() = 0;
|
||||
virtual JSObject* GetWindowProxyPreserveColor() = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContext, NS_ISCRIPTCONTEXT_IID)
|
||||
|
@ -1152,7 +1152,7 @@ nsJSContext::GetGlobalObject()
|
||||
JSObject*
|
||||
nsJSContext::GetNativeGlobal()
|
||||
{
|
||||
return js::DefaultObjectForContextOrNull(mContext);
|
||||
return GetWindowProxy();
|
||||
}
|
||||
|
||||
JSContext*
|
||||
@ -2598,6 +2598,24 @@ nsJSContext::ReportPendingException()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsJSContext::SetWindowProxy(JS::Handle<JSObject*> aWindowProxy)
|
||||
{
|
||||
js::SetDefaultObjectForContext(mContext, aWindowProxy);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
nsJSContext::GetWindowProxy()
|
||||
{
|
||||
return xpc_UnmarkGrayObject(GetWindowProxyPreserveColor());
|
||||
}
|
||||
|
||||
JSObject*
|
||||
nsJSContext::GetWindowProxyPreserveColor()
|
||||
{
|
||||
return js::DefaultObjectForContextOrNull(mContext);
|
||||
}
|
||||
|
||||
void
|
||||
nsJSContext::LikelyShortLivingObjectCreated()
|
||||
{
|
||||
|
@ -81,6 +81,10 @@ public:
|
||||
virtual void WillInitializeContext() MOZ_OVERRIDE;
|
||||
virtual void DidInitializeContext() MOZ_OVERRIDE;
|
||||
|
||||
virtual void SetWindowProxy(JS::Handle<JSObject*> aWindowProxy) MOZ_OVERRIDE;
|
||||
virtual JSObject* GetWindowProxy() MOZ_OVERRIDE;
|
||||
virtual JSObject* GetWindowProxyPreserveColor() MOZ_OVERRIDE;
|
||||
|
||||
static void LoadStart();
|
||||
static void LoadEnd();
|
||||
|
||||
|
@ -932,7 +932,7 @@ CycleCollectedJSRuntime::UsefulToMergeZones() const
|
||||
// NativeGlobal() is not an outer window (this happens with XUL Prototype
|
||||
// compilation scopes, for example, which we're not interested in).
|
||||
nsIScriptContext* scx = GetScriptContextFromJSContext(cx);
|
||||
JS::RootedObject global(cx, scx ? scx->GetNativeGlobal() : nullptr);
|
||||
JS::RootedObject global(cx, scx ? scx->GetWindowProxyPreserveColor() : nullptr);
|
||||
if (!global || !js::GetObjectParent(global)) {
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user