Skip to content

Commit

Permalink
stream: construct correct prototype to transferred streams
Browse files Browse the repository at this point in the history
  • Loading branch information
avivkeller committed Sep 21, 2024
1 parent 5116578 commit fe71574
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 58 deletions.
23 changes: 7 additions & 16 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
PromisePrototypeThen,
PromiseReject,
PromiseResolve,
ReflectConstruct,
SafePromiseAll,
Symbol,
SymbolAsyncIterator,
Expand Down Expand Up @@ -638,23 +639,13 @@ ObjectDefineProperties(ReadableStream, {
from: kEnumerableProperty,
});

function InternalTransferredReadableStream() {
markTransferMode(this, false, true);
this[kType] = 'ReadableStream';
this[kState] = createReadableStreamState();

this[kIsClosedPromise] = createDeferredPromise();
}

ObjectSetPrototypeOf(InternalTransferredReadableStream.prototype, ReadableStream.prototype);
ObjectSetPrototypeOf(InternalTransferredReadableStream, ReadableStream);

function TransferredReadableStream() {
const stream = new InternalTransferredReadableStream();

stream.constructor = ReadableStream;

return stream;
return ReflectConstruct(function() {
markTransferMode(this, false, true);
this[kType] = 'ReadableStream';
this[kState] = createReadableStreamState();
this[kIsClosedPromise] = createDeferredPromise();
}, [], ReadableStream);
}

TransferredReadableStream.prototype[kDeserialize] = () => {};
Expand Down
44 changes: 18 additions & 26 deletions lib/internal/webstreams/transformstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
ObjectDefineProperties,
ObjectSetPrototypeOf,

Check failure on line 6 in lib/internal/webstreams/transformstream.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'ObjectSetPrototypeOf' is assigned a value but never used
PromisePrototypeThen,
ReflectConstruct,
Symbol,
SymbolToStringTag,
} = primordials;
Expand Down Expand Up @@ -255,33 +256,24 @@ ObjectDefineProperties(TransformStream.prototype, {
[SymbolToStringTag]: getNonWritablePropertyDescriptor(TransformStream.name),
});

function InternalTransferredTransformStream() {
markTransferMode(this, false, true);
this[kType] = 'TransformStream';
this[kState] = {
__proto__: null,
readable: undefined,
writable: undefined,
backpressure: undefined,
backpressureChange: {
__proto__: null,
promise: undefined,
resolve: undefined,
reject: undefined,
},
controller: undefined,
};
}

ObjectSetPrototypeOf(InternalTransferredTransformStream.prototype, TransformStream.prototype);
ObjectSetPrototypeOf(InternalTransferredTransformStream, TransformStream);

function TransferredTransformStream() {
const stream = new InternalTransferredTransformStream();

stream.constructor = TransformStream;

return stream;
return ReflectConstruct(function() {
markTransferMode(this, false, true);
this[kType] = 'TransformStream';
this[kState] = {
__proto__: null,
readable: undefined,
writable: undefined,
backpressure: undefined,
backpressureChange: {
__proto__: null,
promise: undefined,
resolve: undefined,
reject: undefined,
},
controller: undefined,
};
}, [], TransformStream);
}

TransferredTransformStream.prototype[kDeserialize] = () => {};
Expand Down
23 changes: 7 additions & 16 deletions lib/internal/webstreams/writablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
PromisePrototypeThen,
PromiseReject,
PromiseResolve,
ReflectConstruct,
Symbol,
SymbolToStringTag,
} = primordials;
Expand Down Expand Up @@ -299,23 +300,13 @@ ObjectDefineProperties(WritableStream.prototype, {
[SymbolToStringTag]: getNonWritablePropertyDescriptor(WritableStream.name),
});

function InternalTransferredWritableStream() {
markTransferMode(this, false, true);
this[kType] = 'WritableStream';
this[kState] = createWritableStreamState();

this[kIsClosedPromise] = createDeferredPromise();
}

ObjectSetPrototypeOf(InternalTransferredWritableStream.prototype, WritableStream.prototype);
ObjectSetPrototypeOf(InternalTransferredWritableStream, WritableStream);

function TransferredWritableStream() {
const stream = new InternalTransferredWritableStream();

stream.constructor = WritableStream;

return stream;
return ReflectConstruct(function() {
markTransferMode(this, false, true);
this[kType] = 'WritableStream';
this[kState] = createWritableStreamState();
this[kIsClosedPromise] = createDeferredPromise();
}, [], WritableStream);
}

TransferredWritableStream.prototype[kDeserialize] = () => {};
Expand Down

0 comments on commit fe71574

Please sign in to comment.