From b2a828bd72a020d4c725a8a894df8fc65b2024c9 Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Sat, 28 Jan 2023 17:03:49 +0530 Subject: [PATCH 1/5] stream: dont access Object.prototype.type during TransformStream init Fixes: https://github.com/nodejs/node/issues/46355 --- lib/internal/webstreams/transformstream.js | 2 ++ test/parallel/test-whatwg-transformstream.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/internal/webstreams/transformstream.js b/lib/internal/webstreams/transformstream.js index 6e119bde63bb2f..991033ea8423a3 100644 --- a/lib/internal/webstreams/transformstream.js +++ b/lib/internal/webstreams/transformstream.js @@ -368,6 +368,7 @@ function initializeTransformStream( close() { return transformStreamDefaultSinkCloseAlgorithm(stream); }, + __proto__: null }, { highWaterMark: writableHighWaterMark, size: writableSizeAlgorithm, @@ -382,6 +383,7 @@ function initializeTransformStream( transformStreamErrorWritableAndUnblockWrite(stream, reason); return PromiseResolve(); }, + __proto__: null, }, { highWaterMark: readableHighWaterMark, size: readableSizeAlgorithm, diff --git a/test/parallel/test-whatwg-transformstream.js b/test/parallel/test-whatwg-transformstream.js index 0cbc76cc4ce8c0..b8779152c7e68b 100644 --- a/test/parallel/test-whatwg-transformstream.js +++ b/test/parallel/test-whatwg-transformstream.js @@ -186,3 +186,18 @@ class Source { inspect(controller, { depth: 0 }), /TransformStreamDefaultController \[/); } + +{ + Object.defineProperty(Object.prototype, 'type', { + get: common.mustNotCall() + }); + + new TransformStream({ + transform(chunk, controller) { + controller.enqueue(chunk); + }, + flush(controller) { + controller.terminate(); + } + }); +} From 0b296367ed14fe9662a076210c26baf643a0294b Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Mon, 30 Jan 2023 22:56:44 +0530 Subject: [PATCH 2/5] fixup! Co-authored-by: Antoine du Hamel --- test/parallel/test-whatwg-transformstream.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-whatwg-transformstream.js b/test/parallel/test-whatwg-transformstream.js index b8779152c7e68b..c099cb2c3d0544 100644 --- a/test/parallel/test-whatwg-transformstream.js +++ b/test/parallel/test-whatwg-transformstream.js @@ -189,7 +189,8 @@ class Source { { Object.defineProperty(Object.prototype, 'type', { - get: common.mustNotCall() + get: common.mustNotCall('get %Object.prototype%.type'), + set: common.mustNotCall('set %Object.prototype%.type'), }); new TransformStream({ From 034f49faa04c1b56ea95a9ab9cacf49b34d9e42a Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Mon, 30 Jan 2023 22:56:55 +0530 Subject: [PATCH 3/5] fixup! Co-authored-by: Antoine du Hamel --- test/parallel/test-whatwg-transformstream.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-whatwg-transformstream.js b/test/parallel/test-whatwg-transformstream.js index c099cb2c3d0544..ab01016bb55e6c 100644 --- a/test/parallel/test-whatwg-transformstream.js +++ b/test/parallel/test-whatwg-transformstream.js @@ -201,4 +201,6 @@ class Source { controller.terminate(); } }); + + delete Object.prototype.type; } From efb65e07005499c8b4b9904f72759873ed61ee16 Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Tue, 31 Jan 2023 00:37:16 +0530 Subject: [PATCH 4/5] fixup --- lib/internal/webstreams/transformstream.js | 4 ++-- test/parallel/test-whatwg-transformstream.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/webstreams/transformstream.js b/lib/internal/webstreams/transformstream.js index 991033ea8423a3..411099552941b0 100644 --- a/lib/internal/webstreams/transformstream.js +++ b/lib/internal/webstreams/transformstream.js @@ -358,6 +358,7 @@ function initializeTransformStream( readableSizeAlgorithm) { const writable = new WritableStream({ + __proto__: null, start() { return startPromise.promise; }, write(chunk) { return transformStreamDefaultSinkWriteAlgorithm(stream, chunk); @@ -368,13 +369,13 @@ function initializeTransformStream( close() { return transformStreamDefaultSinkCloseAlgorithm(stream); }, - __proto__: null }, { highWaterMark: writableHighWaterMark, size: writableSizeAlgorithm, }); const readable = new ReadableStream({ + __proto__: null, start() { return startPromise.promise; }, pull() { return transformStreamDefaultSourcePullAlgorithm(stream); @@ -383,7 +384,6 @@ function initializeTransformStream( transformStreamErrorWritableAndUnblockWrite(stream, reason); return PromiseResolve(); }, - __proto__: null, }, { highWaterMark: readableHighWaterMark, size: readableSizeAlgorithm, diff --git a/test/parallel/test-whatwg-transformstream.js b/test/parallel/test-whatwg-transformstream.js index ab01016bb55e6c..ba46669c0f3bf4 100644 --- a/test/parallel/test-whatwg-transformstream.js +++ b/test/parallel/test-whatwg-transformstream.js @@ -201,6 +201,6 @@ class Source { controller.terminate(); } }); - - delete Object.prototype.type; + + Reflect.deleteProperty(Object.prototype, 'type'); } From a8aa8a2bee23e556e0287a79a4dc66be8905f84e Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Tue, 31 Jan 2023 11:46:14 +0530 Subject: [PATCH 5/5] fixup! use configurable --- test/parallel/test-whatwg-transformstream.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-whatwg-transformstream.js b/test/parallel/test-whatwg-transformstream.js index ba46669c0f3bf4..3276b4dd54a4ec 100644 --- a/test/parallel/test-whatwg-transformstream.js +++ b/test/parallel/test-whatwg-transformstream.js @@ -191,6 +191,7 @@ class Source { Object.defineProperty(Object.prototype, 'type', { get: common.mustNotCall('get %Object.prototype%.type'), set: common.mustNotCall('set %Object.prototype%.type'), + configurable: true, }); new TransformStream({ @@ -202,5 +203,5 @@ class Source { } }); - Reflect.deleteProperty(Object.prototype, 'type'); + delete Object.prototype.type; }