| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } else { | 267 } else { |
| 268 var promiseCapability = NewPromiseCapability(this); | 268 var promiseCapability = NewPromiseCapability(this); |
| 269 %_Call(promiseCapability.reject, UNDEFINED, r); | 269 %_Call(promiseCapability.reject, UNDEFINED, r); |
| 270 return promiseCapability.promise; | 270 return promiseCapability.promise; |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 | 273 |
| 274 // Multi-unwrapped chaining with thenable coercion. | 274 // Multi-unwrapped chaining with thenable coercion. |
| 275 | 275 |
| 276 function PromiseThen(onResolve, onReject) { | 276 function PromiseThen(onResolve, onReject) { |
| 277 var status = GET_PRIVATE(this, promiseStatusSymbol); |
| 278 if (IS_UNDEFINED(status)) { |
| 279 throw MakeTypeError(kNotAPromise, this); |
| 280 } |
| 281 |
| 277 var constructor = this.constructor; | 282 var constructor = this.constructor; |
| 278 onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler; | 283 onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler; |
| 279 onReject = IS_CALLABLE(onReject) ? onReject : PromiseIdRejectHandler; | 284 onReject = IS_CALLABLE(onReject) ? onReject : PromiseIdRejectHandler; |
| 280 var deferred = NewPromiseCapability(constructor); | 285 var deferred = NewPromiseCapability(constructor); |
| 281 switch (GET_PRIVATE(this, promiseStatusSymbol)) { | 286 switch (status) { |
| 282 case UNDEFINED: | |
| 283 // TODO(littledan): The type check should be called before | |
| 284 // constructing NewPromiseCapability; this is observable when | |
| 285 // erroneously copying this method to other classes. | |
| 286 throw MakeTypeError(kNotAPromise, this); | |
| 287 case 0: // Pending | 287 case 0: // Pending |
| 288 GET_PRIVATE(this, promiseOnResolveSymbol).push(onResolve, deferred); | 288 GET_PRIVATE(this, promiseOnResolveSymbol).push(onResolve, deferred); |
| 289 GET_PRIVATE(this, promiseOnRejectSymbol).push(onReject, deferred); | 289 GET_PRIVATE(this, promiseOnRejectSymbol).push(onReject, deferred); |
| 290 break; | 290 break; |
| 291 case +1: // Resolved | 291 case +1: // Resolved |
| 292 PromiseEnqueue(GET_PRIVATE(this, promiseValueSymbol), | 292 PromiseEnqueue(GET_PRIVATE(this, promiseValueSymbol), |
| 293 [onResolve, deferred], | 293 [onResolve, deferred], |
| 294 +1); | 294 +1); |
| 295 break; | 295 break; |
| 296 case -1: // Rejected | 296 case -1: // Rejected |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( | 455 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( |
| 456 fn => %FunctionRemovePrototype(fn)); | 456 fn => %FunctionRemovePrototype(fn)); |
| 457 | 457 |
| 458 utils.Export(function(to) { | 458 utils.Export(function(to) { |
| 459 to.PromiseChain = PromiseChain; | 459 to.PromiseChain = PromiseChain; |
| 460 to.PromiseDeferred = PromiseDeferred; | 460 to.PromiseDeferred = PromiseDeferred; |
| 461 to.PromiseResolved = PromiseResolved; | 461 to.PromiseResolved = PromiseResolved; |
| 462 }); | 462 }); |
| 463 | 463 |
| 464 }) | 464 }) |
| OLD | NEW |