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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // Core functionality. | 23 // Core functionality. |
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. | |
33 | |
34 // Export to bindings | |
35 function DoRejectPromise(promise, reason) { | |
36 %PromiseReject(promise, reason, true); | |
37 } | |
38 | |
39 // Combinators. | 32 // Combinators. |
40 | 33 |
41 // ES#sec-promise.all | 34 // ES#sec-promise.all |
42 // Promise.all ( iterable ) | 35 // Promise.all ( iterable ) |
43 function PromiseAll(iterable) { | 36 function PromiseAll(iterable) { |
44 if (!IS_RECEIVER(this)) { | 37 if (!IS_RECEIVER(this)) { |
45 throw %make_type_error(kCalledOnNonObject, "Promise.all"); | 38 throw %make_type_error(kCalledOnNonObject, "Promise.all"); |
46 } | 39 } |
47 | 40 |
48 // false debugEvent so that forwarding the rejection through all does not | 41 // false debugEvent so that forwarding the rejection through all does not |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 if (instrumenting && %is_promise(throwawayPromise)) { | 122 if (instrumenting && %is_promise(throwawayPromise)) { |
130 SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise); | 123 SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise); |
131 } | 124 } |
132 } | 125 } |
133 } catch (e) { | 126 } catch (e) { |
134 %_Call(deferred.reject, UNDEFINED, e); | 127 %_Call(deferred.reject, UNDEFINED, e); |
135 } | 128 } |
136 return deferred.promise; | 129 return deferred.promise; |
137 } | 130 } |
138 | 131 |
139 function MarkPromiseAsHandled(promise) { | |
140 %PromiseMarkAsHandled(promise); | |
141 } | |
142 | |
143 // ------------------------------------------------------------------- | 132 // ------------------------------------------------------------------- |
144 // Install exported functions. | 133 // Install exported functions. |
145 | 134 |
146 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ | 135 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ |
147 "all", PromiseAll, | 136 "all", PromiseAll, |
148 "race", PromiseRace, | 137 "race", PromiseRace, |
149 ]); | 138 ]); |
150 | 139 |
151 %InstallToContext([ | 140 %InstallToContext([ |
152 "promise_reject", DoRejectPromise, | |
153 "promise_id_resolve_handler", PromiseIdResolveHandler, | 141 "promise_id_resolve_handler", PromiseIdResolveHandler, |
154 "promise_id_reject_handler", PromiseIdRejectHandler | 142 "promise_id_reject_handler", PromiseIdRejectHandler |
155 ]); | 143 ]); |
156 | 144 |
157 // This allows extras to create promises quickly without building extra | |
158 // resolve/reject closures, and allows them to later resolve and reject any | |
159 // promise without having to hold on to those closures forever. | |
160 utils.InstallFunctions(extrasUtils, 0, [ | |
161 "rejectPromise", DoRejectPromise, | |
162 "markPromiseAsHandled", MarkPromiseAsHandled | |
163 ]); | |
164 | |
165 }) | 145 }) |
OLD | NEW |