Issue #1602 - Make sure we have a JSObject before trying to get global.

Dynamic script loading/unloading (thank you modules) can yank the script
out from under us before the JS API for it is initialized, leading to
null deref crashes.
This adds a simple check if the passed-in object is sane and present.
Resolves #1602
This commit is contained in:
wolfbeast
2020-06-27 02:09:19 +02:00
parent c05d07a687
commit c7330b5eb4
+7 -1
View File
@@ -485,7 +485,13 @@ AutoJSAPI::Init(nsIGlobalObject* aGlobalObject)
bool
AutoJSAPI::Init(JSObject* aObject)
{
return Init(xpc::NativeGlobal(aObject));
nsIGlobalObject* global = nullptr;
if (aObject)
global = xpc::NativeGlobal(aObject);
if (global)
return Init(global);
else
return false;
}
bool