Bug 1774111 - Initialize AutoJAPI from the native global in the module loader r=yulia

We're getting a bunch of crashes related to initializing AutoJSAPI from a
JSObject pointer that turns out to be null. That overload of Init() gets the
native global from the JSObject and since we already have a native global in
the module loader we can use the overload that takes that instead. This
overload does a null check so we will catch the case where the global is null
(although that should also not happen).

This might just move crashes elsewhere but it's a reasonable tidyup.

Differential Revision: https://phabricator.services.mozilla.com/D162386
This commit is contained in:
Jon Coppeard
2022-11-18 13:25:46 +00:00
parent 9aea68c66d
commit cabfa4ee4c
2 changed files with 10 additions and 7 deletions

View File

@@ -750,7 +750,7 @@ nsresult ModuleLoaderBase::ResolveRequestedModules(
ModuleScript* ms = aRequest->mModuleScript;
AutoJSAPI jsapi;
if (!jsapi.Init(ms->ModuleRecord())) {
if (!jsapi.Init(mGlobalObject)) {
return NS_ERROR_FAILURE;
}
@@ -925,7 +925,10 @@ void ModuleLoaderBase::FinishDynamicImportAndReject(ModuleLoadRequest* aRequest,
nsresult aResult) {
AutoJSAPI jsapi;
MOZ_ASSERT(NS_FAILED(aResult));
MOZ_ALWAYS_TRUE(jsapi.Init(aRequest->mDynamicPromise));
if (!jsapi.Init(mGlobalObject)) {
return;
}
FinishDynamicImport(jsapi.cx(), aRequest, aResult, nullptr);
}
@@ -1074,7 +1077,7 @@ bool ModuleLoaderBase::InstantiateModuleGraph(ModuleLoadRequest* aRequest) {
MOZ_ASSERT(moduleScript->ModuleRecord());
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(moduleScript->ModuleRecord()))) {
if (NS_WARN_IF(!jsapi.Init(mGlobalObject))) {
return false;
}