Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: fix web streams have no Symbol.toStringTag #45117

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/internal/webstreams/queuingstrategies.js
Expand Up @@ -56,14 +56,20 @@ const byteSizeFunction = ObjectDefineProperty(
);
const countSizeFunction = ObjectDefineProperty(() => 1, 'name', nameDescriptor);

const getNonWritablePropertyDescriptor = (value) => {
return {
__proto__: null,
configurable: true,
value,
};
};

/**
* @type {QueuingStrategy}
*/
class ByteLengthQueuingStrategy {
[kType] = 'ByteLengthQueuingStrategy';

get [SymbolToStringTag]() { return this[kType]; }

/**
* @param {{
* highWaterMark : number
Expand Down Expand Up @@ -110,6 +116,7 @@ class ByteLengthQueuingStrategy {
ObjectDefineProperties(ByteLengthQueuingStrategy.prototype, {
highWaterMark: kEnumerableProperty,
size: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(ByteLengthQueuingStrategy.name),
});

/**
Expand All @@ -118,8 +125,6 @@ ObjectDefineProperties(ByteLengthQueuingStrategy.prototype, {
class CountQueuingStrategy {
[kType] = 'CountQueuingStrategy';

get [SymbolToStringTag]() { return this[kType]; }

/**
* @param {{
* highWaterMark : number
Expand Down Expand Up @@ -166,6 +171,7 @@ class CountQueuingStrategy {
ObjectDefineProperties(CountQueuingStrategy.prototype, {
highWaterMark: kEnumerableProperty,
size: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(CountQueuingStrategy.name),
});

module.exports = {
Expand Down
26 changes: 14 additions & 12 deletions lib/internal/webstreams/readablestream.js
Expand Up @@ -141,6 +141,14 @@ const kError = Symbol('kError');
const kPull = Symbol('kPull');
const kRelease = Symbol('kRelease');

const getNonWritablePropertyDescriptor = (value) => {
return {
__proto__: null,
configurable: true,
value,
};
};

/**
* @typedef {import('../abort_controller').AbortSignal} AbortSignal
* @typedef {import('./queuingstrategies').QueuingStrategy} QueuingStrategy
Expand Down Expand Up @@ -206,8 +214,6 @@ const kRelease = Symbol('kRelease');
class ReadableStream {
[kType] = 'ReadableStream';

get [SymbolToStringTag]() { return this[kType]; }

/**
* @param {UnderlyingSource} [source]
* @param {QueuingStrategy} [strategy]
Expand Down Expand Up @@ -604,6 +610,7 @@ ObjectDefineProperties(ReadableStream.prototype, {
pipeThrough: kEnumerableProperty,
pipeTo: kEnumerableProperty,
tee: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(ReadableStream.name),
});

function TransferredReadableStream() {
Expand All @@ -629,8 +636,6 @@ TransferredReadableStream.prototype[kDeserialize] = () => {};
class ReadableStreamBYOBRequest {
[kType] = 'ReadableStreamBYOBRequest';

get [SymbolToStringTag]() { return this[kType]; }

constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
Expand Down Expand Up @@ -710,6 +715,7 @@ ObjectDefineProperties(ReadableStreamBYOBRequest.prototype, {
view: kEnumerableProperty,
respond: kEnumerableProperty,
respondWithNewView: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(ReadableStreamBYOBRequest.name),
});

function createReadableStreamBYOBRequest(controller, view) {
Expand Down Expand Up @@ -769,8 +775,6 @@ class ReadIntoRequest {
class ReadableStreamDefaultReader {
[kType] = 'ReadableStreamDefaultReader';

get [SymbolToStringTag]() { return this[kType]; }

/**
* @param {ReadableStream} stream
*/
Expand Down Expand Up @@ -854,13 +858,12 @@ ObjectDefineProperties(ReadableStreamDefaultReader.prototype, {
read: kEnumerableProperty,
releaseLock: kEnumerableProperty,
cancel: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(ReadableStreamDefaultReader.name),
});

class ReadableStreamBYOBReader {
[kType] = 'ReadableStreamBYOBReader';

get [SymbolToStringTag]() { return this[kType]; }

/**
* @param {ReadableStream} stream
*/
Expand Down Expand Up @@ -971,13 +974,12 @@ ObjectDefineProperties(ReadableStreamBYOBReader.prototype, {
read: kEnumerableProperty,
releaseLock: kEnumerableProperty,
cancel: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(ReadableStreamBYOBReader.name),
});

class ReadableStreamDefaultController {
[kType] = 'ReadableStreamDefaultController';

get [SymbolToStringTag]() { return this[kType]; }

constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
Expand Down Expand Up @@ -1032,6 +1034,7 @@ ObjectDefineProperties(ReadableStreamDefaultController.prototype, {
close: kEnumerableProperty,
enqueue: kEnumerableProperty,
error: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(ReadableStreamDefaultController.name),
});

function createReadableStreamDefaultController() {
Expand All @@ -1048,8 +1051,6 @@ function createReadableStreamDefaultController() {
class ReadableByteStreamController {
[kType] = 'ReadableByteStreamController';

get [SymbolToStringTag]() { return this[kType]; }

constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
Expand Down Expand Up @@ -1168,6 +1169,7 @@ ObjectDefineProperties(ReadableByteStreamController.prototype, {
close: kEnumerableProperty,
enqueue: kEnumerableProperty,
error: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(ReadableByteStreamController.name),
});

function createReadableByteStreamController() {
Expand Down
14 changes: 10 additions & 4 deletions lib/internal/webstreams/transformstream.js
Expand Up @@ -64,6 +64,14 @@ const {

const assert = require('internal/assert');

const getNonWritablePropertyDescriptor = (value) => {
return {
__proto__: null,
configurable: true,
value,
};
};

/**
* @typedef {import('./queuingstrategies').QueuingStrategy
* } QueuingStrategy
Expand Down Expand Up @@ -102,8 +110,6 @@ const assert = require('internal/assert');
class TransformStream {
[kType] = 'TransformStream';

get [SymbolToStringTag]() { return this[kType]; }

/**
* @param {Transformer} [transformer]
* @param {QueuingStrategy} [writableStrategy]
Expand Down Expand Up @@ -236,6 +242,7 @@ class TransformStream {
ObjectDefineProperties(TransformStream.prototype, {
readable: kEnumerableProperty,
writable: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(TransformStream.name),
});

function TransferredTransformStream() {
Expand All @@ -261,8 +268,6 @@ TransferredTransformStream.prototype[kDeserialize] = () => {};
class TransformStreamDefaultController {
[kType] = 'TransformStreamDefaultController';

get [SymbolToStringTag]() { return this[kType]; }

constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
Expand Down Expand Up @@ -322,6 +327,7 @@ ObjectDefineProperties(TransformStreamDefaultController.prototype, {
enqueue: kEnumerableProperty,
error: kEnumerableProperty,
terminate: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(TransformStreamDefaultController.name),
});

function createTransformStreamDefaultController() {
Expand Down
17 changes: 11 additions & 6 deletions lib/internal/webstreams/writablestream.js
Expand Up @@ -77,6 +77,14 @@ const kAbort = Symbol('kAbort');
const kCloseSentinel = Symbol('kCloseSentinel');
const kError = Symbol('kError');

const getNonWritablePropertyDescriptor = (value) => {
return {
__proto__: null,
configurable: true,
value,
};
};

/**
* @typedef {import('../abort_controller').AbortSignal} AbortSignal
* @typedef {import('./queuingstrategies').QueuingStrategy
Expand Down Expand Up @@ -121,8 +129,6 @@ const kError = Symbol('kError');
class WritableStream {
[kType] = 'WritableStream';

get [SymbolToStringTag]() { return this[kType]; }

/**
* @param {UnderlyingSink} [sink]
* @param {QueuingStrategy} [strategy]
Expand Down Expand Up @@ -295,6 +301,7 @@ ObjectDefineProperties(WritableStream.prototype, {
abort: kEnumerableProperty,
close: kEnumerableProperty,
getWriter: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(WritableStream.name),
});

function TransferredWritableStream() {
Expand Down Expand Up @@ -348,8 +355,6 @@ TransferredWritableStream.prototype[kDeserialize] = () => {};
class WritableStreamDefaultWriter {
[kType] = 'WritableStreamDefaultWriter';

get [SymbolToStringTag]() { return this[kType]; }

/**
* @param {WritableStream} stream
*/
Expand Down Expand Up @@ -487,13 +492,12 @@ ObjectDefineProperties(WritableStreamDefaultWriter.prototype, {
close: kEnumerableProperty,
releaseLock: kEnumerableProperty,
write: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(WritableStreamDefaultWriter.name),
});

class WritableStreamDefaultController {
[kType] = 'WritableStreamDefaultController';

get [SymbolToStringTag]() { return this[kType]; }

constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
Expand Down Expand Up @@ -538,6 +542,7 @@ class WritableStreamDefaultController {
ObjectDefineProperties(WritableStreamDefaultController.prototype, {
signal: kEnumerableProperty,
error: kEnumerableProperty,
[SymbolToStringTag]: getNonWritablePropertyDescriptor(WritableStreamDefaultController.name),
});

function createWritableStreamDefaultController() {
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-webstream-string-tag.js
@@ -0,0 +1,18 @@
'use strict';

require('../common');

const assert = require('assert');

const classesToBeTested = [ WritableStream, WritableStreamDefaultWriter, WritableStreamDefaultController,
ReadableStream, ReadableStreamBYOBRequest, ReadableStreamDefaultReader,
ReadableStreamBYOBReader, ReadableStreamDefaultController, ReadableByteStreamController,
ByteLengthQueuingStrategy, CountQueuingStrategy, TransformStream,
TransformStreamDefaultController];


classesToBeTested.forEach((cls) => {
assert.strictEqual(cls.prototype[Symbol.toStringTag], cls.name);
assert.deepStrictEqual(Object.getOwnPropertyDescriptor(cls.prototype, Symbol.toStringTag),
{ configurable: true, enumerable: false, value: cls.name, writable: false });
});