From 1b8cc04eb0fe0fcf08a8e822569cdd27131cd291 Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Mon, 30 Jan 2023 21:48:51 -0500 Subject: [PATCH 1/3] stream: make readable byte stream cloneable --- lib/internal/webstreams/readablestream.js | 4 +++- .../test-webstream-byte-readable-clone.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-webstream-byte-readable-clone.js diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index 0df8f7aa7f6f35..0061beab8435be 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -281,7 +281,9 @@ class ReadableStream { this, source, extractHighWaterMark(highWaterMark, 0)); - return; + + // eslint-disable-next-line no-constructor-return + return makeTransferable(this); } if (type !== undefined) diff --git a/test/parallel/test-webstream-byte-readable-clone.js b/test/parallel/test-webstream-byte-readable-clone.js new file mode 100644 index 00000000000000..ee38b9c8e11c9b --- /dev/null +++ b/test/parallel/test-webstream-byte-readable-clone.js @@ -0,0 +1,18 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); + +{ + // https://github.com/nodejs/node/issues/46296 + const stream = new ReadableStream({ + start(controller) { + controller.close(); + }, + type: 'bytes', + }); + + const clone = structuredClone(stream); + + assert(clone instanceof ReadableStream); +} From 362b8e38abe6ee1d208e22ad5db5f120777f58b8 Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Mon, 30 Jan 2023 21:53:50 -0500 Subject: [PATCH 2/3] fix: test --- test/parallel/test-webstream-byte-readable-clone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-webstream-byte-readable-clone.js b/test/parallel/test-webstream-byte-readable-clone.js index ee38b9c8e11c9b..8f34b87370be15 100644 --- a/test/parallel/test-webstream-byte-readable-clone.js +++ b/test/parallel/test-webstream-byte-readable-clone.js @@ -12,7 +12,7 @@ const assert = require('assert'); type: 'bytes', }); - const clone = structuredClone(stream); + const clone = structuredClone(stream, { transfer: [stream] }); assert(clone instanceof ReadableStream); } From 26912bf6708ef4615ed60f8a0dab04a670e63c28 Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Mon, 30 Jan 2023 21:59:09 -0500 Subject: [PATCH 3/3] fix: lint --- .../test-webstream-byte-readable-clone.js | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-webstream-byte-readable-clone.js b/test/parallel/test-webstream-byte-readable-clone.js index 8f34b87370be15..debe25923c3382 100644 --- a/test/parallel/test-webstream-byte-readable-clone.js +++ b/test/parallel/test-webstream-byte-readable-clone.js @@ -1,18 +1,18 @@ -'use strict'; - -require('../common'); -const assert = require('assert'); - -{ - // https://github.com/nodejs/node/issues/46296 - const stream = new ReadableStream({ - start(controller) { - controller.close(); - }, - type: 'bytes', - }); - - const clone = structuredClone(stream, { transfer: [stream] }); - - assert(clone instanceof ReadableStream); -} +'use strict'; + +require('../common'); +const assert = require('assert'); + +{ + // https://github.com/nodejs/node/issues/46296 + const stream = new ReadableStream({ + start(controller) { + controller.close(); + }, + type: 'bytes', + }); + + const clone = structuredClone(stream, { transfer: [stream] }); + + assert(clone instanceof ReadableStream); +}