Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: refactor to use validateAbortSignal #46520

Merged
merged 1 commit into from Feb 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/internal/abort_controller.js
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
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