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 30 matching lines...) Expand all Loading... |
41 SpeciesConstructor = from.SpeciesConstructor; | 41 SpeciesConstructor = from.SpeciesConstructor; |
42 }); | 42 }); |
43 | 43 |
44 // ------------------------------------------------------------------- | 44 // ------------------------------------------------------------------- |
45 | 45 |
46 // [[PromiseState]] values: | 46 // [[PromiseState]] values: |
47 const kPending = 0; | 47 const kPending = 0; |
48 const kFulfilled = +1; | 48 const kFulfilled = +1; |
49 const kRejected = -1; | 49 const kRejected = -1; |
50 | 50 |
51 var lastMicrotaskId = 0; | |
52 | |
53 function PromiseNextMicrotaskID() { | |
54 return ++lastMicrotaskId; | |
55 } | |
56 | |
57 // ES#sec-createresolvingfunctions | 51 // ES#sec-createresolvingfunctions |
58 // CreateResolvingFunctions ( promise ) | 52 // CreateResolvingFunctions ( promise ) |
59 function CreateResolvingFunctions(promise, debugEvent) { | 53 function CreateResolvingFunctions(promise, debugEvent) { |
60 var alreadyResolved = false; | 54 var alreadyResolved = false; |
61 | 55 |
62 // ES#sec-promise-resolve-functions | 56 // ES#sec-promise-resolve-functions |
63 // Promise Resolve Functions | 57 // Promise Resolve Functions |
64 var resolve = value => { | 58 var resolve = value => { |
65 if (alreadyResolved === true) return; | 59 if (alreadyResolved === true) return; |
66 alreadyResolved = true; | 60 alreadyResolved = true; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // different stacks from direct Promise use, but we save and restore a | 189 // different stacks from direct Promise use, but we save and restore a |
196 // stack once for all reactions. TODO(littledan): Improve this case. | 190 // stack once for all reactions. TODO(littledan): Improve this case. |
197 if (!IS_UNDEFINED(deferreds) && | 191 if (!IS_UNDEFINED(deferreds) && |
198 HAS_PRIVATE(deferreds.promise, promiseHandledBySymbol) && | 192 HAS_PRIVATE(deferreds.promise, promiseHandledBySymbol) && |
199 HAS_PRIVATE(GET_PRIVATE(deferreds.promise, promiseHandledBySymbol), | 193 HAS_PRIVATE(GET_PRIVATE(deferreds.promise, promiseHandledBySymbol), |
200 promiseAsyncStackIDSymbol)) { | 194 promiseAsyncStackIDSymbol)) { |
201 id = GET_PRIVATE(GET_PRIVATE(deferreds.promise, promiseHandledBySymbol), | 195 id = GET_PRIVATE(GET_PRIVATE(deferreds.promise, promiseHandledBySymbol), |
202 promiseAsyncStackIDSymbol); | 196 promiseAsyncStackIDSymbol); |
203 name = "async function"; | 197 name = "async function"; |
204 } else { | 198 } else { |
205 id = PromiseNextMicrotaskID(); | 199 id = %DebugNextMicrotaskId(); |
206 name = status === kFulfilled ? "Promise.resolve" : "Promise.reject"; | 200 name = status === kFulfilled ? "Promise.resolve" : "Promise.reject"; |
207 %DebugAsyncTaskEvent("enqueue", id, name); | 201 %DebugAsyncTaskEvent("enqueue", id, name); |
208 } | 202 } |
209 } | 203 } |
210 %EnqueuePromiseReactionJob(value, tasks, deferreds, id, name); | 204 %EnqueuePromiseReactionJob(value, tasks, deferreds, id, name); |
211 } | 205 } |
212 | 206 |
213 function PromiseAttachCallbacks(promise, deferred, onResolve, onReject) { | 207 function PromiseAttachCallbacks(promise, deferred, onResolve, onReject) { |
214 var maybeResolveCallbacks = | 208 var maybeResolveCallbacks = |
215 GET_PRIVATE(promise, promiseFulfillReactionsSymbol); | 209 GET_PRIVATE(promise, promiseFulfillReactionsSymbol); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 294 } |
301 | 295 |
302 if (IS_CALLABLE(then)) { | 296 if (IS_CALLABLE(then)) { |
303 var callbacks = CreateResolvingFunctions(promise, false); | 297 var callbacks = CreateResolvingFunctions(promise, false); |
304 var id, name, instrumenting = DEBUG_IS_ACTIVE; | 298 var id, name, instrumenting = DEBUG_IS_ACTIVE; |
305 if (instrumenting) { | 299 if (instrumenting) { |
306 if (IsPromise(resolution)) { | 300 if (IsPromise(resolution)) { |
307 // Mark the dependency of the new promise on the resolution | 301 // Mark the dependency of the new promise on the resolution |
308 SET_PRIVATE(resolution, promiseHandledBySymbol, promise); | 302 SET_PRIVATE(resolution, promiseHandledBySymbol, promise); |
309 } | 303 } |
310 id = PromiseNextMicrotaskID(); | 304 id = %DebugNextMicrotaskId(); |
311 name = "PromiseResolveThenableJob"; | 305 name = "PromiseResolveThenableJob"; |
312 %DebugAsyncTaskEvent("enqueue", id, name); | 306 %DebugAsyncTaskEvent("enqueue", id, name); |
313 } | 307 } |
314 %EnqueuePromiseResolveThenableJob( | 308 %EnqueuePromiseResolveThenableJob( |
315 resolution, then, callbacks.resolve, callbacks.reject, id, name); | 309 resolution, then, callbacks.resolve, callbacks.reject, id, name); |
316 return; | 310 return; |
317 } | 311 } |
318 } | 312 } |
319 FulfillPromise(promise, kFulfilled, resolution, | 313 FulfillPromise(promise, kFulfilled, resolution, |
320 promiseFulfillReactionsSymbol); | 314 promiseFulfillReactionsSymbol); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 utils.InstallFunctions(extrasUtils, 0, [ | 674 utils.InstallFunctions(extrasUtils, 0, [ |
681 "createPromise", PromiseCreate, | 675 "createPromise", PromiseCreate, |
682 "resolvePromise", ResolvePromise, | 676 "resolvePromise", ResolvePromise, |
683 "rejectPromise", DoRejectPromise | 677 "rejectPromise", DoRejectPromise |
684 ]); | 678 ]); |
685 | 679 |
686 utils.Export(function(to) { | 680 utils.Export(function(to) { |
687 to.IsPromise = IsPromise; | 681 to.IsPromise = IsPromise; |
688 to.PromiseCreate = PromiseCreate; | 682 to.PromiseCreate = PromiseCreate; |
689 to.PromiseThen = PromiseThen; | 683 to.PromiseThen = PromiseThen; |
690 to.PromiseNextMicrotaskID = PromiseNextMicrotaskID; | |
691 | 684 |
692 to.GlobalPromise = GlobalPromise; | 685 to.GlobalPromise = GlobalPromise; |
693 to.NewPromiseCapability = NewPromiseCapability; | 686 to.NewPromiseCapability = NewPromiseCapability; |
694 to.PerformPromiseThen = PerformPromiseThen; | 687 to.PerformPromiseThen = PerformPromiseThen; |
695 to.ResolvePromise = ResolvePromise; | 688 to.ResolvePromise = ResolvePromise; |
696 to.RejectPromise = RejectPromise; | 689 to.RejectPromise = RejectPromise; |
697 }); | 690 }); |
698 | 691 |
699 }) | 692 }) |
OLD | NEW |