Bug 1503718 - Part 4: Use the `unwrapped` prefix. Covers spec sections 6.1 to 6.3. r=tcampbell
authorJason Orendorff <jorendorff@mozilla.com>
Fri, 16 Nov 2018 12:40:24 +0000
changeset 503187 0771df5c7ac5b20852b8d5060515c7e3b4ec9173
parent 503186 1918d21eb212e46e671c7fdfd008406d4fee2ebb
child 503188 ca8c304d9bd96bb24544fd9f0f22a40df2ff803b
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1503718
milestone65.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 1503718 - Part 4: Use the `unwrapped` prefix. Covers spec sections 6.1 to 6.3. r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D11687
js/src/builtin/Stream.cpp
--- a/js/src/builtin/Stream.cpp
+++ b/js/src/builtin/Stream.cpp
@@ -3778,70 +3778,66 @@ CLASS_SPEC(CountQueuingStrategy, 1, 0, 0
 
 #undef CLASS_SPEC
 
 
 /*** 6.2. Queue-with-sizes operations ************************************************************/
 
 /**
  * Streams spec, 6.2.1. DequeueValue ( container ) nothrow
- *
- * Note: can operate on unwrapped queue container instances from another
- * compartment. In that case, the returned chunk will be wrapped into the
- * current compartment.
  */
 inline static MOZ_MUST_USE bool
-DequeueValue(JSContext* cx, Handle<ReadableStreamController*> container, MutableHandleValue chunk)
+DequeueValue(JSContext* cx, Handle<ReadableStreamController*> unwrappedContainer, MutableHandleValue chunk)
 {
     // Step 1: Assert: container has [[queue]] and [[queueTotalSize]] internal
     //         slots (implicit).
     // Step 2: Assert: queue is not empty.
-    RootedNativeObject queue(cx, container->queue());
-    MOZ_ASSERT(queue->getDenseInitializedLength() > 0);
+    RootedNativeObject unwrappedQueue(cx, unwrappedContainer->queue());
+    MOZ_ASSERT(unwrappedQueue->getDenseInitializedLength() > 0);
 
     // Step 3. Let pair be the first element of queue.
     // Step 4. Remove pair from queue, shifting all other elements downward
     //         (so that the second becomes the first, and so on).
-    Rooted<QueueEntry*> pair(cx, ShiftFromList<QueueEntry>(cx, queue));
-    MOZ_ASSERT(pair);
+    Rooted<QueueEntry*> unwrappedPair(cx, ShiftFromList<QueueEntry>(cx, unwrappedQueue));
+    MOZ_ASSERT(unwrappedPair);
 
     // Step 5: Set container.[[queueTotalSize]] to
     //         container.[[queueTotalSize]] − pair.[[size]].
     // Step 6: If container.[[queueTotalSize]] < 0, set
     //         container.[[queueTotalSize]] to 0.
     //         (This can occur due to rounding errors.)
-    double totalSize = container->queueTotalSize();
-
-    totalSize -= pair->size();
+    double totalSize = unwrappedContainer->queueTotalSize();
+
+    totalSize -= unwrappedPair->size();
     if (totalSize < 0) {
         totalSize = 0;
     }
-    container->setQueueTotalSize(totalSize);
-
-    RootedValue val(cx, pair->value());
-    if (container->compartment() != cx->compartment() && !cx->compartment()->wrap(cx, &val)) {
+    unwrappedContainer->setQueueTotalSize(totalSize);
+
+    RootedValue val(cx, unwrappedPair->value());
+    if (!cx->compartment()->wrap(cx, &val)) {
         return false;
     }
 
     // Step 7: Return pair.[[value]].
     chunk.set(val);
     return true;
 }
 
 /**
  * Streams spec, 6.2.2. EnqueueValueWithSize ( container, value, size ) throws
- *
- * Note: can operate on unwrapped queue container instances from another
- * compartment than the current one. In that case, the given value will be
- * wrapped into the container compartment.
  */
 static MOZ_MUST_USE bool
-EnqueueValueWithSize(JSContext* cx, Handle<ReadableStreamController*> container, HandleValue value,
+EnqueueValueWithSize(JSContext* cx,
+                     Handle<ReadableStreamController*> unwrappedContainer,
+                     HandleValue value,
                      HandleValue sizeVal)
 {
+    cx->check(value, sizeVal);
+
     // Step 1: Assert: container has [[queue]] and [[queueTotalSize]] internal
     //         slots (implicit).
     // Step 2: Let size be ? ToNumber(size).
     double size;
     if (!ToNumber(cx, sizeVal, &size)) {
         return false;
     }
 
@@ -3850,38 +3846,37 @@ EnqueueValueWithSize(JSContext* cx, Hand
     if (size < 0 || mozilla::IsNaN(size) || mozilla::IsInfinite(size)) {
         JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
                                   JSMSG_NUMBER_MUST_BE_FINITE_NON_NEGATIVE, "size");
         return false;
     }
 
     // Step 4: Append Record {[[value]]: value, [[size]]: size} as the last element
     //         of container.[[queue]].
-    RootedNativeObject queue(cx, container->queue());
-
-    RootedValue wrappedVal(cx, value);
     {
-        AutoRealm ar(cx, container);
+        AutoRealm ar(cx, unwrappedContainer);
+        RootedNativeObject queue(cx, unwrappedContainer->queue());
+        RootedValue wrappedVal(cx, value);
         if (!cx->compartment()->wrap(cx, &wrappedVal)) {
             return false;
         }
 
         QueueEntry* entry = QueueEntry::create(cx, wrappedVal, size);
         if (!entry) {
             return false;
         }
         RootedValue val(cx, ObjectValue(*entry));
         if (!AppendToList(cx, queue, val)) {
             return false;
         }
     }
 
     // Step 5: Set container.[[queueTotalSize]] to
     //         container.[[queueTotalSize]] + size.
-    container->setQueueTotalSize(container->queueTotalSize() + size);
+    unwrappedContainer->setQueueTotalSize(unwrappedContainer->queueTotalSize() + size);
 
     return true;
 }
 
 /**
  * Streams spec, 6.2.4. ResetQueue ( container ) nothrow
  *
  * Note: can operate on unwrapped container instances from another
@@ -3929,16 +3924,18 @@ AppendToListAtSlot(JSContext* cx,
 
 /**
  * Streams spec, 6.3.2. InvokeOrNoop ( O, P, args )
  */
 inline static MOZ_MUST_USE bool
 InvokeOrNoop(JSContext* cx, HandleValue O, HandlePropertyName P, HandleValue arg,
              MutableHandleValue rval)
 {
+    cx->check(O, P, arg);
+
     // Step 1: Assert: P is a valid property key (omitted).
     // Step 2: If args was not passed, let args be a new empty List (omitted).
     // Step 3: Let method be ? GetV(O, P).
     RootedValue method(cx);
     if (!GetProperty(cx, O, P, &method)) {
         return false;
     }
 
@@ -3953,16 +3950,18 @@ InvokeOrNoop(JSContext* cx, HandleValue 
 
 /**
  * Streams spec, obsolete (previously 6.4.3) PromiseInvokeOrNoop ( O, P, args )
  * Specialized to one arg, because that's what all stream related callers use.
  */
 static MOZ_MUST_USE JSObject*
 PromiseInvokeOrNoop(JSContext* cx, HandleValue O, HandlePropertyName P, HandleValue arg)
 {
+    cx->check(O, P, arg);
+
     // Step 1: Assert: O is not undefined.
     MOZ_ASSERT(!O.isUndefined());
 
     // Step 2: Assert: ! IsPropertyKey(P) is true (implicit).
     // Step 3: Assert: args is a List (omitted).
 
     // Step 4: Let returnValue be InvokeOrNoop(O, P, args).
     // Step 5: If returnValue is an abrupt completion, return a promise