From 3158c3b9a243c0b81ecc5fadd1b82e5a907cc408 Mon Sep 17 00:00:00 2001 From: Adam Rice Date: Wed, 8 Aug 2018 14:57:24 +0900 Subject: [PATCH] [Fetch] Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See https://github.com/whatwg/fetch/pull/781 for background. --- fetch/api/basic/stream-safe-creation.any.js | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 fetch/api/basic/stream-safe-creation.any.js diff --git a/fetch/api/basic/stream-safe-creation.any.js b/fetch/api/basic/stream-safe-creation.any.js new file mode 100644 index 00000000000000..50beca12bab301 --- /dev/null +++ b/fetch/api/basic/stream-safe-creation.any.js @@ -0,0 +1,33 @@ +// These tests verify that stream creation is not affected by changes to +// Object.prototype. + +const creationCases = { + fetch: async () => fetch(location.href), + request: () => new Request(location.href), + response: () => new Response('hi'), + consumeEmpty: () => new Response().text(), + consumeNonEmpty: () => new Response(new Uint8Array([64])).text() +}; + +for (creationCase of Object.keys(creationCases)) { + promise_test(async t => { + Object.prototype.start = () => { + throw Error('Object.prototype.start was called'); + }; + t.add_cleanup(() => delete Object.prototype.start); + await creationCases[creationCase]; + }, `throwing Object.prototype.start() should not affect stream creation by ` + + `'${creationCase}'`); + + for (accessorName of ['type', 'size', 'highWaterMark']) { + promise_test(async t => { + Object.defineProperty(Object.prototype, accessorName, { + get() { throw Error(`Object.prototype.${accessorName} was accessed`); }, + configurable: true + }); + t.add_cleanup(() => delete Object.prototype[accessorName]); + await creationCases[creationCase]; + }, `throwing Object.prototype.${accessorName} accessor should not affect ` + + `stream creation by '${creationCase}'`); + } +}