Skip to content

Commit

Permalink
webstreams: fix web streams have no Symbol.toStringTag
Browse files Browse the repository at this point in the history
fix web streams have no Symbol.toStringTag
nodejs#45114
  • Loading branch information
MrJithil committed Oct 22, 2022
1 parent 94020ac commit 958a787
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 13 deletions.
10 changes: 8 additions & 2 deletions lib/internal/webstreams/queuingstrategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const countSizeFunction = function size() { return 1; };
* @type {QueuingStrategy}
*/
class ByteLengthQueuingStrategy {
[kType] = 'ByteLengthQueuingStrategy';

get [kType]() {
return 'ByteLengthQueuingStrategy';
}

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

Expand Down Expand Up @@ -113,7 +116,10 @@ ObjectDefineProperties(ByteLengthQueuingStrategy.prototype, {
* @type {QueuingStrategy}
*/
class CountQueuingStrategy {
[kType] = 'CountQueuingStrategy';

get [kType]() {
return 'CountQueuingStrategy';
}

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

Expand Down
31 changes: 25 additions & 6 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ const kPull = Symbol('kPull');
*/

class ReadableStream {
[kType] = 'ReadableStream';

get [kType]() {
return 'ReadableStream';
}

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

Expand Down Expand Up @@ -621,7 +624,10 @@ function TransferredReadableStream() {
TransferredReadableStream.prototype[kDeserialize] = () => {};

class ReadableStreamBYOBRequest {
[kType] = 'ReadableStreamBYOBRequest';

get [kType]() {
return 'ReadableStreamBYOBRequest';
}

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

Expand Down Expand Up @@ -753,7 +759,10 @@ class ReadIntoRequest {
}

class ReadableStreamDefaultReader {
[kType] = 'ReadableStreamDefaultReader';

get [kType]() {
return 'ReadableStreamDefaultReader';
}

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

Expand Down Expand Up @@ -847,7 +856,11 @@ ObjectDefineProperties(ReadableStreamDefaultReader.prototype, {
});

class ReadableStreamBYOBReader {
[kType] = 'ReadableStreamBYOBReader';

get [kType]() {
return 'ReadableStreamBYOBReader';
}


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

Expand Down Expand Up @@ -964,7 +977,10 @@ ObjectDefineProperties(ReadableStreamBYOBReader.prototype, {
});

class ReadableStreamDefaultController {
[kType] = 'ReadableStreamDefaultController';

get [kType]() {
return 'ReadableStreamDefaultController';
}

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

Expand Down Expand Up @@ -1034,7 +1050,10 @@ function createReadableStreamDefaultController() {
}

class ReadableByteStreamController {
[kType] = 'ReadableByteStreamController';

get [kType]() {
return 'ReadableByteStreamController';
}

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

Expand Down
10 changes: 8 additions & 2 deletions lib/internal/webstreams/transformstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ const assert = require('internal/assert');
*/

class TransformStream {
[kType] = 'TransformStream';

get [kType]() {
return 'TransformStream';
}

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

Expand Down Expand Up @@ -260,7 +263,10 @@ function TransferredTransformStream() {
TransferredTransformStream.prototype[kDeserialize] = () => {};

class TransformStreamDefaultController {
[kType] = 'TransformStreamDefaultController';

get [kType]() {
return 'TransformStreamDefaultController';
}

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

Expand Down
15 changes: 12 additions & 3 deletions lib/internal/webstreams/writablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ const kError = Symbol('kError');
*/

class WritableStream {
[kType] = 'WritableStream';

get [kType]() {
return 'WritableStream';
}

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

Expand Down Expand Up @@ -346,7 +349,10 @@ function TransferredWritableStream() {
TransferredWritableStream.prototype[kDeserialize] = () => {};

class WritableStreamDefaultWriter {
[kType] = 'WritableStreamDefaultWriter';

get [kType]() {
return 'WritableStreamDefaultWriter';
}

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

Expand Down Expand Up @@ -490,7 +496,10 @@ ObjectDefineProperties(WritableStreamDefaultWriter.prototype, {
});

class WritableStreamDefaultController {
[kType] = 'WritableStreamDefaultController';

get [kType]() {
return 'WritableStreamDefaultController';
}

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

Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-webstream-string-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

require('../common');

const assert = require('assert');
const webstreams = require('stream/web');

assert.strictEqual(WritableStream.prototype[Symbol.toStringTag], 'WritableStream');
assert.strictEqual(WritableStreamDefaultWriter.prototype[Symbol.toStringTag], 'WritableStreamDefaultWriter');
assert.strictEqual(WritableStreamDefaultController.prototype[Symbol.toStringTag], 'WritableStreamDefaultController');

assert.strictEqual(ReadableStream.prototype[Symbol.toStringTag], 'ReadableStream');
assert.strictEqual(ReadableStreamBYOBRequest.prototype[Symbol.toStringTag], 'ReadableStreamBYOBRequest');
assert.strictEqual(ReadableStreamDefaultReader.prototype[Symbol.toStringTag], 'ReadableStreamDefaultReader');
assert.strictEqual(ReadableStreamBYOBReader.prototype[Symbol.toStringTag], 'ReadableStreamBYOBReader');
assert.strictEqual(ReadableStreamDefaultController.prototype[Symbol.toStringTag], 'ReadableStreamDefaultController');
assert.strictEqual(ReadableByteStreamController.prototype[Symbol.toStringTag], 'ReadableByteStreamController');

assert.strictEqual(ByteLengthQueuingStrategy.prototype[Symbol.toStringTag], 'ByteLengthQueuingStrategy');
assert.strictEqual(CountQueuingStrategy.prototype[Symbol.toStringTag], 'CountQueuingStrategy');

assert.strictEqual(TransformStream.prototype[Symbol.toStringTag], 'TransformStream');
assert.strictEqual(TransformStreamDefaultController.prototype[Symbol.toStringTag], 'TransformStreamDefaultController');

0 comments on commit 958a787

Please sign in to comment.