Skip to content

Commit

Permalink
[Fetch] Object.prototype shouldn't interfere with fetch streams
Browse files Browse the repository at this point in the history
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 whatwg/fetch#781 for background.
  • Loading branch information
ricea committed Aug 8, 2018
1 parent 273e3f0 commit 3158c3b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions fetch/api/basic/stream-safe-creation.any.js
Original file line number Diff line number Diff line change
@@ -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}'`);
}
}

0 comments on commit 3158c3b

Please sign in to comment.