Skip to content

Commit 4b04bb8

Browse files
addaleaxtargos
authored andcommitted
timers: use AbortController with correct name/message
On the web, `AbortError` is the error name, not the error message. Change the code to match that. PR-URL: #34763 Backport-PR-URL: #38386 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 9660a78 commit 4b04bb8

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

‎lib/internal/timers/promises.js‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ const{
1818

1919
letDOMException;
2020

21-
constlazyDOMException=hideStackFrames((message)=>{
21+
constlazyDOMException=hideStackFrames((message,name)=>{
2222
if(DOMException===undefined)
2323
DOMException=internalBinding('messaging').DOMException;
24-
returnnewDOMException(message);
24+
returnnewDOMException(message,name);
2525
});
2626

2727
functionsetTimeout(after,value,options={}){
@@ -54,8 +54,10 @@ function setTimeout(after, value, options ={}){
5454
// TODO(@jasnell): If a decision is made that this cannot be backported
5555
// to 12.x, then this can be converted to use optional chaining to
5656
// simplify the check.
57-
if(signal&&signal.aborted)
58-
returnPromiseReject(lazyDOMException('AbortError'));
57+
if(signal&&signal.aborted){
58+
returnPromiseReject(
59+
lazyDOMException('The operation was aborted','AbortError'));
60+
}
5961
returnnewPromise((resolve,reject)=>{
6062
consttimeout=newTimeout(resolve,after,args,false,true);
6163
if(!ref)timeout.unref();
@@ -65,7 +67,7 @@ function setTimeout(after, value, options ={}){
6567
if(!timeout._destroyed){
6668
// eslint-disable-next-line no-undef
6769
clearTimeout(timeout);
68-
reject(lazyDOMException('AbortError'));
70+
reject(lazyDOMException('The operation was aborted','AbortError'));
6971
}
7072
},{once: true});
7173
}
@@ -101,8 +103,10 @@ function setImmediate(value, options ={}){
101103
// TODO(@jasnell): If a decision is made that this cannot be backported
102104
// to 12.x, then this can be converted to use optional chaining to
103105
// simplify the check.
104-
if(signal&&signal.aborted)
105-
returnPromiseReject(lazyDOMException('AbortError'));
106+
if(signal&&signal.aborted){
107+
returnPromiseReject(
108+
lazyDOMException('The operation was aborted','AbortError'));
109+
}
106110
returnnewPromise((resolve,reject)=>{
107111
constimmediate=newImmediate(resolve,[value]);
108112
if(!ref)immediate.unref();
@@ -111,7 +115,7 @@ function setImmediate(value, options ={}){
111115
if(!immediate._destroyed){
112116
// eslint-disable-next-line no-undef
113117
clearImmediate(immediate);
114-
reject(lazyDOMException('AbortError'));
118+
reject(lazyDOMException('The operation was aborted','AbortError'));
115119
}
116120
},{once: true});
117121
}

0 commit comments

Comments
(0)