| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // equivalent to throwing an exception directly. | 135 // equivalent to throwing an exception directly. |
| 136 %PromiseRejectEventFromStack(promise, r); | 136 %PromiseRejectEventFromStack(promise, r); |
| 137 return promise; | 137 return promise; |
| 138 } else { | 138 } else { |
| 139 var promiseCapability = NewPromiseCapability(this, true); | 139 var promiseCapability = NewPromiseCapability(this, true); |
| 140 %_Call(promiseCapability.reject, UNDEFINED, r); | 140 %_Call(promiseCapability.reject, UNDEFINED, r); |
| 141 return promiseCapability.promise; | 141 return promiseCapability.promise; |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 // ES#sec-promise.prototype.catch | |
| 146 // Promise.prototype.catch ( onRejected ) | |
| 147 function PromiseCatch(onReject) { | |
| 148 return this.then(UNDEFINED, onReject); | |
| 149 } | |
| 150 | |
| 151 // Combinators. | 145 // Combinators. |
| 152 | 146 |
| 153 // ES#sec-promise.resolve | 147 // ES#sec-promise.resolve |
| 154 // Promise.resolve ( x ) | 148 // Promise.resolve ( x ) |
| 155 function PromiseResolve(x) { | 149 function PromiseResolve(x) { |
| 156 if (!IS_RECEIVER(this)) { | 150 if (!IS_RECEIVER(this)) { |
| 157 throw %make_type_error(kCalledOnNonObject, PromiseResolve); | 151 throw %make_type_error(kCalledOnNonObject, PromiseResolve); |
| 158 } | 152 } |
| 159 if (%is_promise(x) && x.constructor === this) return x; | 153 if (%is_promise(x) && x.constructor === this) return x; |
| 160 | 154 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // ------------------------------------------------------------------- | 332 // ------------------------------------------------------------------- |
| 339 // Install exported functions. | 333 // Install exported functions. |
| 340 | 334 |
| 341 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ | 335 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ |
| 342 "reject", PromiseReject, | 336 "reject", PromiseReject, |
| 343 "all", PromiseAll, | 337 "all", PromiseAll, |
| 344 "race", PromiseRace, | 338 "race", PromiseRace, |
| 345 "resolve", PromiseResolve | 339 "resolve", PromiseResolve |
| 346 ]); | 340 ]); |
| 347 | 341 |
| 348 %SetCode(GlobalPromise.prototype.catch, PromiseCatch); | |
| 349 | |
| 350 %InstallToContext([ | 342 %InstallToContext([ |
| 351 "promise_catch", GlobalPromise.prototype.catch, | |
| 352 "promise_create", PromiseCreate, | 343 "promise_create", PromiseCreate, |
| 353 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, | 344 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, |
| 354 "promise_reject", DoRejectPromise, | 345 "promise_reject", DoRejectPromise, |
| 355 // TODO(gsathya): Remove this once we update the promise builtin. | 346 // TODO(gsathya): Remove this once we update the promise builtin. |
| 356 "promise_internal_reject", RejectPromise, | 347 "promise_internal_reject", RejectPromise, |
| 357 "promise_debug_get_info", PromiseDebugGetInfo, | 348 "promise_debug_get_info", PromiseDebugGetInfo, |
| 358 "new_promise_capability", NewPromiseCapability, | 349 "new_promise_capability", NewPromiseCapability, |
| 359 "internal_promise_capability", CreateInternalPromiseCapability, | 350 "internal_promise_capability", CreateInternalPromiseCapability, |
| 360 "promise_id_resolve_handler", PromiseIdResolveHandler, | 351 "promise_id_resolve_handler", PromiseIdResolveHandler, |
| 361 "promise_id_reject_handler", PromiseIdRejectHandler | 352 "promise_id_reject_handler", PromiseIdRejectHandler |
| 362 ]); | 353 ]); |
| 363 | 354 |
| 364 // This allows extras to create promises quickly without building extra | 355 // This allows extras to create promises quickly without building extra |
| 365 // resolve/reject closures, and allows them to later resolve and reject any | 356 // resolve/reject closures, and allows them to later resolve and reject any |
| 366 // promise without having to hold on to those closures forever. | 357 // promise without having to hold on to those closures forever. |
| 367 utils.InstallFunctions(extrasUtils, 0, [ | 358 utils.InstallFunctions(extrasUtils, 0, [ |
| 368 "createPromise", PromiseCreate, | 359 "createPromise", PromiseCreate, |
| 369 "rejectPromise", DoRejectPromise, | 360 "rejectPromise", DoRejectPromise, |
| 370 "markPromiseAsHandled", MarkPromiseAsHandled | 361 "markPromiseAsHandled", MarkPromiseAsHandled |
| 371 ]); | 362 ]); |
| 372 | 363 |
| 373 utils.Export(function(to) { | 364 utils.Export(function(to) { |
| 374 to.PromiseCreate = PromiseCreate; | 365 to.PromiseCreate = PromiseCreate; |
| 375 | 366 |
| 376 to.CreateInternalPromiseCapability = CreateInternalPromiseCapability; | 367 to.CreateInternalPromiseCapability = CreateInternalPromiseCapability; |
| 377 to.RejectPromise = RejectPromise; | 368 to.RejectPromise = RejectPromise; |
| 378 }); | 369 }); |
| 379 | 370 |
| 380 }) | 371 }) |
| OLD | NEW |