Bug 961204. Remove the my_context bits from nsWindowSH::NewResolve and just use the passed-in cx for everything. r=bholley

This commit is contained in:
Boris Zbarsky 2014-01-21 22:08:47 -05:00
parent d94c32de71
commit 4a61f7bb0c

View File

@ -3356,46 +3356,14 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return DefineComponentsShim(cx, obj, win);
}
nsIScriptContext *my_context = win->GetContextInternal();
// Don't resolve standard classes on XrayWrappers, only resolve them if we're
// resolving on the real global object.
if (!xpc::WrapperFactory::IsXrayWrapper(obj)) {
bool isXray = xpc::WrapperFactory::IsXrayWrapper(obj);
if (!isXray) {
bool did_resolve = false;
bool ok = true;
JS::Rooted<JS::Value> exn(cx, JSVAL_VOID);
{
// Resolve standard classes on my_context's JSContext (or on cx,
// if we don't have a my_context yet), in case the two contexts
// have different origins. We want lazy standard class
// initialization to behave as if it were done eagerly, on each
// window's own context (not on some other window-caller's
// context).
AutoPushJSContext my_cx(my_context ? my_context->GetNativeContext() : cx);
JSAutoCompartment ac(my_cx, obj);
ok = JS_ResolveStandardClass(my_cx, obj, id, &did_resolve);
if (!ok) {
// Trust the JS engine (or the script security manager) to set
// the exception in the JS engine.
if (!JS_GetPendingException(my_cx, &exn)) {
return NS_ERROR_UNEXPECTED;
}
// Return NS_OK to avoid stomping over the exception that was passed
// down from the ResolveStandardClass call.
// Note that the order of the JS_ClearPendingException and
// JS_SetPendingException is important in the case that my_cx == cx.
JS_ClearPendingException(my_cx);
}
}
if (!ok) {
JS_SetPendingException(cx, exn);
if (!JS_ResolveStandardClass(cx, obj, id, &did_resolve)) {
// Return NS_OK to avoid stomping over the exception that was passed
// down from the ResolveStandardClass call.
*_retval = false;
return NS_OK;
}
@ -3406,14 +3374,10 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
}
if (!my_context || !my_context->IsContextInitialized()) {
// The context is not yet initialized so there's nothing we can do
// here yet.
return NS_OK;
}
if (sLocation_id == id) {
// WebIDL quickstubs handle location for us, but Xrays don't see those. So if
// we're an Xray, we have to resolve stuff here to make "window.location =
// someString" work.
if (sLocation_id == id && isXray) {
// This must be done even if we're just getting the value of
// window.location (i.e. no checking flags & JSRESOLVE_ASSIGNING
// here) since we must define window.location to prevent the
@ -3444,7 +3408,10 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_OK;
}
if (sTop_id == id) {
// WebIDL quickstubs handle location for us, but Xrays don't see those. So if
// we're an Xray and we want "top" to be JSPROP_PERMANENT, we need to resolve
// it here.
if (sTop_id == id && isXray) {
nsCOMPtr<nsIDOMWindow> top;
nsresult rv = win->GetScriptableTop(getter_AddRefs(top));
NS_ENSURE_SUCCESS(rv, rv);