зеркало из https://github.com/mozilla/gecko-dev.git
Bug 883450 - MOZ_CRASH if we fail to spin up the SafeJSContext, and remove error handling. r=gabor
There's not a lot we can do without it in the browser these days.
This commit is contained in:
Родитель
7022fc3902
Коммит
9aca4442cf
|
@ -145,20 +145,16 @@ XPCJSContextStack::GetSafeJSContext()
|
||||||
nsRefPtr<nsNullPrincipal> principal = new nsNullPrincipal();
|
nsRefPtr<nsNullPrincipal> principal = new nsNullPrincipal();
|
||||||
nsresult rv = principal->Init();
|
nsresult rv = principal->Init();
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return NULL;
|
MOZ_CRASH();
|
||||||
|
|
||||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||||
XPCJSRuntime* xpcrt = xpc->GetRuntime();
|
JSRuntime *rt = xpc->GetRuntime()->Runtime();
|
||||||
if (!xpcrt)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
JSRuntime *rt = xpcrt->Runtime();
|
|
||||||
if (!rt)
|
if (!rt)
|
||||||
return NULL;
|
MOZ_CRASH();
|
||||||
|
|
||||||
mSafeJSContext = JS_NewContext(rt, 8192);
|
mSafeJSContext = JS_NewContext(rt, 8192);
|
||||||
if (!mSafeJSContext)
|
if (!mSafeJSContext)
|
||||||
return NULL;
|
MOZ_CRASH();
|
||||||
|
|
||||||
JS::RootedObject glob(mSafeJSContext);
|
JS::RootedObject glob(mSafeJSContext);
|
||||||
{
|
{
|
||||||
|
@ -168,8 +164,9 @@ XPCJSContextStack::GetSafeJSContext()
|
||||||
JS_SetErrorReporter(mSafeJSContext, mozJSLoaderErrorReporter);
|
JS_SetErrorReporter(mSafeJSContext, mozJSLoaderErrorReporter);
|
||||||
|
|
||||||
glob = xpc::CreateGlobalObject(mSafeJSContext, &global_class, principal, JS::SystemZone);
|
glob = xpc::CreateGlobalObject(mSafeJSContext, &global_class, principal, JS::SystemZone);
|
||||||
|
if (!glob)
|
||||||
|
MOZ_CRASH();
|
||||||
|
|
||||||
if (glob) {
|
|
||||||
// Make sure the context is associated with a proper compartment
|
// Make sure the context is associated with a proper compartment
|
||||||
// and not the default compartment.
|
// and not the default compartment.
|
||||||
JS_SetGlobalObject(mSafeJSContext, glob);
|
JS_SetGlobalObject(mSafeJSContext, glob);
|
||||||
|
@ -178,21 +175,13 @@ XPCJSContextStack::GetSafeJSContext()
|
||||||
// InitClasses
|
// InitClasses
|
||||||
nsCOMPtr<nsIScriptObjectPrincipal> sop = new SandboxPrivate(principal, glob);
|
nsCOMPtr<nsIScriptObjectPrincipal> sop = new SandboxPrivate(principal, glob);
|
||||||
JS_SetPrivate(glob, sop.forget().get());
|
JS_SetPrivate(glob, sop.forget().get());
|
||||||
}
|
|
||||||
|
|
||||||
// After this point either glob is null and the
|
// After this point either glob is null and the
|
||||||
// nsIScriptObjectPrincipal ownership is either handled by the
|
// nsIScriptObjectPrincipal ownership is either handled by the
|
||||||
// nsCOMPtr or dealt with, or we'll release in the finalize
|
// nsCOMPtr or dealt with, or we'll release in the finalize
|
||||||
// hook.
|
// hook.
|
||||||
if (glob && NS_FAILED(xpc->InitClasses(mSafeJSContext, glob))) {
|
if (NS_FAILED(xpc->InitClasses(mSafeJSContext, glob)))
|
||||||
glob = nullptr;
|
MOZ_CRASH();
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mSafeJSContext && !glob) {
|
|
||||||
// Destroy the context outside the scope of JSAutoRequest that
|
|
||||||
// uses the context in its destructor.
|
|
||||||
JS_DestroyContext(mSafeJSContext);
|
|
||||||
mSafeJSContext = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save it off so we can destroy it later.
|
// Save it off so we can destroy it later.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче