| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 function PromiseIdResolveHandler(x) { return x; } | 25 function PromiseIdResolveHandler(x) { return x; } |
| 26 function PromiseIdRejectHandler(r) { %_ReThrow(r); } | 26 function PromiseIdRejectHandler(r) { %_ReThrow(r); } |
| 27 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true); | 27 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true); |
| 28 | 28 |
| 29 // ------------------------------------------------------------------- | 29 // ------------------------------------------------------------------- |
| 30 // Define exported functions. | 30 // Define exported functions. |
| 31 | 31 |
| 32 // For bootstrapper. | 32 // For bootstrapper. |
| 33 | 33 |
| 34 // This is used by utils and v8-extras. | |
| 35 function PromiseCreate(parent) { | |
| 36 return %promise_internal_constructor(parent); | |
| 37 } | |
| 38 | |
| 39 // Export to bindings | 34 // Export to bindings |
| 40 function DoRejectPromise(promise, reason) { | 35 function DoRejectPromise(promise, reason) { |
| 41 %PromiseReject(promise, reason, true); | 36 %PromiseReject(promise, reason, true); |
| 42 } | 37 } |
| 43 | 38 |
| 44 // Combinators. | 39 // Combinators. |
| 45 | 40 |
| 46 // ES#sec-promise.all | 41 // ES#sec-promise.all |
| 47 // Promise.all ( iterable ) | 42 // Promise.all ( iterable ) |
| 48 function PromiseAll(iterable) { | 43 function PromiseAll(iterable) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 142 |
| 148 // ------------------------------------------------------------------- | 143 // ------------------------------------------------------------------- |
| 149 // Install exported functions. | 144 // Install exported functions. |
| 150 | 145 |
| 151 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ | 146 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ |
| 152 "all", PromiseAll, | 147 "all", PromiseAll, |
| 153 "race", PromiseRace, | 148 "race", PromiseRace, |
| 154 ]); | 149 ]); |
| 155 | 150 |
| 156 %InstallToContext([ | 151 %InstallToContext([ |
| 157 "promise_create", PromiseCreate, | |
| 158 "promise_reject", DoRejectPromise, | 152 "promise_reject", DoRejectPromise, |
| 159 "promise_id_resolve_handler", PromiseIdResolveHandler, | 153 "promise_id_resolve_handler", PromiseIdResolveHandler, |
| 160 "promise_id_reject_handler", PromiseIdRejectHandler | 154 "promise_id_reject_handler", PromiseIdRejectHandler |
| 161 ]); | 155 ]); |
| 162 | 156 |
| 163 // This allows extras to create promises quickly without building extra | 157 // This allows extras to create promises quickly without building extra |
| 164 // resolve/reject closures, and allows them to later resolve and reject any | 158 // resolve/reject closures, and allows them to later resolve and reject any |
| 165 // promise without having to hold on to those closures forever. | 159 // promise without having to hold on to those closures forever. |
| 166 utils.InstallFunctions(extrasUtils, 0, [ | 160 utils.InstallFunctions(extrasUtils, 0, [ |
| 167 "createPromise", PromiseCreate, | |
| 168 "rejectPromise", DoRejectPromise, | 161 "rejectPromise", DoRejectPromise, |
| 169 "markPromiseAsHandled", MarkPromiseAsHandled | 162 "markPromiseAsHandled", MarkPromiseAsHandled |
| 170 ]); | 163 ]); |
| 171 | 164 |
| 172 }) | 165 }) |
| OLD | NEW |