Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
stream: refactor to use validateAbortSignal
  • Loading branch information
aduh95 committed Feb 6, 2023
commit 5fe2e9f05e3decc486ba868be04524547cdec64a
1 change: 0 additions & 1 deletion lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ ObjectDefineProperty(AbortController.prototype, SymbolToStringTag, {
});

module.exports = {
kAborted,
AbortController,
AbortSignal,
ClonedAbortSignal,
Expand Down
27 changes: 13 additions & 14 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down