@@ -58,14 +58,11 @@ const {
5858} = require('internal/util');
5959
6060const {
61+ validateAbortSignal,
6162 validateBuffer,
6263 validateObject,
6364} = require('internal/validators');
6465
65- const {
66- kAborted,
67- } = require('internal/abort_controller');
68-
6966const {
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