Bug 1645510: Part 3 - Make some UnprivilegedJunkScope calls fallible. r=mccr8
authorKris Maglione <maglione.k@gmail.com>
Sat, 27 Jun 2020 03:06:35 +0000
changeset 537693 a6b021b3776ab954b0bf56d7a5641b072a719e2f
parent 537692 93bca0225002f5dae30b60b823cb73684031a348
child 537694 32cb37832953a7331904ccff64c7a7da3d054631
push id120169
push usermaglione.k@gmail.com
push dateSat, 27 Jun 2020 03:09:56 +0000
treeherderautoland@a6b021b3776a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1645510
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1645510: Part 3 - Make some UnprivilegedJunkScope calls fallible. r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D79721
dom/bindings/Codegen.py
dom/xhr/XMLHttpRequestWorker.cpp
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -14396,17 +14396,22 @@ class CGDictionary(CGThing):
                 AutoJSAPI jsapi;
                 jsapi.Init();
                 JSContext *cx = jsapi.cx();
                 // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
                 // because we'll only be creating objects, in ways that have no
                 // side-effects, followed by a call to JS::ToJSONMaybeSafely,
                 // which likewise guarantees no side-effects for the sorts of
                 // things we will pass it.
-                JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
+                JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible);
+                if (!scope) {
+                  JS_ReportOutOfMemory(cx);
+                  return false;
+                }
+                JSAutoRealm ar(cx, scope);
                 JS::Rooted<JS::Value> val(cx);
                 if (!ToObjectInternal(cx, &val)) {
                   return false;
                 }
                 JS::Rooted<JSObject*> obj(cx, &val.toObject());
                 return StringifyToJSON(cx, obj, aJSON);
             """), const=True)
 
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -1261,19 +1261,18 @@ nsresult OpenRunnable::MainThreadRunInte
 void SendRunnable::RunOnMainThread(ErrorResult& aRv) {
   Nullable<
       DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString>
       payload;
 
   if (!mBlobImpl) {
     payload.SetNull();
   } else {
-    AutoSafeJSContext cx;
-
-    JS::Rooted<JSObject*> globalObject(cx, JS::CurrentGlobalOrNull(cx));
+    JS::Rooted<JSObject*> globalObject(RootingCx(),
+                                       xpc::UnprivilegedJunkScope(fallible));
     if (NS_WARN_IF(!globalObject)) {
       aRv.Throw(NS_ERROR_FAILURE);
       return;
     }
 
     nsCOMPtr<nsIGlobalObject> parent = xpc::NativeGlobal(globalObject);
     if (NS_WARN_IF(!parent)) {
       aRv.Throw(NS_ERROR_FAILURE);