Bug 1498562 - Apply new curly-braces-required style to code introduced in Bug 1498562. r=jandem
☠☠ backed out by 814dfda94ebc ☠ ☠
authorJason Orendorff <jorendorff@mozilla.com>
Mon, 15 Oct 2018 10:19:03 +0000
changeset 489616 dc5c09d437018c7bbd72dda3b162c1b3b06b03a1
parent 489615 5aff488dd9e943c985dc7ffed98d26e46c71dfab
child 489617 814dfda94ebc2bd584a139b1638d4335651145ec
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjandem
bugs1498562
milestone64.0a1
Bug 1498562 - Apply new curly-braces-required style to code introduced in Bug 1498562. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D8536
js/src/builtin/Stream.cpp
--- a/js/src/builtin/Stream.cpp
+++ b/js/src/builtin/Stream.cpp
@@ -1063,18 +1063,19 @@ static MOZ_MUST_USE bool
 ReadableStream_cancel(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     // Step 1: If ! IsReadableStream(this) is false, return a promise rejected
     //         with a TypeError exception.
     Rooted<ReadableStream*> stream(cx);
     stream = ToUnwrapped<ReadableStream>(cx, args.thisv(), "ReadableStream", "cancel");
-    if (!stream)
+    if (!stream) {
         return ReturnPromiseRejectedWithPendingError(cx, args);
+    }
 
     // Step 2: If ! IsReadableStreamLocked(this) is true, return a promise
     //         rejected with a TypeError exception.
     if (stream->locked()) {
         JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
                                   JSMSG_READABLESTREAM_LOCKED_METHOD, "cancel");
         return ReturnPromiseRejectedWithPendingError(cx, args);
     }
