feat(ext/web): WritableStreamDefaultController.signal (#12654)

This commit is contained in:
Leo Kettmeir 2021-11-08 12:54:24 +01:00 committed by GitHub
parent 8e010b6844
commit c91da1222b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 35 deletions

View file

@ -9,7 +9,8 @@
((window) => { ((window) => {
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
// TODO(lucacasonato): get AbortSignal from __bootstrap. const { add, remove, signalAbort, newSignal } =
window.__bootstrap.abortSignal;
const { const {
ArrayBuffer, ArrayBuffer,
ArrayBufferIsView, ArrayBufferIsView,
@ -286,6 +287,7 @@
const _readRequests = Symbol("[[readRequests]]"); const _readRequests = Symbol("[[readRequests]]");
const _readIntoRequests = Symbol("[[readIntoRequests]]"); const _readIntoRequests = Symbol("[[readIntoRequests]]");
const _readyPromise = Symbol("[[readyPromise]]"); const _readyPromise = Symbol("[[readyPromise]]");
const _signal = Symbol("[[signal]]");
const _started = Symbol("[[started]]"); const _started = Symbol("[[started]]");
const _state = Symbol("[[state]]"); const _state = Symbol("[[state]]");
const _storedError = Symbol("[[storedError]]"); const _storedError = Symbol("[[storedError]]");
@ -1902,8 +1904,7 @@
abortAlgorithm(); abortAlgorithm();
return promise.promise; return promise.promise;
} }
// TODO(lucacasonato): use the internal API to listen for abort. signal[add](abortAlgorithm);
signal.addEventListener("abort", abortAlgorithm);
} }
function pipeLoop() { function pipeLoop() {
@ -2107,8 +2108,7 @@
readableStreamReaderGenericRelease(reader); readableStreamReaderGenericRelease(reader);
if (signal !== undefined) { if (signal !== undefined) {
// TODO(lucacasonato): use the internal API to remove the listener. signal[remove](abortAlgorithm);
signal.removeEventListener("abort", abortAlgorithm);
} }
if (isError) { if (isError) {
promise.reject(error); promise.reject(error);
@ -2985,6 +2985,7 @@
controller[_stream] = stream; controller[_stream] = stream;
stream[_controller] = controller; stream[_controller] = controller;
resetQueue(controller); resetQueue(controller);
controller[_signal] = newSignal();
controller[_started] = false; controller[_started] = false;
controller[_strategySizeAlgorithm] = sizeAlgorithm; controller[_strategySizeAlgorithm] = sizeAlgorithm;
controller[_strategyHWM] = highWaterMark; controller[_strategyHWM] = highWaterMark;
@ -3342,6 +3343,10 @@
if (state === "closed" || state === "errored") { if (state === "closed" || state === "errored") {
return resolvePromiseWith(undefined); return resolvePromiseWith(undefined);
} }
stream[_controller][_signal][signalAbort]();
if (state === "closed" || state === "errored") {
return resolvePromiseWith(undefined);
}
if (stream[_pendingAbortRequest] !== undefined) { if (stream[_pendingAbortRequest] !== undefined) {
return stream[_pendingAbortRequest].deferred.promise; return stream[_pendingAbortRequest].deferred.promise;
} }
@ -5421,6 +5426,13 @@
[_stream]; [_stream];
/** @type {(chunk: W, controller: this) => Promise<void>} */ /** @type {(chunk: W, controller: this) => Promise<void>} */
[_writeAlgorithm]; [_writeAlgorithm];
/** @type {AbortSignal} */
[_signal];
get signal() {
webidl.assertBranded(this, WritableStreamDefaultController);
return this[_signal];
}
constructor() { constructor() {
webidl.illegalConstructor(); webidl.illegalConstructor();

View file

@ -635,6 +635,7 @@ declare var WritableStream: {
* sink is given a corresponding WritableStreamDefaultController instance to * sink is given a corresponding WritableStreamDefaultController instance to
* manipulate. */ * manipulate. */
interface WritableStreamDefaultController { interface WritableStreamDefaultController {
signal: AbortSignal;
error(error?: any): void; error(error?: any): void;
} }

View file

@ -6056,18 +6056,8 @@
"window-worker-timeOrigin.window.html": false "window-worker-timeOrigin.window.html": false
}, },
"streams": { "streams": {
"idlharness.any.html": [ "idlharness.any.html": true,
"WritableStreamDefaultController interface: attribute abortReason", "idlharness.any.worker.html": true,
"WritableStreamDefaultController interface: attribute signal",
"WritableStreamDefaultController interface: self.writableStreamDefaultController must inherit property \"abortReason\" with the proper type",
"WritableStreamDefaultController interface: self.writableStreamDefaultController must inherit property \"signal\" with the proper type"
],
"idlharness.any.worker.html": [
"WritableStreamDefaultController interface: attribute abortReason",
"WritableStreamDefaultController interface: attribute signal",
"WritableStreamDefaultController interface: self.writableStreamDefaultController must inherit property \"abortReason\" with the proper type",
"WritableStreamDefaultController interface: self.writableStreamDefaultController must inherit property \"signal\" with the proper type"
],
"piping": { "piping": {
"abort.any.html": true, "abort.any.html": true,
"abort.any.worker.html": true, "abort.any.worker.html": true,
@ -6169,24 +6159,8 @@
"terminate.any.worker.html": true "terminate.any.worker.html": true
}, },
"writable-streams": { "writable-streams": {
"aborting.any.html": [ "aborting.any.html": true,
"WritableStreamDefaultController.signal", "aborting.any.worker.html": true,
"the abort signal is signalled synchronously - write",
"the abort signal is signalled synchronously - close",
"the abort signal is not signalled on error",
"the abort signal is not signalled on write failure",
"the abort signal is not signalled on close failure",
"recursive abort() call"
],
"aborting.any.worker.html": [
"WritableStreamDefaultController.signal",
"the abort signal is signalled synchronously - write",
"the abort signal is signalled synchronously - close",
"the abort signal is not signalled on error",
"the abort signal is not signalled on write failure",
"the abort signal is not signalled on close failure",
"recursive abort() call"
],
"bad-strategies.any.html": true, "bad-strategies.any.html": true,
"bad-strategies.any.worker.html": true, "bad-strategies.any.worker.html": true,
"bad-underlying-sinks.any.html": true, "bad-underlying-sinks.any.html": true,