diff options
author | WPT Sync Bot <josh+wptsync@joshmatthews.net> | 2018-11-23 10:56:36 -0500 |
---|---|---|
committer | Tom Servo <servo@server.blueoceanstudios.us> | 2018-11-23 15:48:00 -0500 |
commit | 642f3cb54137c609c6c4180422a5e6064302af0b (patch) | |
tree | 29941cd675fd475b6688e864dc9664edc4b38594 /tests/wpt/web-platform-tests/streams/readable-byte-streams/construct-byob-request.any.js | |
parent | 1bac32edc014e290342e981f65541f4115375fdc (diff) | |
download | servo-642f3cb54137c609c6c4180422a5e6064302af0b.tar.gz servo-642f3cb54137c609c6c4180422a5e6064302af0b.zip |
Update web-platform-tests to revision a8fb1792cbfab3ed59401775da76fb6c15d9f2e2
Diffstat (limited to 'tests/wpt/web-platform-tests/streams/readable-byte-streams/construct-byob-request.any.js')
-rw-r--r-- | tests/wpt/web-platform-tests/streams/readable-byte-streams/construct-byob-request.any.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/wpt/web-platform-tests/streams/readable-byte-streams/construct-byob-request.any.js b/tests/wpt/web-platform-tests/streams/readable-byte-streams/construct-byob-request.any.js new file mode 100644 index 00000000000..427166f67cf --- /dev/null +++ b/tests/wpt/web-platform-tests/streams/readable-byte-streams/construct-byob-request.any.js @@ -0,0 +1,79 @@ +// META: global=worker +// META: script=../resources/rs-utils.js +'use strict'; + +// Prior to whatwg/stream#870 it was possible to construct a ReadableStreamBYOBRequest directly. This made it possible +// to construct requests that were out-of-sync with the state of the ReadableStream. They could then be used to call +// internal operations, resulting in asserts or bad behaviour. This file contains regression tests for the change. + +function getRealByteStreamController() { + let controller; + new ReadableStream({ + start(c) { + controller = c; + }, + type: 'bytes' + }); + return controller; +} + +const ReadableByteStreamController = getRealByteStreamController().constructor; + +// Create an object pretending to have prototype |prototype|, of type |type|. |type| is one of "undefined", "null", +// "fake", or "real". "real" will call the realObjectCreator function to get a real instance of the object. +function createDummyObject(prototype, type, realObjectCreator) { + switch (type) { + case 'undefined': + return undefined; + + case 'null': + return null; + + case 'fake': + return Object.create(prototype); + + case 'real': + return realObjectCreator(); + } + + throw new Error('not reached'); +} + +const dummyTypes = ['undefined', 'null', 'fake', 'real']; + +function runTests(ReadableStreamBYOBRequest) { + for (const controllerType of dummyTypes) { + const controller = createDummyObject(ReadableByteStreamController.prototype, controllerType, + getRealByteStreamController); + for (const viewType of dummyTypes) { + const view = createDummyObject(Uint8Array.prototype, viewType, () => new Uint8Array(16)); + test(() => { + assert_throws(new TypeError(), () => new ReadableStreamBYOBRequest(controller, view), + 'constructor should throw'); + }, `ReadableStreamBYOBRequest constructor should throw when passed a ${controllerType} ` + + `ReadableByteStreamController and a ${viewType} view`); + } + } +} + +function getConstructorAndRunTests() { + let ReadableStreamBYOBRequest; + const rs = new ReadableStream({ + pull(controller) { + const byobRequest = controller.byobRequest; + ReadableStreamBYOBRequest = byobRequest.constructor; + byobRequest.respond(4); + }, + type: 'bytes' + }); + rs.getReader({ mode: 'byob' }).read(new Uint8Array(8)).then(() => { + runTests(ReadableStreamBYOBRequest); + done(); + }); +} + +// We can only get at the ReadableStreamBYOBRequest constructor asynchronously, so we need to make the test harness wait +// for us to explicitly tell it all our tests have run. +setup({ explicit_done: true }); + +getConstructorAndRunTests(); |