| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 %PromiseRevokeReject(resolution); | 272 %PromiseRevokeReject(resolution); |
| 273 } | 273 } |
| 274 // Don't cause a debug event as this case is forwarding a rejection | 274 // Don't cause a debug event as this case is forwarding a rejection |
| 275 RejectPromise(promise, thenableValue, false); | 275 RejectPromise(promise, thenableValue, false); |
| 276 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); | 276 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); |
| 277 return; | 277 return; |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 if (IS_CALLABLE(then)) { | 281 if (IS_CALLABLE(then)) { |
| 282 // PromiseResolveThenableJob | 282 var callbacks = CreateResolvingFunctions(promise, false); |
| 283 var id; | 283 var id, before_debug_event, after_debug_event; |
| 284 var name = "PromiseResolveThenableJob"; | 284 if (DEBUG_IS_ACTIVE) { |
| 285 var instrumenting = DEBUG_IS_ACTIVE; | |
| 286 %EnqueueMicrotask(function() { | |
| 287 if (instrumenting) { | |
| 288 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); | |
| 289 } | |
| 290 // These resolving functions simply forward the exception, so | |
| 291 // don't create a new debugEvent. | |
| 292 var callbacks = CreateResolvingFunctions(promise, false); | |
| 293 try { | |
| 294 %_Call(then, resolution, callbacks.resolve, callbacks.reject); | |
| 295 } catch (e) { | |
| 296 %_Call(callbacks.reject, UNDEFINED, e); | |
| 297 } | |
| 298 if (instrumenting) { | |
| 299 %DebugAsyncTaskEvent({ type: "didHandle", id: id, name: name }); | |
| 300 } | |
| 301 }); | |
| 302 if (instrumenting) { | |
| 303 id = ++lastMicrotaskId; | 285 id = ++lastMicrotaskId; |
| 304 %DebugAsyncTaskEvent({ type: "enqueue", id: id, name: name }); | 286 before_debug_event = { |
| 287 type: "willHandle", |
| 288 id: id, |
| 289 name: "PromiseResolveThenableJob" |
| 290 }; |
| 291 after_debug_event = { |
| 292 type: "didHandle", |
| 293 id: id, |
| 294 name: "PromiseResolveThenableJob" |
| 295 }; |
| 296 %DebugAsyncTaskEvent({ |
| 297 type: "enqueue", |
| 298 id: id, |
| 299 name: "PromiseResolveThenableJob" |
| 300 }); |
| 305 } | 301 } |
| 302 %EnqueuePromiseResolveThenableJob( |
| 303 promise, resolution, then, callbacks.resolve, |
| 304 callbacks.reject, before_debug_event, after_debug_event); |
| 306 return; | 305 return; |
| 307 } | 306 } |
| 308 } | 307 } |
| 309 FulfillPromise(promise, kFulfilled, resolution, promiseFulfillReactionsSymbol)
; | 308 FulfillPromise(promise, kFulfilled, resolution, promiseFulfillReactionsSymbol)
; |
| 310 } | 309 } |
| 311 | 310 |
| 312 // ES#sec-rejectpromise | 311 // ES#sec-rejectpromise |
| 313 // RejectPromise ( promise, reason ) | 312 // RejectPromise ( promise, reason ) |
| 314 function RejectPromise(promise, reason, debugEvent) { | 313 function RejectPromise(promise, reason, debugEvent) { |
| 315 // Check promise status to confirm that this reject has an effect. | 314 // Check promise status to confirm that this reject has an effect. |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 "then", PromiseThen, | 602 "then", PromiseThen, |
| 604 "catch", PromiseCatch | 603 "catch", PromiseCatch |
| 605 ]); | 604 ]); |
| 606 | 605 |
| 607 %InstallToContext([ | 606 %InstallToContext([ |
| 608 "promise_catch", PromiseCatch, | 607 "promise_catch", PromiseCatch, |
| 609 "promise_create", PromiseCreate, | 608 "promise_create", PromiseCreate, |
| 610 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, | 609 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, |
| 611 "promise_reject", DoRejectPromise, | 610 "promise_reject", DoRejectPromise, |
| 612 "promise_resolve", ResolvePromise, | 611 "promise_resolve", ResolvePromise, |
| 613 "promise_then", PromiseThen, | 612 "promise_then", PromiseThen |
| 614 ]); | 613 ]); |
| 615 | 614 |
| 616 // This allows extras to create promises quickly without building extra | 615 // This allows extras to create promises quickly without building extra |
| 617 // resolve/reject closures, and allows them to later resolve and reject any | 616 // resolve/reject closures, and allows them to later resolve and reject any |
| 618 // promise without having to hold on to those closures forever. | 617 // promise without having to hold on to those closures forever. |
| 619 utils.InstallFunctions(extrasUtils, 0, [ | 618 utils.InstallFunctions(extrasUtils, 0, [ |
| 620 "createPromise", PromiseCreate, | 619 "createPromise", PromiseCreate, |
| 621 "resolvePromise", ResolvePromise, | 620 "resolvePromise", ResolvePromise, |
| 622 "rejectPromise", DoRejectPromise | 621 "rejectPromise", DoRejectPromise |
| 623 ]); | 622 ]); |
| 624 | 623 |
| 625 utils.Export(function(to) { | 624 utils.Export(function(to) { |
| 626 to.PromiseCastResolved = PromiseCastResolved; | 625 to.PromiseCastResolved = PromiseCastResolved; |
| 627 to.PromiseThen = PromiseThen; | 626 to.PromiseThen = PromiseThen; |
| 628 | 627 |
| 629 to.GlobalPromise = GlobalPromise; | 628 to.GlobalPromise = GlobalPromise; |
| 630 to.NewPromiseCapability = NewPromiseCapability; | 629 to.NewPromiseCapability = NewPromiseCapability; |
| 631 to.PerformPromiseThen = PerformPromiseThen; | 630 to.PerformPromiseThen = PerformPromiseThen; |
| 632 to.RejectPromise = RejectPromise; | 631 to.RejectPromise = RejectPromise; |
| 633 }); | 632 }); |
| 634 | 633 |
| 635 }) | 634 }) |
| OLD | NEW |