Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! make resource compulsory
  • Loading branch information
debadree25 committed Feb 4, 2023
commit 2e41a14fbf2fb63bd9c580374b2f539ca9aca0c0
4 changes: 3 additions & 1 deletion lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const {
const {
validateUint32,
validateAbortSignal: abortSignalValidator,
validateObject,
} = require('internal/validators');

const {
Expand Down Expand Up @@ -366,8 +367,9 @@ function transferableAbortController() {
* @param {any} resource
* @returns {Promise<void>}
*/
async function aborted(signal, resource = null) {
async function aborted(signal, resource) {
abortSignalValidator(signal, 'signal');
Comment thread
aduh95 marked this conversation as resolved.
Outdated
validateObject(resource, 'resource', { nullable: false, allowFunction: true, allowArray: true });
Comment thread
debadree25 marked this conversation as resolved.
if (signal.aborted)
return PromiseResolve();
const abortPromise = createDeferredPromise();
Expand Down
19 changes: 9 additions & 10 deletions test/parallel/test-aborted-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ const { aborted } = require('util');
const assert = require('assert');
const { getEventListeners } = require('events');

{
// Test aborted works
const ac = new AbortController();
aborted(ac.signal).then(common.mustCall());
ac.abort();
assert.strictEqual(ac.signal.aborted, true);
assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 0);
}

{
// Test aborted works when provided a resource
const ac = new AbortController();
Expand All @@ -39,7 +30,15 @@ const { getEventListeners } = require('events');
{
// Fails with error if not provided abort signal
const sig = new EventTarget();
assert.rejects(aborted(sig), {
assert.rejects(aborted(sig, {}), {
name: 'TypeError',
});
}

{
// Fails if not provided a resource
const ac = new AbortController();
assert.rejects(aborted(ac.signal, null), {
name: 'TypeError',
});
}
Comment thread
debadree25 marked this conversation as resolved.