From b6fd39377ee68dda0a5d82ed7f5dba9c61583a43 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 15 Jun 2021 17:48:25 +0200 Subject: [PATCH] fix: pass some more WHATWG streams WPT (#10970) --- extensions/web/06_streams.js | 29 ++++++++++++++++++----------- tools/wpt/expectation.json | 26 ++++++++++---------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/extensions/web/06_streams.js b/extensions/web/06_streams.js index b3c55fa85e..b24ab21a05 100644 --- a/extensions/web/06_streams.js +++ b/extensions/web/06_streams.js @@ -366,10 +366,10 @@ * @param {number} defaultHWM */ function extractHighWaterMark(strategy, defaultHWM) { - if (!("highWaterMark" in strategy)) { + if (strategy.highWaterMark === undefined) { return defaultHWM; } - const highWaterMark = Number(strategy.highWaterMark); + const highWaterMark = strategy.highWaterMark; if (Number.isNaN(highWaterMark) || highWaterMark < 0) { throw RangeError( `Expected highWaterMark to be a positive number or Infinity, got "${highWaterMark}".`, @@ -384,12 +384,17 @@ * @return {(chunk: T) => number} */ function extractSizeAlgorithm(strategy) { - const { size } = strategy; - - if (!size) { + if (strategy.size === undefined) { return () => 1; } - return (chunk) => size(chunk); + return (chunk) => + webidl.invokeCallbackFunction( + strategy.size, + [chunk], + undefined, + webidl.converters["unrestricted double"], + { prefix: "Failed to call `sizeAlgorithm`" }, + ); } /** @@ -1031,6 +1036,10 @@ if (reader === undefined) { return; } + /** @type {Deferred} */ + const closedPromise = reader[_closedPromise]; + closedPromise.reject(e); + setPromiseIsHandledToTrue(closedPromise.promise); if (isReadableStreamDefaultReader(reader)) { /** @type {Array>} */ const readRequests = reader[_readRequests]; @@ -1040,10 +1049,6 @@ reader[_readRequests] = []; } // 3.5.6.8 Otherwise, support BYOB Reader - /** @type {Deferred} */ - const closedPromise = reader[_closedPromise]; - closedPromise.reject(e); - setPromiseIsHandledToTrue(closedPromise.promise); } /** @@ -3158,7 +3163,9 @@ return Promise.reject(err); } if (isReadableStreamLocked(this)) { - Promise.reject(new TypeError("Cannot cancel a locked ReadableStream.")); + return Promise.reject( + new TypeError("Cannot cancel a locked ReadableStream."), + ); } return readableStreamCancel(this, reason); } diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index 2c1690181d..44b19cd5b7 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -309,6 +309,11 @@ "queuing-strategies.any.html": true, "readable-byte-streams": { "bad-buffers-and-views.any.html": [ + "ReadableStream with byte source: read()ing from a closed stream still transfers the buffer", + "ReadableStream with byte source: read()ing from a stream with queued chunks still transfers the buffer", + "ReadableStream with byte source: reading into an already-detached buffer rejects", + "ReadableStream with byte source: reading into a zero-length buffer rejects", + "ReadableStream with byte source: reading into a zero-length view on a non-zero-length buffer rejects", "ReadableStream with byte source: respond() throws if the BYOB request's buffer has been detached (in the readable state)", "ReadableStream with byte source: respond() throws if the BYOB request's buffer has been detached (in the closed state)", "ReadableStream with byte source: respondWithNewView() throws if the supplied view's buffer has been detached (in the readable state)", @@ -321,12 +326,7 @@ "ReadableStream with byte source: respondWithNewView() throws if the supplied view is non-zero-length (in the closed state)", "ReadableStream with byte source: respondWithNewView() throws if the supplied view's buffer has a different length (in the closed state)", "ReadableStream with byte source: enqueue() throws if the BYOB request's buffer has been detached (in the readable state)", - "ReadableStream with byte source: enqueue() throws if the BYOB request's buffer has been detached (in the closed state)", - "ReadableStream with byte source: read()ing from a closed stream still transfers the buffer", - "ReadableStream with byte source: read()ing from a stream with queued chunks still transfers the buffer", - "ReadableStream with byte source: reading into an already-detached buffer rejects", - "ReadableStream with byte source: reading into a zero-length buffer rejects", - "ReadableStream with byte source: reading into a zero-length view on a non-zero-length buffer rejects" + "ReadableStream with byte source: enqueue() throws if the BYOB request's buffer has been detached (in the closed state)" ], "construct-byob-request.any.html": false, "general.any.html": [ @@ -402,21 +402,17 @@ ], "bad-strategies.any.html": true, "bad-underlying-sources.any.html": true, - "cancel.any.html": false, + "cancel.any.html": true, "constructor.any.html": true, "count-queuing-strategy-integration.any.html": true, "default-reader.any.html": true, "floating-point-total-queue-size.any.html": true, "garbage-collection.any.html": true, - "general.any.html": [ - "ReadableStream: if pull rejects, it should error the stream" - ], + "general.any.html": true, "patched-global.any.html": true, "reentrant-strategies.any.html": true, "tee.any.html": false, - "templated.any.html": [ - "ReadableStream (empty) reader: canceling via the stream should fail" - ] + "templated.any.html": true }, "transform-streams": { "backpressure.any.html": true, @@ -424,9 +420,7 @@ "flush.any.html": true, "general.any.html": true, "lipfuzz.any.html": true, - "patched-global.any.html": [ - "TransformStream constructor should not call setters for highWaterMark or size" - ], + "patched-global.any.html": true, "properties.any.html": true, "reentrant-strategies.any.html": true, "strategies.any.html": true,