From fb03af0c02a96cece93f43207ae2232a7e36a266 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 19 Sep 2020 16:39:58 +0000 Subject: [PATCH] Bug 1665862: Don't use AutoSafeJSContext in XMLHttpRequestWorker. r=nika It crashes if it fails to create the unprivileged junk scope, which is not great when it's being used by a fallible function. Differential Revision: https://phabricator.services.mozilla.com/D90753 --- dom/xhr/XMLHttpRequestWorker.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dom/xhr/XMLHttpRequestWorker.cpp b/dom/xhr/XMLHttpRequestWorker.cpp index 28a0917784bfa..d5c2caae2f59d 100644 --- a/dom/xhr/XMLHttpRequestWorker.cpp +++ b/dom/xhr/XMLHttpRequestWorker.cpp @@ -898,7 +898,12 @@ Proxy::HandleEvent(Event* aEvent) { } { - AutoSafeJSContext cx; + AutoJSAPI jsapi; + JSObject* junkScope = xpc::UnprivilegedJunkScope(fallible); + if (!junkScope || !jsapi.Init(junkScope)) { + return NS_ERROR_FAILURE; + } + JSContext* cx = jsapi.cx(); JS::Rooted value(cx); if (!GetOrCreateDOMReflectorNoWrap(cx, mXHR, &value)) {