diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index 3522836d80439d..c66f2a8367f82d 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -406,7 +406,6 @@ ObjectDefineProperty(AbortController.prototype, SymbolToStringTag, { }); module.exports = { - kAborted, AbortController, AbortSignal, ClonedAbortSignal, diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index 709cc95972f9c9..377eb02a348eaf 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -58,14 +58,11 @@ const { } = require('internal/util'); const { + validateAbortSignal, validateBuffer, validateObject, } = require('internal/validators'); -const { - kAborted, -} = require('internal/abort_controller'); - const { MessageChannel, } = require('internal/worker/io'); @@ -381,8 +378,9 @@ class ReadableStream { const preventClose = options?.preventClose; const signal = options?.signal; - if (signal !== undefined && signal?.[kAborted] === undefined) - throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal); + if (signal !== undefined) { + validateAbortSignal(signal, 'options.signal'); + } if (isReadableStreamLocked(this)) throw new ERR_INVALID_STATE.TypeError('The ReadableStream is locked'); @@ -422,8 +420,9 @@ class ReadableStream { const preventClose = options?.preventClose; const signal = options?.signal; - if (signal !== undefined && signal?.[kAborted] === undefined) - throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal); + if (signal !== undefined) { + validateAbortSignal(signal, 'options.signal'); + } if (isReadableStreamLocked(this)) throw new ERR_INVALID_STATE.TypeError('The ReadableStream is locked'); @@ -1269,12 +1268,12 @@ function readableStreamPipeTo( let shuttingDown = false; - if (signal !== undefined && signal?.[kAborted] === undefined) { - return PromiseReject( - new ERR_INVALID_ARG_TYPE( - 'options.signal', - 'AbortSignal', - signal)); + if (signal !== undefined) { + try { + validateAbortSignal(signal, 'options.signal'); + } catch (error) { + return PromiseReject(error); + } } const promise = createDeferredPromise();