Bug 1507952 - Part 3: Move and rename CreateReadableStreamDefaultController. r=arai
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 22 Nov 2018 13:42:01 +0000
changeset 504205 7687d5a601cb074ba03e97af24ad93d0176867ca
parent 504204 5a0df7634eaf384506d4ed5213dff1235325ced1
child 504206 51f31e8ac73a27c2a1e71de4e546f2069a243bc7
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)
reviewersarai
bugs1507952
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 1507952 - Part 3: Move and rename CreateReadableStreamDefaultController. r=arai The body of the function is unchanged. Differential Revision: https://phabricator.services.mozilla.com/D12457
js/src/builtin/Stream.cpp
--- a/js/src/builtin/Stream.cpp
+++ b/js/src/builtin/Stream.cpp
@@ -484,21 +484,21 @@ const Class cls::protoClass_ = { \
     JS_NULL_CLASS_OPS, \
     &cls::classSpec_ \
 };
 
 
 /*** 3.2. Class ReadableStream **********************************************/
 
 static MOZ_MUST_USE ReadableStreamDefaultController*
-CreateReadableStreamDefaultController(JSContext* cx,
-                                      Handle<ReadableStream*> stream,
-                                      HandleValue underlyingSource,
-                                      HandleValue size,
-                                      double highWaterMarkVal);
+SetUpReadableStreamDefaultController(JSContext* cx,
+                                     Handle<ReadableStream*> stream,
+                                     HandleValue underlyingSource,
+                                     HandleValue size,
+                                     double highWaterMarkVal);
 
 /**
  * Streams spec, 3.2.3., steps 1-4, 8.
  */
 ReadableStream*
 ReadableStream::createDefaultStream(JSContext* cx, HandleValue underlyingSource,
                                     HandleValue size, double highWaterMark,
                                     HandleObject proto /* = nullptr */)
@@ -513,18 +513,18 @@ ReadableStream::createDefaultStream(JSCo
         return nullptr;
     }
 
     // Step 8.b: Set this.[[readableStreamController]] to
     //           ? Construct(ReadableStreamDefaultController,
     //                       « this, underlyingSource, size,
     //                         highWaterMark »).
     ReadableStreamDefaultController* controller =
-        CreateReadableStreamDefaultController(cx, stream, underlyingSource, size,
-                                              highWaterMark);
+        SetUpReadableStreamDefaultController(cx, stream, underlyingSource, size,
+                                             highWaterMark);
     if (!controller) {
         return nullptr;
     }
     stream->setController(controller);
     return stream;
 }
 
 static MOZ_MUST_USE ReadableByteStreamController*
@@ -2287,99 +2287,16 @@ ControllerStartFailedHandler(JSContext* 
         }
     }
 
     args.rval().setUndefined();
     return true;
 }
 
 /**
- * Streams spec, 3.8.3
- *      new ReadableStreamDefaultController ( stream, underlyingSource,
- *                                            size, highWaterMark )
- * Steps 3 - 11.
- *
- * Note: All arguments must be same-compartment with cx. ReadableStream
- * controllers are always created in the same compartment as the stream.
- */
-static MOZ_MUST_USE ReadableStreamDefaultController*
-CreateReadableStreamDefaultController(JSContext* cx,
-                                      Handle<ReadableStream*> stream,
-                                      HandleValue underlyingSource,
-                                      HandleValue size,
-                                      double highWaterMark)
-{
-    cx->check(stream, underlyingSource, size);
-    MOZ_ASSERT(highWaterMark >= 0);
-    MOZ_ASSERT(size.isUndefined() || IsCallable(size));
-
-    Rooted<ReadableStreamDefaultController*> controller(cx,
-        NewBuiltinClassInstance<ReadableStreamDefaultController>(cx));
-    if (!controller) {
-        return nullptr;
-    }
-
-    // Step 3: Set this.[[controlledReadableStream]] to stream.
-    controller->setStream(stream);
-
-    // Step 4: Set this.[[underlyingSource]] to underlyingSource.
-    controller->setUnderlyingSource(underlyingSource);
-
-    // Step 5: Perform ! ResetQueue(this).
-    if (!ResetQueue(cx, controller)) {
-        return nullptr;
-    }
-
-    // Step 6: Set this.[[started]], this.[[closeRequested]], this.[[pullAgain]],
-    //         and this.[[pulling]] to false.
-    controller->setFlags(0);
-
-    // Step 7: Let normalizedStrategy be
-    //         ? ValidateAndNormalizeQueuingStrategy(size, highWaterMark)
-    //         (implicit).
-
-    // Step 8: Set this.[[strategySize]] to normalizedStrategy.[[size]] and
-    //         this.[[strategyHWM]] to normalizedStrategy.[[highWaterMark]].
-    controller->setStrategySize(size);
-    controller->setStrategyHWM(highWaterMark);
-
-    // Step 9: Let controller be this (implicit).
-
-    // Step 10: Let startResult be
-    //          ? InvokeOrNoop(underlyingSource, "start", « this »).
-    RootedValue startResult(cx);
-    RootedValue controllerVal(cx, ObjectValue(*controller));
-    if (!InvokeOrNoop(cx, underlyingSource, cx->names().start, controllerVal, &startResult)) {
-        return nullptr;
-    }
-
-    // Step 11: Let startPromise be a promise resolved with startResult:
-    RootedObject startPromise(cx, PromiseObject::unforgeableResolve(cx, startResult));
-    if (!startPromise) {
-        return nullptr;
-    }
-
-    RootedObject onStartFulfilled(cx, NewHandler(cx, ControllerStartHandler, controller));
-    if (!onStartFulfilled) {
-        return nullptr;
-    }
-
-    RootedObject onStartRejected(cx, NewHandler(cx, ControllerStartFailedHandler, controller));
-    if (!onStartRejected) {
-        return nullptr;
-    }
-
-    if (!JS::AddPromiseReactions(cx, startPromise, onStartFulfilled, onStartRejected)) {
-        return nullptr;
-    }
-
-    return controller;
-}
-
-/**
  * Streams spec, 3.8.3.
  * new ReadableStreamDefaultController( stream, underlyingSource, size,
  *                                      highWaterMark )
  */
 bool
 ReadableStreamDefaultController::constructor(JSContext* cx, unsigned argc, Value* vp)
 {
     // Step 1: Throw a TypeError.
@@ -3148,16 +3065,99 @@ ReadableStreamControllerGetDesiredSizeUn
     ReadableStream* stream = controller->stream();
     MOZ_ASSERT(!(stream->errored() || stream->closed()));
 #endif // DEBUG
 
     // Step 5: Return controller.[[strategyHWM]] − controller.[[queueTotalSize]].
     return controller->strategyHWM() - controller->queueTotalSize();
 }
 
