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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } else { | 178 } else { |
179 %_Call(deferred.reject, UNDEFINED, exception); | 179 %_Call(deferred.reject, UNDEFINED, exception); |
180 } | 180 } |
181 } catch (e) { } | 181 } catch (e) { } |
182 } finally { | 182 } finally { |
183 if (debug_is_active) %DebugPopPromise(); | 183 if (debug_is_active) %DebugPopPromise(); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 function PromiseEnqueue(value, tasks, deferreds, status) { | 187 function PromiseEnqueue(value, tasks, deferreds, status) { |
188 var id, name, beforeDebug, afterDebug, instrumenting = DEBUG_IS_ACTIVE; | 188 var id, name, instrumenting = DEBUG_IS_ACTIVE; |
189 | 189 |
190 if (instrumenting) { | 190 if (instrumenting) { |
191 // In an async function, reuse the existing stack related to the outer | 191 // In an async function, reuse the existing stack related to the outer |
192 // Promise. Otherwise, e.g. in a direct call to then, save a new stack. | 192 // Promise. Otherwise, e.g. in a direct call to then, save a new stack. |
193 // Promises with multiple reactions with one or more of them being async | 193 // Promises with multiple reactions with one or more of them being async |
194 // functions will not get a good stack trace, as async functions require | 194 // functions will not get a good stack trace, as async functions require |
195 // different stacks from direct Promise use, but we save and restore a | 195 // different stacks from direct Promise use, but we save and restore a |
196 // stack once for all reactions. TODO(littledan): Improve this case. | 196 // stack once for all reactions. TODO(littledan): Improve this case. |
197 if (!IS_UNDEFINED(deferreds) && | 197 if (!IS_UNDEFINED(deferreds) && |
198 HAS_PRIVATE(deferreds.promise, promiseHandledBySymbol) && | 198 HAS_PRIVATE(deferreds.promise, promiseHandledBySymbol) && |
199 HAS_PRIVATE(GET_PRIVATE(deferreds.promise, promiseHandledBySymbol), | 199 HAS_PRIVATE(GET_PRIVATE(deferreds.promise, promiseHandledBySymbol), |
200 promiseAsyncStackIDSymbol)) { | 200 promiseAsyncStackIDSymbol)) { |
201 id = GET_PRIVATE(GET_PRIVATE(deferreds.promise, promiseHandledBySymbol), | 201 id = GET_PRIVATE(GET_PRIVATE(deferreds.promise, promiseHandledBySymbol), |
202 promiseAsyncStackIDSymbol); | 202 promiseAsyncStackIDSymbol); |
203 name = "async function"; | 203 name = "async function"; |
204 } else { | 204 } else { |
205 id = PromiseNextMicrotaskID(); | 205 id = PromiseNextMicrotaskID(); |
206 name = status === kFulfilled ? "Promise.resolve" : "Promise.reject"; | 206 name = status === kFulfilled ? "Promise.resolve" : "Promise.reject"; |
207 %DebugAsyncTaskEvent({ type: "enqueue", id: id, name: name }); | 207 %DebugAsyncTaskEvent("enqueue", id, name); |
208 } | 208 } |
209 | |
210 beforeDebug = { type: "willHandle", id: id, name: name }; | |
211 afterDebug = { type: "didHandle", id: id, name: name }; | |
212 } | 209 } |
213 | 210 %EnqueuePromiseReactionJob(value, tasks, deferreds, id, name); |
214 %EnqueuePromiseReactionJob(value, tasks, deferreds, beforeDebug, afterDebug); | |
215 } | 211 } |
216 | 212 |
217 function PromiseAttachCallbacks(promise, deferred, onResolve, onReject) { | 213 function PromiseAttachCallbacks(promise, deferred, onResolve, onReject) { |
218 var maybeResolveCallbacks = | 214 var maybeResolveCallbacks = |
219 GET_PRIVATE(promise, promiseFulfillReactionsSymbol); | 215 GET_PRIVATE(promise, promiseFulfillReactionsSymbol); |
220 if (IS_UNDEFINED(maybeResolveCallbacks)) { | 216 if (IS_UNDEFINED(maybeResolveCallbacks)) { |
221 SET_PRIVATE(promise, promiseFulfillReactionsSymbol, onResolve); | 217 SET_PRIVATE(promise, promiseFulfillReactionsSymbol, onResolve); |
222 SET_PRIVATE(promise, promiseRejectReactionsSymbol, onReject); | 218 SET_PRIVATE(promise, promiseRejectReactionsSymbol, onReject); |
223 SET_PRIVATE(promise, promiseDeferredReactionSymbol, deferred); | 219 SET_PRIVATE(promise, promiseDeferredReactionSymbol, deferred); |
224 } else if (!IS_ARRAY(maybeResolveCallbacks)) { | 220 } else if (!IS_ARRAY(maybeResolveCallbacks)) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 294 } |
299 // Don't cause a debug event as this case is forwarding a rejection | 295 // Don't cause a debug event as this case is forwarding a rejection |
300 RejectPromise(promise, thenableValue, false); | 296 RejectPromise(promise, thenableValue, false); |
301 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); | 297 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); |
302 return; | 298 return; |
303 } | 299 } |
304 } | 300 } |
305 | 301 |
306 if (IS_CALLABLE(then)) { | 302 if (IS_CALLABLE(then)) { |
307 var callbacks = CreateResolvingFunctions(promise, false); | 303 var callbacks = CreateResolvingFunctions(promise, false); |
308 var id, before_debug_event, after_debug_event; | 304 var id, name, instrumenting = DEBUG_IS_ACTIVE; |
309 var instrumenting = DEBUG_IS_ACTIVE; | |
310 if (instrumenting) { | 305 if (instrumenting) { |
311 if (IsPromise(resolution)) { | 306 if (IsPromise(resolution)) { |
312 // Mark the dependency of the new promise on the resolution | 307 // Mark the dependency of the new promise on the resolution |
313 SET_PRIVATE(resolution, promiseHandledBySymbol, promise); | 308 SET_PRIVATE(resolution, promiseHandledBySymbol, promise); |
314 } | 309 } |
315 id = PromiseNextMicrotaskID(); | 310 id = PromiseNextMicrotaskID(); |
316 before_debug_event = { | 311 name = "PromiseResolveThenableJob"; |
317 type: "willHandle", | 312 %DebugAsyncTaskEvent("enqueue", id, name); |
318 id: id, | |
319 name: "PromiseResolveThenableJob" | |
320 }; | |
321 after_debug_event = { | |
322 type: "didHandle", | |
323 id: id, | |
324 name: "PromiseResolveThenableJob" | |
325 }; | |
326 %DebugAsyncTaskEvent({ | |
327 type: "enqueue", | |
328 id: id, | |
329 name: "PromiseResolveThenableJob" | |
330 }); | |
331 } | 313 } |
332 %EnqueuePromiseResolveThenableJob( | 314 %EnqueuePromiseResolveThenableJob( |
333 resolution, then, callbacks.resolve, callbacks.reject, | 315 resolution, then, callbacks.resolve, callbacks.reject, id, name); |
334 before_debug_event, after_debug_event); | |
335 return; | 316 return; |
336 } | 317 } |
337 } | 318 } |
338 FulfillPromise(promise, kFulfilled, resolution, | 319 FulfillPromise(promise, kFulfilled, resolution, |
339 promiseFulfillReactionsSymbol); | 320 promiseFulfillReactionsSymbol); |
340 } | 321 } |
341 | 322 |
342 // ES#sec-rejectpromise | 323 // ES#sec-rejectpromise |
343 // RejectPromise ( promise, reason ) | 324 // RejectPromise ( promise, reason ) |
344 function RejectPromise(promise, reason, debugEvent) { | 325 function RejectPromise(promise, reason, debugEvent) { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 to.PromiseNextMicrotaskID = PromiseNextMicrotaskID; | 690 to.PromiseNextMicrotaskID = PromiseNextMicrotaskID; |
710 | 691 |
711 to.GlobalPromise = GlobalPromise; | 692 to.GlobalPromise = GlobalPromise; |
712 to.NewPromiseCapability = NewPromiseCapability; | 693 to.NewPromiseCapability = NewPromiseCapability; |
713 to.PerformPromiseThen = PerformPromiseThen; | 694 to.PerformPromiseThen = PerformPromiseThen; |
714 to.ResolvePromise = ResolvePromise; | 695 to.ResolvePromise = ResolvePromise; |
715 to.RejectPromise = RejectPromise; | 696 to.RejectPromise = RejectPromise; |
716 }); | 697 }); |
717 | 698 |
718 }) | 699 }) |
OLD | NEW |