Skip to content

Commit 17b4e9b

Browse files
aduh95danielleadams
authored andcommitted
stream: refactor to use validateAbortSignal
PR-URL: #46520 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3d0602c commit 17b4e9b

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lib/internal/abort_controller.js

-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ ObjectDefineProperty(AbortController.prototype, SymbolToStringTag, {
406406
});
407407

408408
module.exports = {
409-
kAborted,
410409
AbortController,
411410
AbortSignal,
412411
ClonedAbortSignal,

lib/internal/webstreams/readablestream.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,11 @@ const {
5858
} = require('internal/util');
5959

6060
const {
61+
validateAbortSignal,
6162
validateBuffer,
6263
validateObject,
6364
} = require('internal/validators');
6465

65-
const {
66-
kAborted,
67-
} = require('internal/abort_controller');
68-
6966
const {
7067
MessageChannel,
7168
} = require('internal/worker/io');
@@ -381,8 +378,9 @@ class ReadableStream {
381378
const preventClose = options?.preventClose;
382379
const signal = options?.signal;
383380

384-
if (signal !== undefined && signal?.[kAborted] === undefined)
385-
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
381+
if (signal !== undefined) {
382+
validateAbortSignal(signal, 'options.signal');
383+
}
386384

387385
if (isReadableStreamLocked(this))
388386
throw new ERR_INVALID_STATE.TypeError('The ReadableStream is locked');
@@ -422,8 +420,9 @@ class ReadableStream {
422420
const preventClose = options?.preventClose;
423421
const signal = options?.signal;
424422

425-
if (signal !== undefined && signal?.[kAborted] === undefined)
426-
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
423+
if (signal !== undefined) {
424+
validateAbortSignal(signal, 'options.signal');
425+
}
427426

428427
if (isReadableStreamLocked(this))
429428
throw new ERR_INVALID_STATE.TypeError('The ReadableStream is locked');
@@ -1269,12 +1268,12 @@ function readableStreamPipeTo(
12691268

12701269
let shuttingDown = false;
12711270

1272-
if (signal !== undefined && signal?.[kAborted] === undefined) {
1273-
return PromiseReject(
1274-
new ERR_INVALID_ARG_TYPE(
1275-
'options.signal',
1276-
'AbortSignal',
1277-
signal));
1271+
if (signal !== undefined) {
1272+
try {
1273+
validateAbortSignal(signal, 'options.signal');
1274+
} catch (error) {
1275+
return PromiseReject(error);
1276+
}
12781277
}
12791278

12801279
const promise = createDeferredPromise();

0 commit comments

Comments
 (0)