|
| 1 | +// META: global=worker |
| 2 | + |
| 3 | +// These tests verify that stream creation is not affected by changes to |
| 4 | +// Object.prototype. |
| 5 | + |
| 6 | +const creationCases = { |
| 7 | + fetch: async () => fetch(location.href), |
| 8 | + request: () => new Request(location.href, {method: 'POST', body: 'hi'}), |
| 9 | + response: () => new Response('bye'), |
| 10 | + consumeEmptyResponse: () => new Response().text(), |
| 11 | + consumeNonEmptyResponse: () => new Response(new Uint8Array([64])).text(), |
| 12 | + consumeEmptyRequest: () => new Request(location.href).text(), |
| 13 | + consumeNonEmptyRequest: () => new Request(location.href, |
| 14 | + {method: 'POST', body: 'yes'}).arrayBuffer(), |
| 15 | +}; |
| 16 | + |
| 17 | +for (creationCase of Object.keys(creationCases)) { |
| 18 | + for (accessorName of ['start', 'type', 'size', 'highWaterMark']) { |
| 19 | + promise_test(async t => { |
| 20 | + Object.defineProperty(Object.prototype, accessorName, { |
| 21 | + get() { throw Error(`Object.prototype.${accessorName} was accessed`); }, |
| 22 | + configurable: true |
| 23 | + }); |
| 24 | + t.add_cleanup(() => { |
| 25 | + delete Object.prototype[accessorName]; |
| 26 | + return Promise.resolve(); |
| 27 | + }); |
| 28 | + await creationCases[creationCase](); |
| 29 | + }, `throwing Object.prototype.${accessorName} accessor should not affect ` + |
| 30 | + `stream creation by '${creationCase}'`); |
| 31 | + |
| 32 | + promise_test(async t => { |
| 33 | + // -1 is a convenient value which is invalid, and should cause the |
| 34 | + // constructor to throw, for all four fields. |
| 35 | + Object.prototype[accessorName] = -1; |
| 36 | + t.add_cleanup(() => { |
| 37 | + delete Object.prototype[accessorName]; |
| 38 | + return Promise.resolve(); |
| 39 | + }); |
| 40 | + await creationCases[creationCase](); |
| 41 | + }, `Object.prototype.${accessorName} accessor returning invalid value ` + |
| 42 | + `should not affect stream creation by '${creationCase}'`); |
| 43 | + } |
| 44 | + |
| 45 | + promise_test(async t => { |
| 46 | + Object.prototype.start = controller => controller.error(new Error('start')); |
| 47 | + t.add_cleanup(() => { |
| 48 | + delete Object.prototype.start; |
| 49 | + return Promise.resolve(); |
| 50 | + }); |
| 51 | + await creationCases[creationCase](); |
| 52 | + }, `Object.prototype.start function which errors the stream should not ` + |
| 53 | + `affect stream creation by '${creationCase}'`); |
| 54 | +} |
0 commit comments