Skip to content

Commit e65f320

Browse files
committed
stream: move webstream abort hooks onto prototypes
1 parent bb0c045 commit e65f320

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

lib/internal/webstreams/readablestream.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ class ReadableStream {
254254
this[kState] = createReadableStreamState();
255255

256256
this[kIsClosedPromise] = PromiseWithResolvers();
257-
this[kControllerAbortFunction] = () => {};
258257

259258
// The spec requires handling of the strategy first
260259
// here. Specifically, if getting the size and
@@ -284,6 +283,20 @@ class ReadableStream {
284283
}
285284
}
286285

286+
[kControllerAbortFunction](error) {
287+
if (!isReadableStream(this))
288+
throw new ERR_INVALID_THIS('ReadableStream');
289+
290+
const controller = this[kState].controller;
291+
if (isReadableStreamDefaultController(controller)) {
292+
readableStreamDefaultControllerError(controller, error);
293+
return;
294+
}
295+
296+
assert(isReadableByteStreamController(controller));
297+
readableByteStreamControllerError(controller, error);
298+
}
299+
287300
get [kIsDisturbed]() {
288301
return this[kState].disturbed;
289302
}
@@ -2540,8 +2553,6 @@ function setupReadableStreamDefaultController(
25402553
stream,
25412554
};
25422555
stream[kState].controller = controller;
2543-
stream[kControllerAbortFunction] =
2544-
(error) => readableStreamDefaultControllerError(controller, error);
25452556

25462557
const startResult = startAlgorithm();
25472558

@@ -3365,8 +3376,6 @@ function setupReadableByteStreamController(
33653376
pendingPullIntos: [],
33663377
};
33673378
stream[kState].controller = controller;
3368-
stream[kControllerAbortFunction] =
3369-
(error) => readableByteStreamControllerError(controller, error);
33703379

33713380
const startResult = startAlgorithm();
33723381

lib/internal/webstreams/writablestream.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ class WritableStream {
173173
this[kState] = createWritableStreamState();
174174

175175
this[kIsClosedPromise] = PromiseWithResolvers();
176-
this[kControllerAbortFunction] = () => {};
177176

178177
const size = extractSizeAlgorithm(strategy?.size);
179178
const highWaterMark = extractHighWaterMark(strategy?.highWaterMark, 1);
@@ -185,6 +184,12 @@ class WritableStream {
185184
size);
186185
}
187186

187+
[kControllerAbortFunction](reason) {
188+
if (!isWritableStream(this))
189+
throw new ERR_INVALID_THIS('WritableStream');
190+
setPromiseHandled(writableStreamAbort(this, reason));
191+
}
192+
188193
get [kIsErrored]() {
189194
return this[kState].state === 'errored';
190195
}
@@ -1322,9 +1327,6 @@ function setupWritableStreamDefaultController(
13221327
writeAlgorithm,
13231328
};
13241329
stream[kState].controller = controller;
1325-
stream[kControllerAbortFunction] = (reason) => {
1326-
setPromiseHandled(writableStreamAbort(stream, reason));
1327-
};
13281330

13291331
writableStreamUpdateBackpressure(
13301332
stream,

test/parallel/test-webstreams-abort-controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function assertWritableStreamEventuallyAborted(ws, writer, {
171171
{
172172
/** @member {import('internal/webstreams/readablestream').ReadableStreamDefaultController} */
173173
let controller;
174-
let pullPromiseWithResolvers = Promise.withResolvers();
174+
const pullPromiseWithResolvers = Promise.withResolvers();
175175
const rs = new ReadableStream({
176176
start(c) { controller = c; },
177177
pull() { return pullPromiseWithResolvers.promise; },

0 commit comments

Comments
 (0)