@@ -8,7 +8,7 @@ const originalPromiseReject = Promise.reject;
88
99const promiseSideTable = new WeakMap ( ) ;
1010
11- // https://heycam.github.io/webidl /#a-new-promise
11+ // https://webidl.spec.whatwg.org /#a-new-promise
1212function newPromise ( ) {
1313 // The stateIsPending tracking only works if we never resolve the promises with other promises.
1414 // 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() {
2222 return promise ;
2323}
2424
25- // https://heycam.github.io/webidl /#resolve
25+ // https://webidl.spec.whatwg.org /#resolve
2626function resolvePromise ( p , value ) {
2727 // We intend to only resolve or reject promises that are still pending.
2828 // 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) {
3333 promiseSideTable . get ( p ) . stateIsPending = false ;
3434}
3535
36- // https://heycam.github.io/webidl /#reject
36+ // https://webidl.spec.whatwg.org /#reject
3737function rejectPromise ( p , reason ) {
3838 assert ( stateIsPending ( p ) === true ) ;
3939 promiseSideTable . get ( p ) . reject ( reason ) ;
4040 promiseSideTable . get ( p ) . stateIsPending = false ;
4141}
4242
43- // https://heycam.github.io/webidl /#a-promise-resolved-with
43+ // https://webidl.spec.whatwg.org /#a-promise-resolved-with
4444function promiseResolvedWith ( value ) {
4545 // Cannot use original Promise.resolve since that will return value itself sometimes, unlike Web IDL.
4646 const promise = new originalPromise ( resolve => resolve ( value ) ) ;
4747 promiseSideTable . set ( promise , { stateIsPending : false } ) ;
4848 return promise ;
4949}
5050
51- // https://heycam.github.io/webidl /#a-promise-rejected-with
51+ // https://webidl.spec.whatwg.org /#a-promise-rejected-with
5252function promiseRejectedWith ( reason ) {
5353 const promise = originalPromiseReject . call ( originalPromise , reason ) ;
5454 promiseSideTable . set ( promise , { stateIsPending : false } ) ;
@@ -61,7 +61,7 @@ function PerformPromiseThen(promise, onFulfilled, onRejected) {
6161 return originalPromiseThen . call ( promise , onFulfilled , onRejected ) ;
6262}
6363
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
6565function uponPromise ( promise , onFulfilled , onRejected ) {
6666 PerformPromiseThen (
6767 PerformPromiseThen ( promise , onFulfilled , onRejected ) ,
@@ -104,8 +104,9 @@ Object.assign(exports, {
104104 stateIsPending
105105} ) ;
106106
107- // https://heycam.github.io/webidl /#wait-for-all
107+ // https://webidl.spec.whatwg.org /#wait-for-all
108108function waitForAll ( promises , successSteps , failureSteps ) {
109+ let fulfilledCount = 0 ;
109110 let rejected = false ;
110111 const rejectionHandler = arg => {
111112 if ( rejected === false ) {
@@ -114,7 +115,6 @@ function waitForAll(promises, successSteps, failureSteps) {
114115 }
115116 } ;
116117 let index = 0 ;
117- let fulfilledCount = 0 ;
118118 const total = promises . length ;
119119 const result = new Array ( total ) ;
120120 if ( total === 0 ) {
@@ -135,35 +135,15 @@ function waitForAll(promises, successSteps, failureSteps) {
135135 }
136136}
137137
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 ) ;
158143 } ;
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 ) ;
166146 } ;
167- waitForAll ( promises , successStepsWrapper , failureStepsWrapper ) ;
147+ waitForAll ( promises , successSteps , failureSteps ) ;
168148 return promise ;
169149} ;
0 commit comments