@@ -8,7 +8,7 @@ const originalPromiseReject = Promise.reject;
8
8
9
9
const promiseSideTable = new WeakMap ( ) ;
10
10
11
- // https://heycam.github.io/webidl /#a-new-promise
11
+ // https://webidl.spec.whatwg.org /#a-new-promise
12
12
function newPromise ( ) {
13
13
// The stateIsPending tracking only works if we never resolve the promises with other promises.
14
14
// In this spec, that happens to be true for the promises in question; they are always resolved with undefined.
@@ -22,7 +22,7 @@ function newPromise() {
22
22
return promise ;
23
23
}
24
24
25
- // https://heycam.github.io/webidl /#resolve
25
+ // https://webidl.spec.whatwg.org /#resolve
26
26
function resolvePromise ( p , value ) {
27
27
// We intend to only resolve or reject promises that are still pending.
28
28
// When this is not the case, it usually means there's a bug in the specification that we want to fix.
@@ -33,22 +33,22 @@ function resolvePromise(p, value) {
33
33
promiseSideTable . get ( p ) . stateIsPending = false ;
34
34
}
35
35
36
- // https://heycam.github.io/webidl /#reject
36
+ // https://webidl.spec.whatwg.org /#reject
37
37
function rejectPromise ( p , reason ) {
38
38
assert ( stateIsPending ( p ) === true ) ;
39
39
promiseSideTable . get ( p ) . reject ( reason ) ;
40
40
promiseSideTable . get ( p ) . stateIsPending = false ;
41
41
}
42
42
43
- // https://heycam.github.io/webidl /#a-promise-resolved-with
43
+ // https://webidl.spec.whatwg.org /#a-promise-resolved-with
44
44
function promiseResolvedWith ( value ) {
45
45
// Cannot use original Promise.resolve since that will return value itself sometimes, unlike Web IDL.
46
46
const promise = new originalPromise ( resolve => resolve ( value ) ) ;
47
47
promiseSideTable . set ( promise , { stateIsPending : false } ) ;
48
48
return promise ;
49
49
}
50
50
51
- // https://heycam.github.io/webidl /#a-promise-rejected-with
51
+ // https://webidl.spec.whatwg.org /#a-promise-rejected-with
52
52
function promiseRejectedWith ( reason ) {
53
53
const promise = originalPromiseReject . call ( originalPromise , reason ) ;
54
54
promiseSideTable . set ( promise , { stateIsPending : false } ) ;
@@ -61,7 +61,7 @@ function PerformPromiseThen(promise, onFulfilled, onRejected) {
61
61
return originalPromiseThen . call ( promise , onFulfilled , onRejected ) ;
62
62
}
63
63
64
- // https://heycam.github.io/webidl /#dfn-perform-steps-once-promise-is-settled
64
+ // https://webidl.spec.whatwg.org /#dfn-perform-steps-once-promise-is-settled
65
65
function uponPromise ( promise , onFulfilled , onRejected ) {
66
66
PerformPromiseThen (
67
67
PerformPromiseThen ( promise , onFulfilled , onRejected ) ,
@@ -104,8 +104,9 @@ Object.assign(exports, {
104
104
stateIsPending
105
105
} ) ;
106
106
107
- // https://heycam.github.io/webidl /#wait-for-all
107
+ // https://webidl.spec.whatwg.org /#wait-for-all
108
108
function waitForAll ( promises , successSteps , failureSteps ) {
109
+ let fulfilledCount = 0 ;
109
110
let rejected = false ;
110
111
const rejectionHandler = arg => {
111
112
if ( rejected === false ) {
@@ -114,7 +115,6 @@ function waitForAll(promises, successSteps, failureSteps) {
114
115
}
115
116
} ;
116
117
let index = 0 ;
117
- let fulfilledCount = 0 ;
118
118
const total = promises . length ;
119
119
const result = new Array ( total ) ;
120
120
if ( total === 0 ) {
@@ -135,35 +135,15 @@ function waitForAll(promises, successSteps, failureSteps) {
135
135
}
136
136
}
137
137
138
- // https://heycam.github.io/webidl/#waiting-for-all-promise
139
- exports . waitForAllPromise = ( promises , successSteps , failureSteps = undefined ) => {
140
- let resolveP ;
141
- let rejectP ;
142
- const promise = new Promise ( ( resolve , reject ) => {
143
- resolveP = resolve ;
144
- rejectP = reject ;
145
- } ) ;
146
- if ( failureSteps === undefined ) {
147
- failureSteps = arg => {
148
- throw arg ;
149
- } ;
150
- }
151
- const successStepsWrapper = results => {
152
- try {
153
- const stepsResult = successSteps ( results ) ;
154
- resolveP ( stepsResult ) ;
155
- } catch ( e ) {
156
- rejectP ( e ) ;
157
- }
138
+ // https://webidl.spec.whatwg.org/#waiting-for-all-promise
139
+ exports . waitForAllPromise = promises => {
140
+ const promise = newPromise ( ) ;
141
+ const successSteps = results => {
142
+ resolvePromise ( promise , results ) ;
158
143
} ;
159
- const failureStepsWrapper = reason => {
160
- try {
161
- const stepsResult = failureSteps ( reason ) ;
162
- resolveP ( stepsResult ) ;
163
- } catch ( e ) {
164
- rejectP ( e ) ;
165
- }
144
+ const failureSteps = reason => {
145
+ rejectPromise ( promise , reason ) ;
166
146
} ;
167
- waitForAll ( promises , successStepsWrapper , failureStepsWrapper ) ;
147
+ waitForAll ( promises , successSteps , failureSteps ) ;
168
148
return promise ;
169
149
} ;
0 commit comments