Bug 1507952 - Part 1: Rename ReadableStream::createStream() to create() and make it our implementation of 3.3.5. r=arai
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 22 Nov 2018 13:41:33 +0000
changeset 504203 dc904523f5a381ed77904a2b4db577160a2a4e03
parent 504202 77623171e512127f109569942fd4ae8468d2cf60
child 504204 5a0df7634eaf384506d4ed5213dff1235325ced1
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 1: Rename ReadableStream::createStream() to create() and make it our implementation of 3.3.5. r=arai The general approach of this stack is to update our code to the current standard and let the bug fixes fall out of that, as a side effect. Differential Revision: https://phabricator.services.mozilla.com/D12454
js/src/builtin/Stream.cpp
js/src/builtin/Stream.h
--- a/js/src/builtin/Stream.cpp
+++ b/js/src/builtin/Stream.cpp
@@ -483,54 +483,33 @@ const Class cls::protoClass_ = { \
     JSCLASS_HAS_CACHED_PROTO(JSProto_##cls), \
     JS_NULL_CLASS_OPS, \
     &cls::classSpec_ \
 };
 
 
 /*** 3.2. Class ReadableStream **********************************************/
 
-/**
- * Streams spec, 3.2.3., steps 1-4.
- */
-ReadableStream*
-ReadableStream::createStream(JSContext* cx, HandleObject proto /* = nullptr */)
-{
-    Rooted<ReadableStream*> stream(cx, NewObjectWithClassProto<ReadableStream>(cx, proto));
-    if (!stream) {
-        return nullptr;
-    }
-
-    // Step 1: Set this.[[state]] to "readable".
-    // Step 2: Set this.[[reader]] and this.[[storedError]] to
-    //         undefined (implicit).
-    // Step 3: Set this.[[disturbed]] to false (implicit).
-    // Step 4: Set this.[[readableStreamController]] to undefined (implicit).
-    stream->initStateBits(Readable);
-
-    return stream;
-}
-
 static MOZ_MUST_USE ReadableStreamDefaultController*
 CreateReadableStreamDefaultController(JSContext* cx,
                                       Handle<ReadableStream*> stream,
                                       HandleValue underlyingSource,
                                       HandleValue size,
                                       HandleValue highWaterMarkVal);
 
 /**
  * Streams spec, 3.2.3., steps 1-4, 8.
  */
 ReadableStream*
 ReadableStream::createDefaultStream(JSContext* cx, HandleValue underlyingSource,
                                     HandleValue size, HandleValue highWaterMark,
                                     HandleObject proto /* = nullptr */)
 {
     // Steps 1-4.
-    Rooted<ReadableStream*> stream(cx, createStream(cx));
+    Rooted<ReadableStream*> stream(cx, create(cx));
     if (!stream) {
         return nullptr;
     }
 
     // Step 8.b: Set this.[[readableStreamController]] to
     //           ? Construct(ReadableStreamDefaultController,
     //                       « this, underlyingSource, size,
     //                         highWaterMark »).
@@ -546,17 +525,17 @@ ReadableStream::createDefaultStream(JSCo
 static MOZ_MUST_USE ReadableByteStreamController*
 CreateExternalReadableByteStreamController(JSContext* cx, Handle<ReadableStream*> stream,
                                            void* underlyingSource);
 
 ReadableStream*
 ReadableStream::createExternalSourceStream(JSContext* cx, void* underlyingSource,
                                            uint8_t flags, HandleObject proto /* = nullptr */)
 {
-    Rooted<ReadableStream*> stream(cx, createStream(cx, proto));
+    Rooted<ReadableStream*> stream(cx, create(cx, proto));
     if (!stream) {
         return nullptr;
     }
 
     Rooted<ReadableStreamController*> controller(cx);
     controller = CreateExternalReadableByteStreamController(cx, stream, underlyingSource);
     if (!controller) {
         return nullptr;
@@ -856,18 +835,43 @@ CLASS_SPEC(ReadableStream, 0, SlotCount,
 //                          [, highWaterMark [, sizeAlgorithm ] ] )
 // Not implemented.
 
 // Streams spec, 3.3.4. CreateReadableByteStream (
 //                          startAlgorithm, pullAlgorithm, cancelAlgorithm
 //                          [, highWaterMark [, autoAllocateChunkSize ] ] )
 // Not implemented.
 
-// Streams spec, 3.3.5. InitializeReadableStream ( stream )
-// Not implemented.
+/**
+ * Streams spec, 3.3.5. InitializeReadableStream ( stream )
+ */
+MOZ_MUST_USE /* static */ ReadableStream*
+ReadableStream::create(JSContext* cx, HandleObject proto /* = nullptr */)
+{
+    // In the spec, InitializeReadableStream is always passed a newly created
+    // ReadableStream object. We instead create it here and return it below.
+    Rooted<ReadableStream*> stream(cx, NewObjectWithClassProto<ReadableStream>(cx, proto));
+    if (!stream) {
+        return nullptr;
+    }
+
+    // Step 1: Set stream.[[state]] to "readable".
+    stream->initStateBits(Readable);
+    MOZ_ASSERT(stream->readable());
+
+    // Step 2: Set stream.[[reader]] and stream.[[storedError]] to
+    //         undefined (implicit).
+    MOZ_ASSERT(!stream->hasReader());
+    MOZ_ASSERT(stream->storedError().isUndefined());
+
+    // Step 3: Set stream.[[disturbed]] to false (done in step 1).
+    MOZ_ASSERT(!stream->disturbed());
+
+    return stream;
+}
 
 // Streams spec, 3.3.6. IsReadableStream ( x )
 // Using is<T> instead.
 
 // Streams spec, 3.3.7. IsReadableStreamDisturbed ( stream )
 // Using stream->disturbed() instead.
 
 /**
--- a/js/src/builtin/Stream.h
+++ b/js/src/builtin/Stream.h
@@ -100,17 +100,17 @@ class ReadableStream : public NativeObje
   public:
     static ReadableStream* createDefaultStream(JSContext* cx, HandleValue underlyingSource,
                                                HandleValue size, HandleValue highWaterMark,
                                                HandleObject proto = nullptr);
     static ReadableStream* createExternalSourceStream(JSContext* cx, void* underlyingSource,
                                                       uint8_t flags, HandleObject proto = nullptr);
 
   private:
-    static MOZ_MUST_USE ReadableStream* createStream(JSContext* cx, HandleObject proto = nullptr);
+    static MOZ_MUST_USE ReadableStream* create(JSContext* cx, HandleObject proto = nullptr);
 
   public:
     static bool constructor(JSContext* cx, unsigned argc, Value* vp);
     static const ClassSpec classSpec_;
     static const Class class_;
     static const ClassSpec protoClassSpec_;
     static const Class protoClass_;
 };