+/**
+ * Streams spec, 3.9.11.
+ *      SetUpReadableStreamDefaultController(stream, controller,
+ *          startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark,
+ *          sizeAlgorithm )
+ *
+ * Note: All arguments must be same-compartment with cx. ReadableStream
+ * controllers are always created in the same compartment as the stream.
+ */
+static MOZ_MUST_USE ReadableStreamDefaultController*
+SetUpReadableStreamDefaultController(JSContext* cx,
+                                     Handle<ReadableStream*> stream,
+                                     HandleValue underlyingSource,
+                                     HandleValue size,
+                                     double highWaterMark)
+{
+    cx->check(stream, underlyingSource, size);
+    MOZ_ASSERT(highWaterMark >= 0);
+    MOZ_ASSERT(size.isUndefined() || IsCallable(size));
+
+    Rooted<ReadableStreamDefaultController*> controller(cx,
+        NewBuiltinClassInstance<ReadableStreamDefaultController>(cx));
+    if (!controller) {
+        return nullptr;
+    }
+
+    // Step 3: Set this.[[controlledReadableStream]] to stream.
+    controller->setStream(stream);
+
+    // Step 4: Set this.[[underlyingSource]] to underlyingSource.
+    controller->setUnderlyingSource(underlyingSource);
+
+    // Step 5: Perform ! ResetQueue(this).
+    if (!ResetQueue(cx, controller)) {
+        return nullptr;
+    }
+
+    // Step 6: Set this.[[started]], this.[[closeRequested]], this.[[pullAgain]],
+    //         and this.[[pulling]] to false.
+    controller->setFlags(0);
+
+    // Step 7: Let normalizedStrategy be
+    //         ? ValidateAndNormalizeQueuingStrategy(size, highWaterMark)
+    //         (implicit).
+
+    // Step 8: Set this.[[strategySize]] to normalizedStrategy.[[size]] and
+    //         this.[[strategyHWM]] to normalizedStrategy.[[highWaterMark]].
+    controller->setStrategySize(size);
+    controller->setStrategyHWM(highWaterMark);
+
+    // Step 9: Let controller be this (implicit).
+
+    // Step 10: Let startResult be
+    //          ? InvokeOrNoop(underlyingSource, "start", « this »).
+    RootedValue startResult(cx);
+    RootedValue controllerVal(cx, ObjectValue(*controller));
+    if (!InvokeOrNoop(cx, underlyingSource, cx->names().start, controllerVal, &startResult)) {
+        return nullptr;
+    }
+
+    // Step 11: Let startPromise be a promise resolved with startResult:
+    RootedObject startPromise(cx, PromiseObject::unforgeableResolve(cx, startResult));
+    if (!startPromise) {
+        return nullptr;
+    }
+
+    RootedObject onStartFulfilled(cx, NewHandler(cx, ControllerStartHandler, controller));
+    if (!onStartFulfilled) {
+        return nullptr;
+    }
+
+    RootedObject onStartRejected(cx, NewHandler(cx, ControllerStartFailedHandler, controller));
+    if (!onStartRejected) {
+        return nullptr;
+    }
+
+    if (!JS::AddPromiseReactions(cx, startPromise, onStartFulfilled, onStartRejected)) {
+        return nullptr;
+    }
+
+    return controller;
+}
+
 
 /*** 3.10. Class ReadableByteStreamController *******************************/
 
 #if 0 // disable user-defined byte streams
 
 /**
  * Streams spec, 3.10.3
  *      new ReadableByteStreamController ( stream, underlyingSource,