Bug 1510717 - Part 3: #ifdef out more code involving user-defined byte streams. r=jwalden
authorJason Orendorff <jorendorff@mozilla.com>
Tue, 04 Dec 2018 19:55:43 +0000
changeset 508539 146b5bd178c1f3554aa9dd47854ee84e28e2c6e0
parent 508538 a9aecbc2d273351da812e8a365485a0ea67e6bea
child 508540 67fb6d9224a1f2debc5fa535c11427cd6911535e
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1510717
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 1510717 - Part 3: #ifdef out more code involving user-defined byte streams. r=jwalden Differential Revision: https://phabricator.services.mozilla.com/D13295
js/src/builtin/Stream.cpp
--- a/js/src/builtin/Stream.cpp
+++ b/js/src/builtin/Stream.cpp
@@ -158,52 +158,64 @@ inline static MOZ_MUST_USE bool SetNewLi
   ListObject* list = ListObject::create(cx);
   if (!list) {
     return false;
   }
   unwrappedContainer->setFixedSlot(slot, ObjectValue(*list));
   return true;
 }
 
-class ByteStreamChunk : public NativeObject {
- private:
-  enum Slots { Slot_Buffer = 0, Slot_ByteOffset, Slot_ByteLength, SlotCount };
-
- public:
-  static const Class class_;
-
-  ArrayBufferObject* buffer() {
-    return &getFixedSlot(Slot_Buffer).toObject().as<ArrayBufferObject>();
-  }
-  uint32_t byteOffset() { return getFixedSlot(Slot_ByteOffset).toInt32(); }
-  void SetByteOffset(uint32_t offset) {
-    setFixedSlot(Slot_ByteOffset, Int32Value(offset));
-  }
-  uint32_t byteLength() { return getFixedSlot(Slot_ByteLength).toInt32(); }
-  void SetByteLength(uint32_t length) {
-    setFixedSlot(Slot_ByteLength, Int32Value(length));
-  }
-
-  static ByteStreamChunk* create(JSContext* cx, HandleObject buffer,
-                                 uint32_t byteOffset, uint32_t byteLength) {
-    Rooted<ByteStreamChunk*> chunk(
-        cx, NewBuiltinClassInstance<ByteStreamChunk>(cx));
-    if (!chunk) {
-      return nullptr;
+#if 0  // disable user-defined byte streams
+
+class ByteStreamChunk : public NativeObject
+{
+  private:
+    enum Slots {
+        Slot_Buffer = 0,
+        Slot_ByteOffset,
+        Slot_ByteLength,
+        SlotCount
+    };
+
+  public:
+    static const Class class_;
+
+    ArrayBufferObject* buffer() {
+        return &getFixedSlot(Slot_Buffer).toObject().as<ArrayBufferObject>();
+    }
+    uint32_t byteOffset() { return getFixedSlot(Slot_ByteOffset).toInt32(); }
+    void SetByteOffset(uint32_t offset) {
+        setFixedSlot(Slot_ByteOffset, Int32Value(offset));
     }
-
-    chunk->setFixedSlot(Slot_Buffer, ObjectValue(*buffer));
-    chunk->setFixedSlot(Slot_ByteOffset, Int32Value(byteOffset));
-    chunk->setFixedSlot(Slot_ByteLength, Int32Value(byteLength));
-    return chunk;
-  }
+    uint32_t byteLength() { return getFixedSlot(Slot_ByteLength).toInt32(); }
+    void SetByteLength(uint32_t length) {
+        setFixedSlot(Slot_ByteLength, Int32Value(length));
+    }
+
+    static ByteStreamChunk* create(JSContext* cx, HandleObject buffer, uint32_t byteOffset,
+                                   uint32_t byteLength)
+    {
+        Rooted<ByteStreamChunk*> chunk(cx, NewBuiltinClassInstance<ByteStreamChunk>(cx));
+        if (!chunk) {
+            return nullptr;
+        }
+
+        chunk->setFixedSlot(Slot_Buffer, ObjectValue(*buffer));
+        chunk->setFixedSlot(Slot_ByteOffset, Int32Value(byteOffset));
+        chunk->setFixedSlot(Slot_ByteLength, Int32Value(byteLength));
+        return chunk;
+    }
 };
 
-const Class ByteStreamChunk::class_ = {"ByteStreamChunk",
-                                       JSCLASS_HAS_RESERVED_SLOTS(SlotCount)};
+const Class ByteStreamChunk::class_ = {
+    "ByteStreamChunk",
+    JSCLASS_HAS_RESERVED_SLOTS(SlotCount)
+};
+
+#endif  // user-defined byte streams
 
 class PullIntoDescriptor : public NativeObject {
  private:
   enum Slots {
     Slot_buffer,
     Slot_ByteOffset,
     Slot_ByteLength,
     Slot_BytesFilled,
@@ -3392,17 +3404,22 @@ static MOZ_MUST_USE JSObject* ReadableBy
   // Step 3: If this.[[queueTotalSize]] > 0,
   double queueTotalSize = unwrappedController->queueTotalSize();
   if (queueTotalSize > 0) {
     // Step 3.a: Assert: ! ReadableStreamGetNumReadRequests(_stream_) is 0.
     MOZ_ASSERT(ReadableStreamGetNumReadRequests(unwrappedStream) == 0);
 
     RootedObject view(cx);
 
-    if (unwrappedStream->mode() == JS::ReadableStreamMode::ExternalSource) {
+    MOZ_RELEASE_ASSERT(unwrappedStream->mode() ==
+                       JS::ReadableStreamMode::ExternalSource);
+#if 0   // disable user-defined byte streams
+        if (unwrappedStream->mode() == JS::ReadableStreamMode::ExternalSource)
+#endif  // user-defined byte streams
+    {
       JS::ReadableStreamUnderlyingSource* source =
           unwrappedController->externalSource();
 
       view = JS_NewUint8Array(cx, queueTotalSize);
       if (!view) {
         return nullptr;
       }
 
@@ -3414,49 +3431,52 @@ static MOZ_MUST_USE JSObject* ReadableBy
         bool dummy;
         void* buffer = JS_GetArrayBufferViewData(view, &dummy, noGC);
 
         source->writeIntoReadRequestBuffer(cx, unwrappedStream, buffer,
                                            queueTotalSize, &bytesWritten);
       }
 
       queueTotalSize = queueTotalSize - bytesWritten;
-    } 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).
-      Rooted<ListObject*> unwrappedQueue(cx, unwrappedController->queue());
-      Rooted<ByteStreamChunk*> unwrappedEntry(
-          cx, UnwrapAndDowncastObject<ByteStreamChunk>(
-                  cx, &unwrappedQueue->popFirstAs<JSObject>(cx)));
-      if (!unwrappedEntry) {
-        return nullptr;
-      }
-
-      queueTotalSize = queueTotalSize - unwrappedEntry->byteLength();
-
-      // Step 3.f: Let view be ! Construct(%Uint8Array%,
-      //                                   « entry.[[buffer]],
-      //                                     entry.[[byteOffset]],
-      //                                     entry.[[byteLength]] »).
-      // (reordered)
-      RootedObject buffer(cx, unwrappedEntry->buffer());
-      if (!cx->compartment()->wrap(cx, &buffer)) {
-        return nullptr;
-      }
-
-      uint32_t byteOffset = unwrappedEntry->byteOffset();
-      view = JS_NewUint8ArrayWithBuffer(cx, buffer, byteOffset,
-                                        unwrappedEntry->byteLength());
-      if (!view) {
-        return nullptr;
-      }
     }
 
+#if 0   // disable user-defined byte streams
+        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).
+            Rooted<ListObject*> unwrappedQueue(cx, unwrappedController->queue());
+            Rooted<ByteStreamChunk*> unwrappedEntry(cx,
+                UnwrapAndDowncastObject<ByteStreamChunk>(
+                    cx, &unwrappedQueue->popFirstAs<JSObject>(cx)));
+            if (!unwrappedEntry) {
+                return nullptr;
+            }
+
+            queueTotalSize = queueTotalSize - unwrappedEntry->byteLength();
+
+            // Step 3.f: Let view be ! Construct(%Uint8Array%,
+            //                                   « entry.[[buffer]],
+            //                                     entry.[[byteOffset]],
+            //                                     entry.[[byteLength]] »).
+            // (reordered)
+            RootedObject buffer(cx, unwrappedEntry->buffer());
+            if (!cx->compartment()->wrap(cx, &buffer)) {
+                return nullptr;
+            }
+
+            uint32_t byteOffset = unwrappedEntry->byteOffset();
+            view = JS_NewUint8ArrayWithBuffer(cx, buffer, byteOffset, unwrappedEntry->byteLength());
+            if (!view) {
+                return nullptr;
+            }
+        }
+#endif  // user-defined byte streams
+
     // Step 3.d: Set this.[[queueTotalSize]] to
     //           this.[[queueTotalSize]] − entry.[[byteLength]].
     // (reordered)
     unwrappedController->setQueueTotalSize(queueTotalSize);
 
     // Step 3.e: Perform ! ReadableByteStreamControllerHandleQueueDrain(this).
     // (reordered)
     if (!ReadableByteStreamControllerHandleQueueDrain(cx,