@@ -1095,18 +1096,19 @@ CreateReadableStreamDefaultReader(JSCont
 static bool
 ReadableStream_getReader(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     // Step 1: If ! IsReadableStream(this) is false, throw a TypeError exception.
     Rooted<ReadableStream*> stream(cx);
     stream = ToUnwrapped<ReadableStream>(cx, args.thisv(), "ReadableStream", "getReader");
-    if (!stream)
+    if (!stream) {
         return false;
+    }
 
     RootedObject reader(cx);
 
     // Step 2: If mode is undefined, return
     //         ? AcquireReadableStreamDefaultReader(this).
     RootedValue modeVal(cx);
     HandleValue optionsVal = args.get(0);
     if (!optionsVal.isUndefined()) {
@@ -1178,18 +1180,19 @@ ReadableStreamTee(JSContext* cx, Handle<
 static bool
 ReadableStream_tee(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     // Step 1: If ! IsReadableStream(this) is false, throw a TypeError exception.
     Rooted<ReadableStream*> stream(cx);
     stream = ToUnwrapped<ReadableStream>(cx, args.thisv(), "ReadableStream", "tee");
-    if (!stream)
+    if (!stream) {
         return false;
+    }
 
     // Step 2: Let branches be ? ReadableStreamTee(this, false).
     Rooted<ReadableStream*> branch1(cx);
     Rooted<ReadableStream*> branch2(cx);
     if (!ReadableStreamTee(cx, stream, false, &branch1, &branch2)) {
         return false;
     }
 
@@ -1358,21 +1361,23 @@ ReadableStreamTee_Pull(JSContext* cx, Ha
     //         branch2 be F.[[branch2]], teeState be F.[[teeState]], and
     //         cloneForBranch2 be F.[[cloneForBranch2]].
 
     // Step 2: Return the result of transforming
     //         ! ReadableStreamDefaultReaderRead(reader) by a fulfillment
     //         handler which takes the argument result and performs the
     //         following steps:
     Rooted<ReadableStream*> stream(cx, TeeState::stream(cx, teeState));
-    if (!stream)
+    if (!stream) {
         return nullptr;
+    }
     RootedObject readerObj(cx, ReaderFromStream(cx, stream));
-    if (!readerObj)
+    if (!readerObj) {
         return nullptr;
+    }
     Rooted<ReadableStreamDefaultReader*> reader(cx,
                                                 &readerObj->as<ReadableStreamDefaultReader>());
 
     RootedObject readPromise(cx, ReadableStreamDefaultReader::read(cx, reader));
     if (!readPromise) {
         return nullptr;
     }
 
@@ -1393,31 +1398,33 @@ ReadableStreamTee_Pull(JSContext* cx, Ha
  * created in the current cx compartment.
  */
 static MOZ_MUST_USE JSObject*
 ReadableStreamTee_Cancel(JSContext* cx, Handle<TeeState*> teeState,
                          Handle<ReadableStreamDefaultController*> branch, HandleValue reason_)
 {
     // Step 1: Let stream be F.[[stream]] and teeState be F.[[teeState]].
     Rooted<ReadableStream*> stream(cx, TeeState::stream(cx, teeState));
-    if (!stream)
+    if (!stream) {
         return nullptr;
+    }
 
     bool bothBranchesCanceled = false;
 
     // Step 2: Set teeState.[[canceled1]] to true.
     // Step 3: Set teeState.[[reason1]] to reason.
     {
         RootedValue reason(cx, reason_);
         if (reason.isGCThing() &&
             reason.toGCThing()->maybeCompartment() != teeState->compartment())
         {
             AutoRealm ar(cx, teeState);
-            if (!cx->compartment()->wrap(cx, &reason))
+            if (!cx->compartment()->wrap(cx, &reason)) {
                 return nullptr;
+            }
         }
         if (ControllerFlags(branch) & ControllerFlag_TeeBranch1) {
             teeState->setCanceled1(reason);
             bothBranchesCanceled = teeState->canceled2();
         } else {
             MOZ_ASSERT(ControllerFlags(branch) & ControllerFlag_TeeBranch2);
             teeState->setCanceled2(reason);
             bothBranchesCanceled = teeState->canceled1();
@@ -1434,18 +1441,19 @@ ReadableStreamTee_Cancel(JSContext* cx, 
             return nullptr;
         }
 
         compositeReason->setDenseInitializedLength(2);
 
         RootedValue reason1(cx, teeState->reason1());
         RootedValue reason2(cx, teeState->reason2());
         if (teeState->compartment() != cx->compartment()) {
-            if (!cx->compartment()->wrap(cx, &reason1) || !cx->compartment()->wrap(cx, &reason2))
+            if (!cx->compartment()->wrap(cx, &reason1) || !cx->compartment()->wrap(cx, &reason2)) {
                 return nullptr;
+            }
         }
         compositeReason->initDenseElement(0, reason1);
         compositeReason->initDenseElement(1, reason2);
         RootedValue compositeReasonVal(cx, ObjectValue(*compositeReason));
 
         Rooted<PromiseObject*> promise(cx, teeState->promise());
 
         // Step b: Let cancelResult be ! ReadableStreamCancel(stream, compositeReason).
@@ -1454,30 +1462,32 @@ ReadableStreamTee_Cancel(JSContext* cx, 
             AutoRealm ar(cx, promise);
             if (!cancelResult) {
                 if (!RejectWithPendingError(cx, promise)) {
                     return nullptr;
                 }
             } else {
                 // Step c: Resolve teeState.[[promise]] with cancelResult.
                 RootedValue resultVal(cx, ObjectValue(*cancelResult));
-                if (!cx->compartment()->wrap(cx, &resultVal))
+                if (!cx->compartment()->wrap(cx, &resultVal)) {
                     return nullptr;
+                }
                 if (!PromiseObject::resolve(cx, promise, resultVal)) {
                     return nullptr;
                 }
             }
         }
     }
 
     // Step 5: Return teeState.[[promise]].
     RootedObject promise(cx, teeState->promise());
     if (promise->compartment() != cx->compartment()) {
-        if (!cx->compartment()->wrap(cx, &promise))
+        if (!cx->compartment()->wrap(cx, &promise)) {
             return nullptr;
+        }
     }
     return promise;
 }
 
 static MOZ_MUST_USE bool
 ReadableStreamDefaultControllerErrorIfNeeded(JSContext* cx,
                                              Handle<ReadableStreamDefaultController*> controller,
                                              HandleValue e);
@@ -1628,18 +1638,19 @@ AppendToListAtSlot(JSContext* cx, Handle
  * Note: The returned Promise is created in the current cx compartment.
  */
 static MOZ_MUST_USE JSObject*
 ReadableStreamAddReadOrReadIntoRequest(JSContext* cx, Handle<ReadableStream*> stream)
 {
     // Step 1: Assert: ! IsReadableStreamBYOBReader(stream.[[reader]]) is true.
     // Skipped: handles both kinds of readers.
     Rooted<ReadableStreamReader*> reader(cx, ReaderFromStream(cx, stream));
-    if (!reader)
+    if (!reader) {
         return nullptr;
+    }
 
     // Step 2 of 3.4.2: Assert: stream.[[state]] is "readable".
     MOZ_ASSERT_IF(reader->is<ReadableStreamDefaultReader>(), stream->readable());
 
     // Step 3: Let promise be a new promise.
     RootedObject promise(cx, PromiseObject::createSkippingExecutor(cx));
     if (!promise) {
         return nullptr;
@@ -1693,18 +1704,19 @@ ReadableStream::cancel(JSContext* cx, Ha
     if (stream->closed()) {
         return PromiseObject::unforgeableResolve(cx, UndefinedHandleValue);
     }
 
     // Step 3: If stream.[[state]] is "errored", return a new promise rejected
     //         with stream.[[storedError]].
     if (stream->errored()) {
         RootedValue storedError(cx, stream->getFixedSlot(StreamSlot_StoredError));
-        if (!cx->compartment()->wrap(cx, &storedError))
+        if (!cx->compartment()->wrap(cx, &storedError)) {
             return nullptr;
+        }
         return PromiseObject::unforgeableReject(cx, storedError);
     }
 
     // Step 4: Perform ! ReadableStreamClose(stream).
     if (!ReadableStreamCloseInternal(cx, stream)) {
         return nullptr;
     }
 
@@ -1778,18 +1790,19 @@ ReadableStreamCloseInternal(JSContext* c
                     return false;
                 }
 
                 resultObj = CreateIterResultObject(cx, UndefinedHandleValue, true);
                 if (!resultObj) {
                     return false;
                 }
                 resultVal = ObjectValue(*resultObj);
-                if (!ResolvePromise(cx, readRequest, resultVal))
+                if (!ResolvePromise(cx, readRequest, resultVal)) {
                     return false;
+                }
             }
 
             // Step b: Set reader.[[readRequests]] to an empty List.
             reader->setFixedSlot(ReaderSlot_Requests, UndefinedValue());
         }
     }
 
     // Step 6: Resolve reader.[[closedPromise]] with undefined.
@@ -1857,18 +1870,19 @@ ReadableStreamErrorInternal(JSContext* c
     for (uint32_t i = 0; i < len; i++) {
         // Step i: Reject readRequest.[[promise]] with e.
         val = readRequests->getDenseElement(i);
         readRequest = &val.toObject();
 
         // Responses have to be created in the compartment from which the
         // error was triggered, which might not be the same as the one the
         // request was created in, so we have to wrap requests here.
-        if (!cx->compartment()->wrap(cx, &readRequest))
+        if (!cx->compartment()->wrap(cx, &readRequest)) {
             return false;
+        }
 
         if (!RejectPromise(cx, readRequest, e)) {
             return false;
         }
     }
 
     // Step b: Set reader.[[readRequests]] to a new empty List.
     if (!SetNewList(cx, reader, ReaderSlot_Requests)) {
@@ -1895,18 +1909,19 @@ ReadableStreamErrorInternal(JSContext* c
         // Make sure we're in the stream's compartment.
         AutoRealm ar(cx, stream);
         ReadableStreamController* controller = ControllerFromStream(stream);
         void* source = controller->getFixedSlot(ControllerSlot_UnderlyingSource).toPrivate();
 
         // Ensure that the embedding doesn't have to deal with
         // mixed-compartment arguments to the callback.
         RootedValue error(cx, e);
-        if (!cx->compartment()->wrap(cx, &error))
+        if (!cx->compartment()->wrap(cx, &error)) {
             return false;
+        }
 
         cx->runtime()->readableStreamErroredCallback(cx, stream, source,
                                                      stream->embeddingFlags(), error);
     }
 
     return true;
 }
 
@@ -1920,36 +1935,39 @@ ReadableStreamErrorInternal(JSContext* c
  * of this function's operation is created in the current cx compartment.
  */
 static MOZ_MUST_USE bool
 ReadableStreamFulfillReadOrReadIntoRequest(JSContext* cx, Handle<ReadableStream*> stream,
                                            HandleValue chunk, bool done)
 {
     // Step 1: Let reader be stream.[[reader]].
     Rooted<ReadableStreamReader*> reader(cx, ReaderFromStream(cx, stream));
-    if (!reader)
+    if (!reader) {
         return false;
+    }
 
     // Step 2: Let readIntoRequest be the first element of
     //         reader.[[readIntoRequests]].
     // Step 3: Remove readIntoRequest from reader.[[readIntoRequests]], shifting
     //         all other elements downward (so that the second becomes the first,
     //         and so on).
     RootedValue val(cx, reader->getFixedSlot(ReaderSlot_Requests));
     RootedNativeObject readIntoRequests(cx, &val.toObject().as<NativeObject>());
     RootedObject readIntoRequest(cx, ShiftFromList<JSObject>(cx, readIntoRequests));
     MOZ_ASSERT(readIntoRequest);
-    if (!cx->compartment()->wrap(cx, &readIntoRequest))
+    if (!cx->compartment()->wrap(cx, &readIntoRequest)) {
         return false;
+    }
 
     // Step 4: Resolve readIntoRequest.[[promise]] with
     //         ! CreateIterResultObject(chunk, done).
     RootedValue wrappedChunk(cx, chunk);
-    if (!cx->compartment()->wrap(cx, &wrappedChunk))
+    if (!cx->compartment()->wrap(cx, &wrappedChunk)) {
         return false;
+    }
     RootedObject iterResult(cx, CreateIterResultObject(cx, wrappedChunk, done));
     if (!iterResult) {
         return false;
     }
     val = ObjectValue(*iterResult);
     return ResolvePromise(cx, readIntoRequest, val);
 }
 
@@ -1993,35 +2011,37 @@ ReadableStreamHasDefaultReader(JSContext
     if (stream->getFixedSlot(StreamSlot_Reader).isUndefined()) {
         *result = false;
         return true;
     }
 
     // Step 3: If ! ReadableStreamDefaultReader(reader) is false, return false.
     // Step 4: Return true.
     JSObject* readerObj = ReaderFromStream(cx, stream);
-    if (!readerObj)
+    if (!readerObj) {
         return false;
+    }
 
     *result = readerObj->is<ReadableStreamDefaultReader>();
     return true;
 }
 #endif // DEBUG
 
 static MOZ_MUST_USE bool
 ReadableStreamGetReaderMode(JSContext* cx, ReadableStream* stream, ReaderMode* mode)
 {
     if (stream->getFixedSlot(StreamSlot_Reader).isUndefined()) {
         *mode = ReaderMode::None;
         return true;
     }
 
     JSObject* readerObj = ReaderFromStream(cx, stream);
-    if (!readerObj)
+    if (!readerObj) {
         return false;
+    }
 
     *mode = ReaderMode::Default;
 
     return true;
 }
 
 static MOZ_MUST_USE bool
 ReadableStreamReaderGenericInitialize(JSContext* cx,
@@ -2275,18 +2295,19 @@ ReadableStreamControllerCallPullIfNeeded
  */
 static MOZ_MUST_USE JSObject*
 ReadableStreamReaderGenericCancel(JSContext* cx, Handle<ReadableStreamReader*> reader,
                                   HandleValue reason)
 {
     // Step 1: Let stream be reader.[[ownerReadableStream]].
     // Step 2: Assert: stream is not undefined (implicit).
     Rooted<ReadableStream*> stream(cx, StreamFromReader(cx, reader));
-    if (!stream)
+    if (!stream) {
         return nullptr;
+    }
 
     // Step 3: Return ! ReadableStreamCancel(stream, reason).
     return ReadableStream::cancel(cx, stream, reason);
 }
 
 /**
  * Streams spec, 3.7.4. ReadableStreamReaderGenericInitialize ( reader, stream )
  *
@@ -2296,23 +2317,25 @@ ReadableStreamReaderGenericCancel(JSCont
 static MOZ_MUST_USE bool
 ReadableStreamReaderGenericInitialize(JSContext* cx, Handle<ReadableStreamReader*> reader,
                                       Handle<ReadableStream*> stream)
 {
     // Step 1: Set reader.[[ownerReadableStream]] to stream.
     // Step 2: Set stream.[[reader]] to reader.
     if (!IsObjectInContextCompartment(stream, cx)) {
         RootedObject wrappedStream(cx, stream);
-        if (!cx->compartment()->wrap(cx, &wrappedStream))
+        if (!cx->compartment()->wrap(cx, &wrappedStream)) {
             return false;
+        }
         reader->setFixedSlot(ReaderSlot_Stream, ObjectValue(*wrappedStream));
         AutoRealm ar(cx, stream);
         RootedObject wrappedReader(cx, reader);
-        if (!cx->compartment()->wrap(cx, &wrappedReader))
+        if (!cx->compartment()->wrap(cx, &wrappedReader)) {
             return false;
+        }
         stream->setFixedSlot(StreamSlot_Reader, ObjectValue(*wrappedReader));
     } else {
         reader->setFixedSlot(ReaderSlot_Stream, ObjectValue(*stream));
         stream->setFixedSlot(StreamSlot_Reader, ObjectValue(*reader));
     }
 
     // Step 3: If stream.[[state]] is "readable",
     RootedObject promise(cx);
@@ -2328,18 +2351,19 @@ ReadableStreamReaderGenericInitialize(JS
     } else {
         // Step b: Otherwise,
         // Step i: Assert: stream.[[state]] is "errored".
         MOZ_ASSERT(stream->errored());
 
         // Step ii: Set reader.[[closedPromise]] to a new promise rejected with
         //          stream.[[storedError]].
         RootedValue storedError(cx, stream->getFixedSlot(StreamSlot_StoredError));
-        if (!cx->compartment()->wrap(cx, &storedError))
+        if (!cx->compartment()->wrap(cx, &storedError)) {
             return false;
+        }
         promise = PromiseObject::unforgeableReject(cx, storedError);
     }
 
     if (!promise) {
         return false;
     }
 
     reader->setFixedSlot(ReaderSlot_ClosedPromise, ObjectValue(*promise));
@@ -2352,18 +2376,19 @@ ReadableStreamReaderGenericInitialize(JS
  * Note: can operate on unwrapped ReadableStream reader instances from
  * another compartment.
  */
 static MOZ_MUST_USE bool
 ReadableStreamReaderGenericRelease(JSContext* cx, Handle<ReadableStreamReader*> reader)
 {
     // Step 1: Assert: reader.[[ownerReadableStream]] is not undefined.
     Rooted<ReadableStream*> stream(cx, StreamFromReader(cx, reader));
-    if (!stream)
+    if (!stream) {
         return false;
+    }
 
     // Step 2: Assert: reader.[[ownerReadableStream]].[[reader]] is reader.
     MOZ_ASSERT(ReaderFromStream(cx, stream) == reader);
 
     // Create an exception to reject promises with below. We don't have a
     // clean way to do this, unfortunately.
     JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_READABLESTREAMREADER_RELEASED);
     RootedValue exn(cx);
@@ -2384,18 +2409,19 @@ ReadableStreamReaderGenericRelease(JSCon
         Value val = reader->getFixedSlot(ReaderSlot_ClosedPromise);
         Rooted<PromiseObject*> closedPromise(cx, &val.toObject().as<PromiseObject>());
         if (closedPromise->compartment() != cx->compartment()) {
             ar.emplace(cx, closedPromise);
             if (!cx->compartment()->wrap(cx, &exn)) {
                 return false;
             }
         }
-        if (!PromiseObject::reject(cx, closedPromise, exn))
+        if (!PromiseObject::reject(cx, closedPromise, exn)) {
             return false;
+        }
     } else {
         // Step 4: Otherwise, set reader.[[closedPromise]] to a new promise rejected
         //         with a TypeError exception.
         RootedObject closedPromise(cx, PromiseObject::unforgeableReject(cx, exn));
         if (!closedPromise) {
             return false;
         }
         if (reader->compartment() != cx->compartment()) {
@@ -2426,18 +2452,19 @@ ReadableStreamControllerPullSteps(JSCont
  * another compartment.
  */
 /* static */ MOZ_MUST_USE JSObject*
 ReadableStreamDefaultReader::read(JSContext* cx, Handle<ReadableStreamDefaultReader*> reader)
 {
     // Step 1: Let stream be reader.[[ownerReadableStream]].
     // Step 2: Assert: stream is not undefined.
     Rooted<ReadableStream*> stream(cx, StreamFromReader(cx, reader));
-    if (!stream)
+    if (!stream) {
         return nullptr;
+    }
 
     // Step 3: Set stream.[[disturbed]] to true.
     SetStreamState(stream, StreamState(stream) | ReadableStream::Disturbed);
 
     // Step 4: If stream.[[state]] is "closed", return a new promise resolved with
     //         ! CreateIterResultObject(undefined, true).
     if (stream->closed()) {
         RootedObject iterResult(cx, CreateIterResultObject(cx, UndefinedHandleValue, true));
@@ -2447,18 +2474,19 @@ ReadableStreamDefaultReader::read(JSCont
         RootedValue iterResultVal(cx, ObjectValue(*iterResult));
         return PromiseObject::unforgeableResolve(cx, iterResultVal);
     }
 
     // Step 5: If stream.[[state]] is "errored", return a new promise rejected with
     //         stream.[[storedError]].
     if (stream->errored()) {
         RootedValue storedError(cx, stream->getFixedSlot(StreamSlot_StoredError));
-        if (!cx->compartment()->wrap(cx, &storedError))
+        if (!cx->compartment()->wrap(cx, &storedError)) {
             return nullptr;
+        }
         return PromiseObject::unforgeableReject(cx, storedError);
     }
 
     // Step 6: Assert: stream.[[state]] is "readable".
     MOZ_ASSERT(stream->readable());
 
     // Step 7: Return ! stream.[[readableStreamController]].[[PullSteps]]().
     Rooted<ReadableStreamController*> controller(cx, ControllerFromStream(stream));
@@ -2890,18 +2918,19 @@ ReadableStreamControllerCancelSteps(JSCo
         RootedNativeObject pendingPullIntos(cx, &val.toObject().as<NativeObject>());
 
         if (pendingPullIntos->getDenseInitializedLength() != 0) {
             // Step a: Let firstDescriptor be the first element of
             //         this.[[pendingPullIntos]].
             // Step b: Set firstDescriptor.[[bytesFilled]] to 0.
             PullIntoDescriptor* descriptor;
             descriptor = ToUnwrapped<PullIntoDescriptor>(cx, PeekList<JSObject>(pendingPullIntos));
-            if (!descriptor)
+            if (!descriptor) {
                 return nullptr;
+            }
             descriptor->setBytesFilled(0);
         }
     }
 
     RootedValue underlyingSource(cx);
     underlyingSource = controller->getFixedSlot(ControllerSlot_UnderlyingSource);
 
     // Step 1 of 3.8.5.1, step 2 of 3.10.5.1: Perform ! ResetQueue(this).
@@ -2928,36 +2957,39 @@ ReadableStreamControllerCancelSteps(JSCo
     if (ControllerFlags(controller) & ControllerFlag_ExternalSource) {
         bool needsWrapping = controller->compartment() != cx->compartment();
         RootedValue rval(cx);
         {
             RootedValue wrappedReason(cx, reason);
             mozilla::Maybe<AutoRealm> ar;
             if (needsWrapping) {
                 ar.emplace(cx, controller);
-                if (!cx->compartment()->wrap(cx, &wrappedReason))
+                if (!cx->compartment()->wrap(cx, &wrappedReason)) {
                     return nullptr;
+                }
             }
             void* source = underlyingSource.toPrivate();
             Rooted<ReadableStream*> stream(cx, StreamFromController(controller));
             rval = cx->runtime()->readableStreamCancelCallback(cx, stream, source,
                                                                 stream->embeddingFlags(),
                                                                 wrappedReason);
         }
 
-        if (needsWrapping && !cx->compartment()->wrap(cx, &rval))
+        if (needsWrapping && !cx->compartment()->wrap(cx, &rval)) {
             return nullptr;
+        }
         return PromiseObject::unforgeableResolve(cx, rval);
     }
 
     // If the stream and its controller aren't in the cx compartment, we have
     // to ensure that the underlying source is correctly wrapped before
     // operating on it.
-    if (!cx->compartment()->wrap(cx, &underlyingSource))
+    if (!cx->compartment()->wrap(cx, &underlyingSource)) {
         return nullptr;
+    }
 
     return PromiseInvokeOrNoop(cx, underlyingSource, cx->names().cancel, reason);
 }
 
 inline static MOZ_MUST_USE bool
 DequeueValue(JSContext* cx, Handle<ReadableStreamController*> container, MutableHandleValue chunk);
 
 /**
@@ -3001,18 +3033,19 @@ ReadableStreamDefaultControllerPullSteps
         // Step c: Otherwise, perform ! ReadableStreamDefaultControllerCallPullIfNeeded(this).
         else {
         if (!ReadableStreamControllerCallPullIfNeeded(cx, controller)) {
             return nullptr;
         }
         }
 
         // Step d: Return a promise resolved with ! CreateIterResultObject(chunk, false).
-        if (!cx->compartment()->wrap(cx, &chunk))
+        if (!cx->compartment()->wrap(cx, &chunk)) {
             return nullptr;
+        }
         RootedObject iterResultObj(cx, CreateIterResultObject(cx, chunk, false));
         if (!iterResultObj) {
             return nullptr;
         }
         RootedValue iterResult(cx, ObjectValue(*iterResultObj));
         return PromiseObject::unforgeableResolve(cx, iterResult);
     }
 
@@ -3036,18 +3069,19 @@ ReadableStreamDefaultControllerPullSteps
 static bool
 ControllerPullHandler(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     RootedValue controllerVal(cx, args.callee().as<JSFunction>().getExtendedSlot(0));
     Rooted<ReadableStreamController*> controller(cx);
     controller = ToUnwrapped<ReadableStreamController>(cx, controllerVal);
-    if (!controller)
+    if (!controller) {
         return false;
+    }
 
     uint32_t flags = ControllerFlags(controller);
 
     // Step a: Set controller.[[pulling]] to false.
     // Step b.i: Set controller.[[pullAgain]] to false.
     RemoveControllerFlags(controller, ControllerFlag_Pulling | ControllerFlag_PullAgain);
 
     // Step b: If controller.[[pullAgain]] is true,
@@ -3068,18 +3102,19 @@ static bool
 ControllerPullFailedHandler(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     HandleValue e = args.get(0);
 
     RootedValue controllerVal(cx, args.callee().as<JSFunction>().getExtendedSlot(0));
     Rooted<ReadableStreamController*> controller(cx);
     controller = ToUnwrapped<ReadableStreamController>(cx, controllerVal);
-    if (!controller)
+    if (!controller) {
         return false;
+    }
 
     // Step a: If controller.[[controlledReadableStream]].[[state]] is "readable",
     //         perform ! ReadableByteStreamControllerError(controller, e).
     if (StreamFromController(controller)->readable()) {
         if (!ReadableStreamControllerError(cx, controller, e)) {
             return false;
         }
     }
@@ -3127,18 +3162,19 @@ ReadableStreamControllerCallPullIfNeeded
     MOZ_ASSERT(!(ControllerFlags(controller) & ControllerFlag_PullAgain));
 
     // Step 5: Set controller.[[pulling]] to true.
     AddControllerFlags(controller, ControllerFlag_Pulling);
 
     // Step 6: Let pullPromise be
     //         ! PromiseInvokeOrNoop(controller.[[underlyingByteSource]], "pull", controller).
     RootedObject wrappedController(cx, controller);
-    if (!cx->compartment()->wrap(cx, &wrappedController))
+    if (!cx->compartment()->wrap(cx, &wrappedController)) {
         return false;
+    }
     RootedValue controllerVal(cx, ObjectValue(*wrappedController));
     RootedValue underlyingSource(cx);
     underlyingSource = controller->getFixedSlot(ControllerSlot_UnderlyingSource);
     RootedObject pullPromise(cx);
 
     if (IsMaybeWrapped<TeeState>(underlyingSource)) {
         Rooted<TeeState*> teeState(cx);
         teeState = &UncheckedUnwrap(&underlyingSource.toObject())->as<TeeState>();
@@ -3292,18 +3328,19 @@ ReadableStreamDefaultControllerEnqueue(J
         RootedValue chunkSize(cx, NumberValue(1));
         bool success = true;
 
         // Step b: If controller.[[strategySize]] is not undefined,
         RootedValue strategySize(cx);
         strategySize = controller->getFixedSlot(DefaultControllerSlot_StrategySize);
         if (!strategySize.isUndefined()) {
             // Step i: Set chunkSize to Call(stream.[[strategySize]], undefined, chunk).
-            if (!cx->compartment()->wrap(cx, &strategySize))
+            if (!cx->compartment()->wrap(cx, &strategySize)) {
                 return false;
+            }
             success = Call(cx, strategySize, UndefinedHandleValue, chunk, &chunkSize);
         }
 
         // Step c: Let enqueueResult be
         //         EnqueueValueWithSize(controller, chunk, chunkSize).
         if (success) {
             success = EnqueueValueWithSize(cx, controller, chunk, chunkSize);
         }
@@ -3709,18 +3746,19 @@ static MOZ_MUST_USE JSObject*
 ReadableByteStreamControllerPullSteps(JSContext* cx, Handle<ReadableStreamController*> controller)
 {
     // Step 1: Let stream be this.[[controlledReadableStream]].
     Rooted<ReadableStream*> stream(cx, StreamFromController(controller));
 
     // Step 2: Assert: ! ReadableStreamHasDefaultReader(stream) is true.
 #ifdef DEBUG
     bool result;
-    if (!ReadableStreamHasDefaultReader(cx, stream, &result))
+    if (!ReadableStreamHasDefaultReader(cx, stream, &result)) {
         return nullptr;
+    }
     MOZ_ASSERT(result);
 #endif
 
     RootedValue val(cx);
     // Step 3: If this.[[queueTotalSize]] > 0,
     double queueTotalSize = QueueSize(controller);
     if (queueTotalSize > 0) {
         // Step 3.a: Assert: ! ReadableStreamGetNumReadRequests(_stream_) is 0.
@@ -3755,27 +3793,29 @@ ReadableByteStreamControllerPullSteps(JS
         } else {
             // Step 3.b: Let entry be the first element of this.[[queue]].
             // Step 3.c: Remove entry from this.[[queue]], shifting all other elements
             //           downward (so that the second becomes the first, and so on).
             val = controller->getFixedSlot(QueueContainerSlot_Queue);
             RootedNativeObject queue(cx, &val.toObject().as<NativeObject>());
             Rooted<ByteStreamChunk*> entry(cx);
             entry = ToUnwrapped<ByteStreamChunk>(cx, ShiftFromList<JSObject>(cx, queue));
-            if (!entry)
+            if (!entry) {
                 return nullptr;
+            }
 
             queueTotalSize = queueTotalSize - entry->byteLength();
 
             // Step 3.f: Let view be ! Construct(%Uint8Array%, « entry.[[buffer]],
             //                                   entry.[[byteOffset]], entry.[[byteLength]] »).
             // (reordered)
             RootedObject buffer(cx, entry->buffer());
-            if (!cx->compartment()->wrap(cx, &buffer))
+            if (!cx->compartment()->wrap(cx, &buffer)) {
                 return nullptr;
+            }
 
             uint32_t byteOffset = entry->byteOffset();
             view = JS_NewUint8ArrayWithBuffer(cx, buffer, byteOffset, entry->byteLength());
             if (!view) {
                 return nullptr;
             }
         }
 
@@ -3899,18 +3939,19 @@ ReadableByteStreamControllerInvalidateBY
  */
 static MOZ_MUST_USE bool
 ReadableByteStreamControllerClearPendingPullIntos(JSContext* cx,
                                                   Handle<ReadableStreamController*> controller)
 {
     MOZ_ASSERT(controller->is<ReadableByteStreamController>());
 
     // Step 1: Perform ! ReadableByteStreamControllerInvalidateBYOBRequest(controller).
-    if (!ReadableByteStreamControllerInvalidateBYOBRequest(cx, controller))
+    if (!ReadableByteStreamControllerInvalidateBYOBRequest(cx, controller)) {
         return false;
+    }
 
     // Step 2: Set controller.[[pendingPullIntos]] to a new empty List.
     return SetNewList(cx, controller, ByteControllerSlot_PendingPullIntos);
 }
 
 /**
  * Streams spec, 3.12.5. ReadableByteStreamControllerClose ( controller )
  *
@@ -3943,18 +3984,19 @@ ReadableByteStreamControllerClose(JSCont
     RootedValue val(cx, controller->getFixedSlot(ByteControllerSlot_PendingPullIntos));
     RootedNativeObject pendingPullIntos(cx, &val.toObject().as<NativeObject>());
     if (pendingPullIntos->getDenseInitializedLength() != 0) {
         // Step a: Let firstPendingPullInto be the first element of
         //         controller.[[pendingPullIntos]].
         Rooted<PullIntoDescriptor*> firstPendingPullInto(cx);
         firstPendingPullInto = ToUnwrapped<PullIntoDescriptor>(cx,
                                                                PeekList<JSObject>(pendingPullIntos));
-        if (!firstPendingPullInto)
+        if (!firstPendingPullInto) {
             return false;
+        }
 
         // Step b: If firstPendingPullInto.[[bytesFilled]] > 0,
         if (firstPendingPullInto->bytesFilled() > 0) {
             // Step i: Let e be a new TypeError exception.
             JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
                                       JSMSG_READABLEBYTESTREAMCONTROLLER_CLOSE_PENDING_PULL);
             RootedValue e(cx);
             // Not much we can do about uncatchable exceptions, just bail.
@@ -4319,18 +4361,19 @@ inline static MOZ_MUST_USE bool
 AppendToListAtSlot(JSContext* cx, HandleNativeObject container, uint32_t slot, HandleObject obj)
 {
     RootedValue val(cx, container->getFixedSlot(slot));
     RootedNativeObject list(cx, &val.toObject().as<NativeObject>());
 
     val = ObjectValue(*obj);
 
     AutoRealm ar(cx, list);
-    if (!cx->compartment()->wrap(cx, &val))
+    if (!cx->compartment()->wrap(cx, &val)) {
         return false;
+    }
     return AppendToList(cx, list, val);
 }
 
 
 /**
  * Streams spec, 6.4.1. InvokeOrNoop ( O, P, args )
  */
 inline static MOZ_MUST_USE bool
@@ -4421,28 +4464,30 @@ ValidateAndNormalizeQueuingStrategy(JSCo
     return true;
 }
 
 MOZ_MUST_USE bool
 js::ReadableStreamReaderCancel(JSContext* cx, HandleObject readerObj, HandleValue reason)
 {
     Rooted<ReadableStreamReader*> reader(cx, &readerObj->as<ReadableStreamReader>());
     ReadableStream* stream = StreamFromReader(cx, reader);
-    if (!stream)
+    if (!stream) {
         return false;
+    }
     return ReadableStreamReaderGenericCancel(cx, reader, reason);
 }
 
 MOZ_MUST_USE bool
 js::ReadableStreamReaderReleaseLock(JSContext* cx, HandleObject readerObj)
 {
     Rooted<ReadableStreamReader*> reader(cx, &readerObj->as<ReadableStreamReader>());
     ReadableStream* stream = StreamFromReader(cx, reader);
-    if (!stream)
+    if (!stream) {
         return false;
+    }
     MOZ_ASSERT(ReadableStreamGetNumReadRequests(stream) == 0);
     return ReadableStreamReaderGenericRelease(cx, reader);
 }
 
 MOZ_MUST_USE bool
 ReadableStream::enqueue(JSContext* cx, Handle<ReadableStream*> stream, HandleValue chunk)
 {
     Rooted<ReadableStreamDefaultController*> controller(cx);
@@ -4554,18 +4599,19 @@ ReadableStream::updateDataAvailableFromS
     // Reordered because for externally-sourced streams it applies regardless
     // of reader type.
     if (ReadableStreamGetNumReadRequests(stream) == 0) {
         return true;
     }
 
     // Step 8: If ! ReadableStreamHasDefaultReader(stream) is true
     ReaderMode readerMode;
-    if (!ReadableStreamGetReaderMode(cx, stream, &readerMode))
+    if (!ReadableStreamGetReaderMode(cx, stream, &readerMode)) {
         return false;
+    }
 
     if (readerMode == ReaderMode::Default) {
         // Step b: Otherwise,
         // Step i: Assert: controller.[[queue]] is empty.
         MOZ_ASSERT(oldAvailableData == 0);
 
         // Step ii: Let transferredView be
         //          ! Construct(%Uint8Array%, transferredBuffer, byteOffset, byteLength).