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 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
14 var InternalArray = utils.InternalArray; | 14 var InternalArray = utils.InternalArray; |
| 15 var MicrotaskEnq; |
15 var promiseCombinedDeferredSymbol = | 16 var promiseCombinedDeferredSymbol = |
16 utils.ImportNow("promise_combined_deferred_symbol"); | 17 utils.ImportNow("promise_combined_deferred_symbol"); |
17 var promiseHasHandlerSymbol = | 18 var promiseHasHandlerSymbol = |
18 utils.ImportNow("promise_has_handler_symbol"); | 19 utils.ImportNow("promise_has_handler_symbol"); |
19 var promiseRejectReactionsSymbol = | 20 var promiseRejectReactionsSymbol = |
20 utils.ImportNow("promise_reject_reactions_symbol"); | 21 utils.ImportNow("promise_reject_reactions_symbol"); |
21 var promiseFulfillReactionsSymbol = | 22 var promiseFulfillReactionsSymbol = |
22 utils.ImportNow("promise_fulfill_reactions_symbol"); | 23 utils.ImportNow("promise_fulfill_reactions_symbol"); |
23 var promiseDeferredReactionsSymbol = | 24 var promiseDeferredReactionsSymbol = |
24 utils.ImportNow("promise_deferred_reactions_symbol"); | 25 utils.ImportNow("promise_deferred_reactions_symbol"); |
25 var promiseRawSymbol = utils.ImportNow("promise_raw_symbol"); | 26 var promiseRawSymbol = utils.ImportNow("promise_raw_symbol"); |
26 var promiseStateSymbol = utils.ImportNow("promise_state_symbol"); | 27 var promiseStateSymbol = utils.ImportNow("promise_state_symbol"); |
27 var promiseResultSymbol = utils.ImportNow("promise_result_symbol"); | 28 var promiseResultSymbol = utils.ImportNow("promise_result_symbol"); |
28 var SpeciesConstructor; | 29 var SpeciesConstructor; |
29 var speciesSymbol = utils.ImportNow("species_symbol"); | 30 var speciesSymbol = utils.ImportNow("species_symbol"); |
30 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 31 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
31 | 32 |
32 utils.Import(function(from) { | 33 utils.Import(function(from) { |
33 SpeciesConstructor = from.SpeciesConstructor; | 34 SpeciesConstructor = from.SpeciesConstructor; |
| 35 MicrotaskEnq = from.MicrotaskEnq; |
34 }); | 36 }); |
35 | 37 |
36 // ------------------------------------------------------------------- | 38 // ------------------------------------------------------------------- |
37 | 39 |
38 // [[PromiseState]] values: | 40 // [[PromiseState]] values: |
39 const kPending = 0; | 41 const kPending = 0; |
40 const kFulfilled = +1; | 42 const kFulfilled = +1; |
41 const kRejected = -1; | 43 const kRejected = -1; |
42 | 44 |
43 var lastMicrotaskId = 0; | 45 var lastMicrotaskId = 0; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 deferred.resolve(result); | 161 deferred.resolve(result); |
160 } %catch (exception) { // Natives syntax to mark this catch block. | 162 } %catch (exception) { // Natives syntax to mark this catch block. |
161 try { deferred.reject(exception); } catch (e) { } | 163 try { deferred.reject(exception); } catch (e) { } |
162 } finally { | 164 } finally { |
163 if (debug_is_active) %DebugPopPromise(); | 165 if (debug_is_active) %DebugPopPromise(); |
164 } | 166 } |
165 } | 167 } |
166 | 168 |
167 function PromiseEnqueue(value, tasks, deferreds, status) { | 169 function PromiseEnqueue(value, tasks, deferreds, status) { |
168 var id, name, instrumenting = DEBUG_IS_ACTIVE; | 170 var id, name, instrumenting = DEBUG_IS_ACTIVE; |
169 %EnqueueMicrotask(function() { | 171 MicrotaskEnq(function() { |
170 if (instrumenting) { | 172 if (instrumenting) { |
171 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); | 173 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); |
172 } | 174 } |
173 if (IS_ARRAY(tasks)) { | 175 if (IS_ARRAY(tasks)) { |
174 for (var i = 0; i < tasks.length; i += 2) { | 176 for (var i = 0; i < tasks.length; i += 2) { |
175 PromiseHandle(value, tasks[i], tasks[i + 1]); | 177 PromiseHandle(value, tasks[i], tasks[i + 1]); |
176 } | 178 } |
177 } else { | 179 } else { |
178 PromiseHandle(value, tasks, deferreds); | 180 PromiseHandle(value, tasks, deferreds); |
179 } | 181 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); | 274 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); |
273 return; | 275 return; |
274 } | 276 } |
275 } | 277 } |
276 | 278 |
277 if (IS_CALLABLE(then)) { | 279 if (IS_CALLABLE(then)) { |
278 // PromiseResolveThenableJob | 280 // PromiseResolveThenableJob |
279 var id; | 281 var id; |
280 var name = "PromiseResolveThenableJob"; | 282 var name = "PromiseResolveThenableJob"; |
281 var instrumenting = DEBUG_IS_ACTIVE; | 283 var instrumenting = DEBUG_IS_ACTIVE; |
282 %EnqueueMicrotask(function() { | 284 MicrotaskEnq(function() { |
283 if (instrumenting) { | 285 if (instrumenting) { |
284 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); | 286 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); |
285 } | 287 } |
286 var callbacks = CreateResolvingFunctions(promise); | 288 var callbacks = CreateResolvingFunctions(promise); |
287 try { | 289 try { |
288 %_Call(then, resolution, callbacks.resolve, callbacks.reject); | 290 %_Call(then, resolution, callbacks.resolve, callbacks.reject); |
289 } catch (e) { | 291 } catch (e) { |
290 %_Call(callbacks.reject, UNDEFINED, e); | 292 %_Call(callbacks.reject, UNDEFINED, e); |
291 } | 293 } |
292 if (instrumenting) { | 294 if (instrumenting) { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 | 647 |
646 to.PromiseCastResolved = PromiseCastResolved; | 648 to.PromiseCastResolved = PromiseCastResolved; |
647 to.PromiseThen = PromiseThen; | 649 to.PromiseThen = PromiseThen; |
648 | 650 |
649 to.GlobalPromise = GlobalPromise; | 651 to.GlobalPromise = GlobalPromise; |
650 to.NewPromiseCapability = NewPromiseCapability; | 652 to.NewPromiseCapability = NewPromiseCapability; |
651 to.PerformPromiseThen = PerformPromiseThen; | 653 to.PerformPromiseThen = PerformPromiseThen; |
652 }); | 654 }); |
653 | 655 |
654 }) | 656 }) |
OLD | NEW |