diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index e4f5f14f1e4cbe..b9465333dfd0f0 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -292,34 +292,21 @@ function abortSignal(signal, reason) { signal.dispatchEvent(event); } -// TODO(joyeecheung): use private fields and we'll get invalid access -// validation from V8 instead of throwing ERR_INVALID_THIS ourselves. -const kSignal = Symbol('signal'); - -function validateAbortController(obj) { - if (obj?.[kSignal] === undefined) - throw new ERR_INVALID_THIS('AbortController'); -} - class AbortController { - constructor() { - this[kSignal] = createAbortSignal(); - } + #signal = createAbortSignal(); /** * @type {AbortSignal} */ get signal() { - validateAbortController(this); - return this[kSignal]; + return this.#signal; } /** * @param {any} reason */ abort(reason = new DOMException('This operation was aborted', 'AbortError')) { - validateAbortController(this); - abortSignal(this[kSignal], reason); + abortSignal(this.#signal, reason); } [customInspectSymbol](depth, options) { diff --git a/test/parallel/test-abortcontroller.js b/test/parallel/test-abortcontroller.js index ed7af146e35967..c32edcd72c5c6c 100644 --- a/test/parallel/test-abortcontroller.js +++ b/test/parallel/test-abortcontroller.js @@ -108,11 +108,11 @@ const { setTimeout: sleep } = require('timers/promises'); for (const badController of badAbortControllers) { throws( () => acSignalGet.call(badController), - { code: 'ERR_INVALID_THIS', name: 'TypeError' } + { name: 'TypeError' } ); throws( () => acAbort.call(badController), - { code: 'ERR_INVALID_THIS', name: 'TypeError' } + { name: 'TypeError' } ); } } @@ -139,7 +139,7 @@ const { setTimeout: sleep } = require('timers/promises'); for (const badSignal of badAbortSignals) { throws( () => signalAbortedGet.call(badSignal), - { code: 'ERR_INVALID_THIS', name: 'TypeError' } + { name: 'TypeError' } ); } }