Skip to content

Commit

Permalink
stream: refactor to use validateAbortSignal
Browse files Browse the repository at this point in the history
PR-URL: #46520
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 authored and MylesBorins committed Feb 18, 2023
1 parent d8c527f commit f91260b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,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

0 comments on commit f91260b

Please sign in to comment.