Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/internal/webstreams/readablestream.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -639,6 +639,7 @@ ObjectDefineProperties(ReadableStream, {
});

function InternalTransferredReadableStream() {
ObjectSetPrototypeOf(this, ReadableStream.prototype);
markTransferMode(this, false, true);
this[kType] = 'ReadableStream';
this[kState] = createReadableStreamState();
Expand DownExpand Up@@ -1226,6 +1227,7 @@ ObjectDefineProperties(ReadableByteStreamController.prototype, {
});

function InternalReadableStream(start, pull, cancel, highWaterMark, size) {
ObjectSetPrototypeOf(this, ReadableStream.prototype);
markTransferMode(this, false, true);
this[kType] = 'ReadableStream';
this[kState] = createReadableStreamState();
Expand DownExpand Up@@ -1253,6 +1255,7 @@ function createReadableStream(start, pull, cancel, highWaterMark = 1, size = ()
}

function InternalReadableByteStream(start, pull, cancel) {
ObjectSetPrototypeOf(this, ReadableStream.prototype);
markTransferMode(this, false, true);
this[kType] = 'ReadableStream';
this[kState] = createReadableStreamState();
Expand Down
1 change: 1 addition & 0 deletions lib/internal/webstreams/transformstream.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -256,6 +256,7 @@ ObjectDefineProperties(TransformStream.prototype, {
});

function InternalTransferredTransformStream() {
ObjectSetPrototypeOf(this, TransformStream.prototype);
markTransferMode(this, false, true);
this[kType] = 'TransformStream';
this[kState] = {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/webstreams/writablestream.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -300,6 +300,7 @@ ObjectDefineProperties(WritableStream.prototype, {
});

function InternalTransferredWritableStream() {
ObjectSetPrototypeOf(this, WritableStream.prototype);
markTransferMode(this, false, true);
this[kType] = 'WritableStream';
this[kState] = createWritableStreamState();
Expand DownExpand Up@@ -516,6 +517,7 @@ ObjectDefineProperties(WritableStreamDefaultController.prototype, {
});

function InternalWritableStream(start, write, close, abort, highWaterMark, size) {
ObjectSetPrototypeOf(this, WritableStream.prototype);
markTransferMode(this, false, true);
this[kType] = 'WritableStream';
this[kState] = createWritableStreamState();
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-structuredClone-global.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,20 @@ assert.strictEqual(structuredClone(undefined, null), undefined);
assert.strictEqual(structuredClone(undefined, { transfer: null }), undefined);
assert.strictEqual(structuredClone(undefined, { }), undefined);

// Transferables or its subclasses should be received with its closest transferable superclass
for (const StreamClass of [ReadableStream, WritableStream, TransformStream]) {
const original = new StreamClass();
const transfer = structuredClone(original, { transfer: [original] });
assert.strictEqual(Object.getPrototypeOf(transfer), StreamClass.prototype);
assert.ok(transfer instanceof StreamClass);

const extended = class extends StreamClass {};
const extendedOriginal = new extended();
const extendedTransfer = structuredClone(extendedOriginal, { transfer: [extendedOriginal] });
assert.strictEqual(Object.getPrototypeOf(extendedTransfer), StreamClass.prototype);
assert.ok(extendedTransfer instanceof StreamClass);
}

{
// See: https://github.com/nodejs/node/issues/49940
const cloned = structuredClone({}, {
Expand Down