summaryrefslogtreecommitdiff
path: root/test/parallel/test-abortcontroller.js
diff options
context:
space:
mode:
authorMattias Buelens <mattias@buelens.com>2021-03-11 23:25:45 +0100
committerJames M Snell <jasnell@gmail.com>2021-03-19 12:30:56 -0700
commitfeaeb76d12bc1e9d80c25df0e3c12ddd731147e1 (patch)
tree8518e2480062d4eb66a7de9b8a117749be0f9a54 /test/parallel/test-abortcontroller.js
parenteaf0f0f1b57adbd1d1acac4b8aba54d29ceab36f (diff)
downloadnode-new-feaeb76d12bc1e9d80c25df0e3c12ddd731147e1.tar.gz
lib: add brand checks to AbortController and AbortSignal
PR-URL: https://github.com/nodejs/node/pull/37720 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'test/parallel/test-abortcontroller.js')
-rw-r--r--test/parallel/test-abortcontroller.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/parallel/test-abortcontroller.js b/test/parallel/test-abortcontroller.js
index 2b36da332e..d26ec8641a 100644
--- a/test/parallel/test-abortcontroller.js
+++ b/test/parallel/test-abortcontroller.js
@@ -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
+ 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,
+ undefined,
+ 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
+ const signalAbortedGet = Object.getOwnPropertyDescriptor(
+ AbortSignal.prototype,
+ 'aborted'
+ ).get;
+
+ const goodSignal = new AbortController().signal;
+ strictEqual(signalAbortedGet.call(goodSignal), false);
+
+ const badAbortSignals = [
+ null,
+ undefined,
+ 0,
+ NaN,
+ true,
+ 'AbortSignal',
+ Object.create(AbortSignal.prototype)
+ ];
+ for (const badSignal of badAbortSignals) {
+ throws(
+ () => signalAbortedGet.call(badSignal),
+ { code: 'ERR_INVALID_THIS', name: 'TypeError' }
+ );
+ }
+}