Bug 1254847 part 3. Make AutoEntryScript always take ownership of error reporting. r=bholley

This commit is contained in:
Boris Zbarsky 2016-03-09 19:02:03 -05:00
Родитель 6b80989ddf
Коммит 36d4079be7
25 изменённых файлов: 23 добавлений и 64 удалений

Просмотреть файл

@ -612,6 +612,8 @@ AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject,
if (aIsMainThread && gRunToCompletionListeners > 0) {
mDocShellEntryMonitor.emplace(cx(), aReason);
}
TakeOwnershipOfErrorReporting();
}
AutoEntryScript::AutoEntryScript(JSObject* aObject,

Просмотреть файл

@ -1104,7 +1104,6 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
}
AutoEntryScript aes(wrappedJS->GetJSObject(), "message manager handler");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> object(cx, wrappedJS->GetJSObject());
@ -1687,7 +1686,6 @@ nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL,
JS::Rooted<JSObject*> global(rt, mGlobal->GetJSObject());
if (global) {
AutoEntryScript aes(global, "message manager script load");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
if (script) {
if (aRunInGlobalScope) {

Просмотреть файл

@ -11915,13 +11915,12 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout,
// New script entry point required, due to the "Create a script" sub-step of
// http://www.whatwg.org/specs/web-apps/current-work/#timer-initialisation-steps
nsAutoMicroTask mt;
AutoEntryScript entryScript(this, reason, true, aScx->GetNativeContext());
entryScript.TakeOwnershipOfErrorReporting();
JS::CompileOptions options(entryScript.cx());
AutoEntryScript aes(this, reason, true, aScx->GetNativeContext());
JS::CompileOptions options(aes.cx());
options.setFileAndLine(filename, lineNo)
.setVersion(JSVERSION_DEFAULT);
JS::Rooted<JSObject*> global(entryScript.cx(), FastGetGlobalJSObject());
nsJSUtils::EvaluateString(entryScript.cx(), nsDependentString(script),
JS::Rooted<JSObject*> global(aes.cx(), FastGetGlobalJSObject());
nsJSUtils::EvaluateString(aes.cx(), nsDependentString(script),
global, options);
} else {
// Hold strong ref to ourselves while we call the callback.
@ -13967,7 +13966,6 @@ nsGlobalWindow::FireOnNewGlobalObject()
// AutoEntryScript required to invoke debugger hook, which is a
// Gecko-specific concept at present.
AutoEntryScript aes(this, "nsGlobalWindow report new global");
aes.TakeOwnershipOfErrorReporting();
JS::Rooted<JSObject*> global(aes.cx(), GetWrapper());
JS_FireOnNewGlobalObject(aes.cx(), global);
}

Просмотреть файл

@ -1113,10 +1113,9 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
// New script entry point required, due to the "Create a script" sub-step of
// http://www.whatwg.org/specs/web-apps/current-work/#execute-the-script-block
nsAutoMicroTask mt;
AutoEntryScript entryScript(globalObject, "<script> element", true,
context->GetNativeContext());
entryScript.TakeOwnershipOfErrorReporting();
JS::Rooted<JSObject*> global(entryScript.cx(),
AutoEntryScript aes(globalObject, "<script> element", true,
context->GetNativeContext());
JS::Rooted<JSObject*> global(aes.cx(),
globalObject->GetGlobalJSObject());
bool oldProcessingScriptTag = context->GetProcessingScriptTag();
@ -1137,9 +1136,9 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
aRequest->mElement);
}
JS::CompileOptions options(entryScript.cx());
FillCompileOptionsForRequest(entryScript, aRequest, global, &options);
rv = nsJSUtils::EvaluateString(entryScript.cx(), aSrcBuf, global, options,
JS::CompileOptions options(aes.cx());
FillCompileOptionsForRequest(aes, aRequest, global, &options);
rv = nsJSUtils::EvaluateString(aes.cx(), aSrcBuf, global, options,
aRequest->OffThreadTokenPtr());
}

Просмотреть файл

@ -3227,7 +3227,6 @@ WrappedJSToDictionary(nsISupports* aObject, T& aDictionary)
// we need this AutoEntryScript here because the spec requires us to execute
// getters when parsing a dictionary
AutoEntryScript aes(global, "WebIDL dictionary creation");
aes.TakeOwnershipOfErrorReporting();
JS::Rooted<JS::Value> v(aes.cx(), JS::ObjectValue(*obj));
return aDictionary.Init(aes.cx(), v);

Просмотреть файл

@ -189,9 +189,6 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
// And now we're ready to go.
mCx = cx;
// Make sure the JS engine doesn't report exceptions we want to re-throw.
mAutoEntryScript->TakeOwnershipOfErrorReporting();
}
bool

Просмотреть файл

@ -243,7 +243,6 @@ nsGeolocationSettings::HandleGeolocationPerOriginSettingsChange(const JS::Value&
// because the spec requires calling getters when enumerating the key of a
// dictionary
AutoEntryScript aes(global, "geolocation.app_settings enumeration");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
JS::Rooted<JS::IdVector> ids(cx, JS::IdVector(cx));
@ -327,7 +326,6 @@ nsGeolocationSettings::HandleGeolocationAlwaysPreciseChange(const JS::Value& aVa
// the spec requires calling getters when accessing array by index
AutoEntryScript aes(global, "geolocation.always_precise indexing");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
bool isArray;

Просмотреть файл

@ -240,13 +240,9 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
// New script entry point required, due to the "Create a script" step of
// http://www.whatwg.org/specs/web-apps/current-work/#javascript-protocol
nsAutoMicroTask mt;
AutoEntryScript entryScript(innerGlobal, "javascript: URI", true,
scriptContext->GetNativeContext());
// We want to make sure we report any exceptions that happen before we
// return, since whatever happens inside our execution shouldn't affect any
// other scripts that might happen to be running.
entryScript.TakeOwnershipOfErrorReporting();
JSContext* cx = entryScript.cx();
AutoEntryScript aes(innerGlobal, "javascript: URI", true,
scriptContext->GetNativeContext());
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> globalJSObject(cx, innerGlobal->GetGlobalJSObject());
NS_ENSURE_TRUE(globalJSObject, NS_ERROR_UNEXPECTED);

Просмотреть файл

@ -737,7 +737,6 @@ nsJSObjWrapper::NP_HasMethod(NPObject *npobj, NPIdentifier id)
}
dom::AutoEntryScript aes(globalObject, "NPAPI HasMethod");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
if (!npobj) {
@ -774,7 +773,6 @@ doInvoke(NPObject *npobj, NPIdentifier method, const NPVariant *args,
// We're about to run script via JS_CallFunctionValue, so we need an
// AutoEntryScript. NPAPI plugins are Gecko-specific and not in any spec.
dom::AutoEntryScript aes(globalObject, "NPAPI doInvoke");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
if (!npobj || !result) {
@ -867,7 +865,6 @@ nsJSObjWrapper::NP_HasProperty(NPObject *npobj, NPIdentifier npid)
}
dom::AutoEntryScript aes(globalObject, "NPAPI HasProperty");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
if (!npobj) {
@ -906,7 +903,6 @@ nsJSObjWrapper::NP_GetProperty(NPObject *npobj, NPIdentifier id,
// We're about to run script via JS_CallFunctionValue, so we need an
// AutoEntryScript. NPAPI plugins are Gecko-specific and not in any spec.
dom::AutoEntryScript aes(globalObject, "NPAPI get");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
if (!npobj) {
@ -941,7 +937,6 @@ nsJSObjWrapper::NP_SetProperty(NPObject *npobj, NPIdentifier npid,
// We're about to run script via JS_CallFunctionValue, so we need an
// AutoEntryScript. NPAPI plugins are Gecko-specific and not in any spec.
dom::AutoEntryScript aes(globalObject, "NPAPI set");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
if (!npobj) {
@ -979,7 +974,6 @@ nsJSObjWrapper::NP_RemoveProperty(NPObject *npobj, NPIdentifier npid)
}
dom::AutoEntryScript aes(globalObject, "NPAPI RemoveProperty");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
if (!npobj) {
@ -1031,7 +1025,6 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
}
dom::AutoEntryScript aes(globalObject, "NPAPI Enumerate");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
*idarray = 0;
@ -2304,7 +2297,6 @@ nsJSObjWrapper::HasOwnProperty(NPObject *npobj, NPIdentifier npid)
}
dom::AutoEntryScript aes(globalObject, "NPAPI HasOwnProperty");
aes.TakeOwnershipOfErrorReporting();
JSContext *cx = aes.cx();
if (!npobj) {

Просмотреть файл

@ -1357,7 +1357,6 @@ _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result)
nsAutoMicroTask mt;
dom::AutoEntryScript aes(win, "NPAPI NPN_evaluate");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> obj(cx, nsNPObjWrapper::GetNewOrUsed(npp, cx, npobj));

Просмотреть файл

@ -6011,8 +6011,7 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
{ // scope for the AutoEntryScript, so it comes off the stack before we do
// Promise::PerformMicroTaskCheckpoint.
AutoEntryScript entryScript(global, reason, false, aCx);
entryScript.TakeOwnershipOfErrorReporting();
AutoEntryScript aes(global, reason, false, aCx);
if (!info->mTimeoutCallable.isUndefined()) {
JS::Rooted<JS::Value> rval(aCx);
JS::HandleValueArray args =

Просмотреть файл

@ -327,8 +327,8 @@ WorkerRunnable::Run()
maybeJSAPI->Init();
jsapi = maybeJSAPI.ptr();
cx = jsapi->cx();
jsapi->TakeOwnershipOfErrorReporting();
}
jsapi->TakeOwnershipOfErrorReporting();
// Note that we can't assert anything about mWorkerPrivate->GetWrapper()
// existing, since it may in fact have been GCed (and we may be one of the

Просмотреть файл

@ -400,9 +400,8 @@ nsXBLProtoImplField::InstallField(JS::Handle<JSObject*> aBoundNode,
// We are going to run script via EvaluateString, so we need a script entry
// point, but as this is XBL related it does not appear in the HTML spec.
AutoEntryScript entryScript(globalObject, "XBL <field> initialization", true);
entryScript.TakeOwnershipOfErrorReporting();
JSContext* cx = entryScript.cx();
AutoEntryScript aes(globalObject, "XBL <field> initialization", true);
JSContext* cx = aes.cx();
NS_ASSERTION(!::JS_IsExceptionPending(cx),
"Shouldn't get here when an exception is pending!");
@ -440,7 +439,7 @@ nsXBLProtoImplField::InstallField(JS::Handle<JSObject*> aBoundNode,
if (rv == NS_SUCCESS_DOM_SCRIPT_EVALUATION_THREW) {
// Report the exception now, before we try using the JSContext for
// the JS_DefineUCProperty call.
entryScript.ReportException();
aes.ReportException();
}
// Now, enter the node's compartment, wrap the eval result, and define it on

Просмотреть файл

@ -290,7 +290,6 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement, JSAddonId* aAd
// We are going to run script via JS::Call, so we need a script entry point,
// but as this is XBL related it does not appear in the HTML spec.
dom::AutoEntryScript aes(global, "XBL <constructor>/<destructor> invocation");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> globalObject(cx, global->GetGlobalJSObject());

Просмотреть файл

@ -3503,7 +3503,6 @@ XULDocument::ExecuteScript(nsXULPrototypeScript *aScript)
// We're about to run script via JS::CloneAndExecuteScript, so we need an
// AutoEntryScript. This is Gecko specific and not in any spec.
AutoEntryScript aes(mScriptGlobalObject, "precompiled XUL <script> element");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> baseGlobal(cx, JS::CurrentGlobalOrNull(cx));
NS_ENSURE_TRUE(nsContentUtils::GetSecurityManager()->ScriptAllowed(baseGlobal), NS_OK);

Просмотреть файл

@ -1373,9 +1373,8 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot()
// We are going to run script via JS_SetProperty, so we need a script entry
// point, but as this is XUL related it does not appear in the HTML spec.
AutoEntryScript entryScript(innerWin, "nsXULTemplateBuilder creation", true);
entryScript.TakeOwnershipOfErrorReporting();
JSContext* jscontext = entryScript.cx();
AutoEntryScript aes(innerWin, "nsXULTemplateBuilder creation", true);
JSContext* jscontext = aes.cx();
JS::Rooted<JS::Value> v(jscontext);
rv = nsContentUtils::WrapNative(jscontext, mRoot, mRoot, &v);

Просмотреть файл

@ -72,7 +72,6 @@ TestShellCommandParent::RunCallback(const nsString& aResponse)
// We're about to run script via JS_CallFunctionValue, so we need an
// AutoEntryScript. This is just for testing and not in any spec.
dom::AutoEntryScript aes(&mCallback.toObject(), "TestShellCommand");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));

Просмотреть файл

@ -279,7 +279,6 @@ WrapperAnswer::RecvGet(const ObjectId& objId, const JSVariant& receiverVar,
// We may run scripted getters.
AutoEntryScript aes(scopeForTargetObjects(),
"Cross-Process Object Wrapper 'get'");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
// The outparam will be written to the buffer, so it must be set even if
@ -317,7 +316,6 @@ WrapperAnswer::RecvSet(const ObjectId& objId, const JSIDVariant& idVar, const JS
// We may run scripted setters.
AutoEntryScript aes(scopeForTargetObjects(),
"Cross-Process Object Wrapper 'set'");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
RootedObject obj(cx, findObjectById(cx, objId));
@ -379,7 +377,6 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId,
{
AutoEntryScript aes(scopeForTargetObjects(),
"Cross-Process Object Wrapper call/construct");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
// The outparam will be written to the buffer, so it must be set even if

Просмотреть файл

@ -639,7 +639,6 @@ mozJSComponentLoader::PrepareObjectForLocation(JSContext* aCx,
// Gecko-specific concept at present.
dom::AutoEntryScript aes(holder->GetJSObject(),
"component loader report global");
aes.TakeOwnershipOfErrorReporting();
RootedObject global(aes.cx(), holder->GetJSObject());
JS_FireOnNewGlobalObject(aes.cx(), global);
}
@ -941,7 +940,6 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo& aInfo,
// This is Gecko-specific and not in any spec.
dom::AutoEntryScript aes(CurrentGlobalOrNull(cx),
"component loader load module");
aes.TakeOwnershipOfErrorReporting();
JSContext* aescx = aes.cx();
AutoSaveContextOptions asco(aescx);
if (aPropagateExceptions)

Просмотреть файл

@ -347,7 +347,6 @@ AsyncScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
nsCOMPtr<nsIGlobalObject> globalObject = xpc::NativeGlobal(mTargetObj);
AutoEntryScript aes(globalObject, "async loadSubScript");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
AutoRejectPromise autoPromise(cx, mPromise, globalObject);

Просмотреть файл

@ -1703,7 +1703,6 @@ xpc::EvalInSandbox(JSContext* cx, HandleObject sandboxArg, const nsAString& sour
// We're about to evaluate script, so make an AutoEntryScript.
// This is clearly Gecko-specific and not in any spec.
mozilla::dom::AutoEntryScript aes(priv, "XPConnect sandbox evaluation");
aes.TakeOwnershipOfErrorReporting();
JSContext* sandcx = aes.cx();
AutoSaveContextOptions savedOptions(sandcx);
JS::ContextOptionsRef(sandcx).setDontReportUncaught(true);

Просмотреть файл

@ -1567,9 +1567,8 @@ XRE_XPCShellMain(int argc, char** argv, char** envp)
AutoEntryScript aes(backstagePass, "xpcshell argument processing");
// If an exception is thrown, we'll set our return code
// appropriately, and then let the AutoJSAPI destructor report
// appropriately, and then let the AutoEntryScript destructor report
// the error to the console.
aes.TakeOwnershipOfErrorReporting();
if (!ProcessArgs(aes, argv, argc, &dirprovider)) {
if (gExitCode) {
result = gExitCode;

Просмотреть файл

@ -515,7 +515,6 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
NS_ENSURE_TRUE(nativeGlobal->GetGlobalJSObject(), NS_ERROR_FAILURE);
AutoEntryScript aes(nativeGlobal, "XPCWrappedJS QueryInterface",
/* aIsMainThread = */ true);
aes.TakeOwnershipOfErrorReporting();
XPCCallContext ccx(NATIVE_CALLER, aes.cx());
if (!ccx.IsValid()) {
*aInstancePtr = nullptr;
@ -983,7 +982,6 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
NativeGlobal(js::GetGlobalForObjectCrossCompartment(wrapper->GetJSObject()));
AutoEntryScript aes(nativeGlobal, "XPCWrappedJS method call",
/* aIsMainThread = */ true);
aes.TakeOwnershipOfErrorReporting();
XPCCallContext ccx(NATIVE_CALLER, aes.cx());
if (!ccx.IsValid())
return retval;

Просмотреть файл

@ -1637,7 +1637,6 @@ CycleCollectedJSRuntime::EnvironmentPreparer::invoke(JS::HandleObject scope,
JSContext* cx =
mainThread ? nullptr : nsContentUtils::GetDefaultJSContextForThread();
AutoEntryScript aes(global, "JS-engine-initiated execution", mainThread, cx);
aes.TakeOwnershipOfErrorReporting();
MOZ_ASSERT(!JS_IsExceptionPending(aes.cx()));

Просмотреть файл

@ -157,7 +157,6 @@ nsHTTPIndex::OnFTPControlLog(bool server, const char *msg)
// AutoEntryScript. This is Gecko specific and not in any spec.
dom::AutoEntryScript aes(globalObject,
"nsHTTPIndex OnFTPControlLog");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
@ -232,7 +231,6 @@ nsHTTPIndex::OnStartRequest(nsIRequest *request, nsISupports* aContext)
// This is Gecko specific and not in any spec.
dom::AutoEntryScript aes(globalObject,
"nsHTTPIndex set HTTPIndex property");
aes.TakeOwnershipOfErrorReporting();
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));