From 679973866d614506ab309516da75e6909423e61e Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Sun, 16 May 2021 16:44:43 +0200 Subject: [PATCH] timers: reject with AbortError on cancellation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/36317 Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Robert Nagy --- lib/internal/timers/promises.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/internal/timers/promises.js b/lib/internal/timers/promises.js index e58756edac0e46..55d554bb838e95 100644 --- a/lib/internal/timers/promises.js +++ b/lib/internal/timers/promises.js @@ -14,24 +14,16 @@ const { } = require('internal/timers'); const { - hideStackFrames, + AbortError, codes: { ERR_INVALID_ARG_TYPE } } = require('internal/errors'); const { validateAbortSignal } = require('internal/validators'); -let DOMException; - -const lazyDOMException = hideStackFrames((message, name) => { - if (DOMException === undefined) - DOMException = internalBinding('messaging').DOMException; - return new DOMException(message, name); -}); - function cancelListenerHandler(clear, reject) { if (!this._destroyed) { clear(this); - reject(lazyDOMException('The operation was aborted', 'AbortError')); + reject(new AbortError()); } } @@ -61,8 +53,7 @@ function setTimeout(after, value, options = {}) { // to 12.x, then this can be converted to use optional chaining to // simplify the check. if (signal && signal.aborted) { - return PromiseReject( - lazyDOMException('The operation was aborted', 'AbortError')); + return PromiseReject(new AbortError()); } let oncancel; const ret = new Promise((resolve, reject) => { @@ -107,8 +98,7 @@ function setImmediate(value, options = {}) { // to 12.x, then this can be converted to use optional chaining to // simplify the check. if (signal && signal.aborted) { - return PromiseReject( - lazyDOMException('The operation was aborted', 'AbortError')); + return PromiseReject(new AbortError()); } let oncancel; const ret = new Promise((resolve, reject) => {