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
Родитель 9ac9619c3c
Коммит 71d7de8c4d
2 изменённых файлов: 10 добавлений и 7 удалений

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

@ -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;
}

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

@ -349,8 +349,8 @@ class ModuleLoaderBase : public nsISupports {
JS::Value FindFirstParseError(ModuleLoadRequest* aRequest);
static nsresult InitDebuggerDataForModuleGraph(JSContext* aCx,
ModuleLoadRequest* aRequest);
static nsresult ResolveRequestedModules(ModuleLoadRequest* aRequest,
nsCOMArray<nsIURI>* aUrlsOut);
nsresult ResolveRequestedModules(ModuleLoadRequest* aRequest,
nsCOMArray<nsIURI>* aUrlsOut);
void SetModuleFetchFinishedAndResumeWaitingRequests(
ModuleLoadRequest* aRequest, nsresult aResult);
@ -371,8 +371,8 @@ class ModuleLoaderBase : public nsISupports {
* The result of running ModuleEvaluate -- If this is successful, then
* we can await the associated EvaluationPromise.
*/
static void FinishDynamicImportAndReject(ModuleLoadRequest* aRequest,
nsresult aResult);
void FinishDynamicImportAndReject(ModuleLoadRequest* aRequest,
nsresult aResult);
/**
* Wrapper for JSAPI FinishDynamicImport function. Takes an optional argument