Skip to content
Closed
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
test: check if AbortController and AbortSignal validate the receiver
  • Loading branch information
MattiasBuelens committed Mar 15, 2021
commit bc871642b1292a64a300f967e693b2b25305f81e
60 changes: 60 additions & 0 deletions test/parallel/test-abortcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,63 @@ const { ok, strictEqual, throws } = require('assert');
const signal = AbortSignal.abort();
ok(signal.aborted);
}

{
// Test that AbortController properties and methods
// validate the receiver object
const acSignalGet = Object.getOwnPropertyDescriptor(
AbortController.prototype,
'signal'
).get;
const acAbort = AbortController.prototype.abort;

const goodController = new AbortController();
ok(acSignalGet.call(goodController));
acAbort.call(goodController);

const badAbortControllers = [
null,
0,
NaN,
true,
'AbortController',
Object.create(AbortController.prototype)
];
for (const badController of badAbortControllers) {
throws(
() => acSignalGet.call(badController),
{ code: 'ERR_INVALID_THIS', name: 'TypeError' }
);
throws(
() => acAbort.call(badController),
{ code: 'ERR_INVALID_THIS', name: 'TypeError' }
);
}
}

{
// Test that AbortSignal properties
// validate the receiver object
const signalAbortedGet = Object.getOwnPropertyDescriptor(
AbortSignal.prototype,
'aborted'
).get;

const goodSignal = new AbortController().signal;
strictEqual(signalAbortedGet.call(goodSignal), false);

const badAbortSignals = [
null,
0,
NaN,
true,
'AbortSignal',
Object.create(AbortSignal.prototype)
];
for (const badSignal of badAbortSignals) {
throws(
() => signalAbortedGet.call(badSignal),
{ code: 'ERR_INVALID_THIS', name: 'TypeError' }
);
}
}