OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/builtins/builtins-promise.h" | 5 #include "src/builtins/builtins-promise.h" |
6 #include "src/builtins/builtins-constructor.h" | 6 #include "src/builtins/builtins-constructor.h" |
7 #include "src/builtins/builtins-utils.h" | 7 #include "src/builtins/builtins-utils.h" |
8 #include "src/builtins/builtins.h" | 8 #include "src/builtins/builtins.h" |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/code-stub-assembler.h" | 10 #include "src/code-stub-assembler.h" |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 { | 565 { |
566 Label reject(this); | 566 Label reject(this); |
567 Node* const result = LoadObjectField(promise, JSPromise::kResultOffset); | 567 Node* const result = LoadObjectField(promise, JSPromise::kResultOffset); |
568 GotoUnless(WordEqual(status, SmiConstant(v8::Promise::kFulfilled)), | 568 GotoUnless(WordEqual(status, SmiConstant(v8::Promise::kFulfilled)), |
569 &reject); | 569 &reject); |
570 | 570 |
571 Node* info = AllocatePromiseReactionJobInfo( | 571 Node* info = AllocatePromiseReactionJobInfo( |
572 promise, result, var_on_resolve.value(), deferred_promise, | 572 promise, result, var_on_resolve.value(), deferred_promise, |
573 deferred_on_resolve, deferred_on_reject, context); | 573 deferred_on_resolve, deferred_on_reject, context); |
574 // TODO(gsathya): Move this to TF | 574 // TODO(gsathya): Move this to TF |
575 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, | 575 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, promise, |
576 SmiConstant(v8::Promise::kFulfilled)); | 576 SmiConstant(v8::Promise::kFulfilled)); |
577 Goto(&out); | 577 Goto(&out); |
578 | 578 |
579 Bind(&reject); | 579 Bind(&reject); |
580 { | 580 { |
581 Node* const has_handler = PromiseHasHandler(promise); | 581 Node* const has_handler = PromiseHasHandler(promise); |
582 Label enqueue(this); | 582 Label enqueue(this); |
583 | 583 |
584 // TODO(gsathya): Fold these runtime calls and move to TF. | 584 // TODO(gsathya): Fold these runtime calls and move to TF. |
585 GotoIf(has_handler, &enqueue); | 585 GotoIf(has_handler, &enqueue); |
586 CallRuntime(Runtime::kPromiseRevokeReject, context, promise); | 586 CallRuntime(Runtime::kPromiseRevokeReject, context, promise); |
587 Goto(&enqueue); | 587 Goto(&enqueue); |
588 | 588 |
589 Bind(&enqueue); | 589 Bind(&enqueue); |
590 { | 590 { |
591 Node* info = AllocatePromiseReactionJobInfo( | 591 Node* info = AllocatePromiseReactionJobInfo( |
592 promise, result, var_on_reject.value(), deferred_promise, | 592 promise, result, var_on_reject.value(), deferred_promise, |
593 deferred_on_resolve, deferred_on_reject, context); | 593 deferred_on_resolve, deferred_on_reject, context); |
594 // TODO(gsathya): Move this to TF | 594 // TODO(gsathya): Move this to TF |
595 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, | 595 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, |
596 SmiConstant(v8::Promise::kRejected)); | 596 promise, SmiConstant(v8::Promise::kRejected)); |
597 Goto(&out); | 597 Goto(&out); |
598 } | 598 } |
599 } | 599 } |
600 } | 600 } |
601 } | 601 } |
602 | 602 |
603 Bind(&out); | 603 Bind(&out); |
604 PromiseSetHasHandler(promise); | 604 PromiseSetHasHandler(promise); |
605 return deferred_promise; | 605 return deferred_promise; |
606 } | 606 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 Node* reject = nullptr; | 787 Node* reject = nullptr; |
788 std::tie(resolve, reject) = CreatePromiseResolvingFunctions( | 788 std::tie(resolve, reject) = CreatePromiseResolvingFunctions( |
789 promise, FalseConstant(), native_context); | 789 promise, FalseConstant(), native_context); |
790 | 790 |
791 Node* const info = AllocatePromiseResolveThenableJobInfo( | 791 Node* const info = AllocatePromiseResolveThenableJobInfo( |
792 result, var_then.value(), resolve, reject, context); | 792 result, var_then.value(), resolve, reject, context); |
793 | 793 |
794 Label enqueue(this); | 794 Label enqueue(this); |
795 GotoUnless(IsDebugActive(), &enqueue); | 795 GotoUnless(IsDebugActive(), &enqueue); |
796 | 796 |
797 Node* const debug_id = CallRuntime(Runtime::kDebugNextMicrotaskId, context); | 797 Node* const debug_id = |
| 798 CallRuntime(Runtime::kDebugNextAsyncTaskId, context, promise); |
798 Node* const debug_name = SmiConstant(kDebugPromiseResolveThenableJob); | 799 Node* const debug_name = SmiConstant(kDebugPromiseResolveThenableJob); |
799 CallRuntime(Runtime::kDebugAsyncTaskEvent, context, | |
800 SmiConstant(kDebugEnqueue), debug_id, debug_name); | |
801 | 800 |
802 StoreObjectField(info, PromiseResolveThenableJobInfo::kDebugIdOffset, | 801 StoreObjectField(info, PromiseResolveThenableJobInfo::kDebugIdOffset, |
803 debug_id); | 802 debug_id); |
804 StoreObjectField(info, PromiseResolveThenableJobInfo::kDebugNameOffset, | 803 StoreObjectField(info, PromiseResolveThenableJobInfo::kDebugNameOffset, |
805 debug_name); | 804 debug_name); |
806 | 805 |
807 GotoIf(TaggedIsSmi(result), &enqueue); | 806 GotoIf(TaggedIsSmi(result), &enqueue); |
808 GotoUnless(HasInstanceType(result, JS_PROMISE_TYPE), &enqueue); | 807 GotoUnless(HasInstanceType(result, JS_PROMISE_TYPE), &enqueue); |
809 | 808 |
810 // Mark the dependency of the new promise on the resolution | 809 // Mark the dependency of the new promise on the resolution |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 TrueConstant()); | 847 TrueConstant()); |
849 Goto(&out); | 848 Goto(&out); |
850 } | 849 } |
851 | 850 |
852 Bind(&out); | 851 Bind(&out); |
853 } | 852 } |
854 | 853 |
855 void PromiseBuiltinsAssembler::PromiseFulfill( | 854 void PromiseBuiltinsAssembler::PromiseFulfill( |
856 Node* context, Node* promise, Node* result, | 855 Node* context, Node* promise, Node* result, |
857 v8::Promise::PromiseState status) { | 856 v8::Promise::PromiseState status) { |
858 Label do_promisereset(this); | 857 Label do_promisereset(this), debug_async_event_enqueue_recurring(this); |
859 | 858 |
860 Node* const status_smi = SmiConstant(static_cast<int>(status)); | 859 Node* const status_smi = SmiConstant(static_cast<int>(status)); |
861 Node* const deferred_promise = | 860 Node* const deferred_promise = |
862 LoadObjectField(promise, JSPromise::kDeferredPromiseOffset); | 861 LoadObjectField(promise, JSPromise::kDeferredPromiseOffset); |
863 | 862 |
864 GotoIf(IsUndefined(deferred_promise), &do_promisereset); | 863 GotoIf(IsUndefined(deferred_promise), &debug_async_event_enqueue_recurring); |
865 | 864 |
866 Node* const tasks = | 865 Node* const tasks = |
867 status == v8::Promise::kFulfilled | 866 status == v8::Promise::kFulfilled |
868 ? LoadObjectField(promise, JSPromise::kFulfillReactionsOffset) | 867 ? LoadObjectField(promise, JSPromise::kFulfillReactionsOffset) |
869 : LoadObjectField(promise, JSPromise::kRejectReactionsOffset); | 868 : LoadObjectField(promise, JSPromise::kRejectReactionsOffset); |
870 | 869 |
871 Node* const deferred_on_resolve = | 870 Node* const deferred_on_resolve = |
872 LoadObjectField(promise, JSPromise::kDeferredOnResolveOffset); | 871 LoadObjectField(promise, JSPromise::kDeferredOnResolveOffset); |
873 Node* const deferred_on_reject = | 872 Node* const deferred_on_reject = |
874 LoadObjectField(promise, JSPromise::kDeferredOnRejectOffset); | 873 LoadObjectField(promise, JSPromise::kDeferredOnRejectOffset); |
875 | 874 |
876 Node* const info = AllocatePromiseReactionJobInfo( | 875 Node* const info = AllocatePromiseReactionJobInfo( |
877 promise, result, tasks, deferred_promise, deferred_on_resolve, | 876 promise, result, tasks, deferred_promise, deferred_on_resolve, |
878 deferred_on_reject, context); | 877 deferred_on_reject, context); |
879 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, status_smi); | 878 |
880 Goto(&do_promisereset); | 879 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, promise, |
| 880 status_smi); |
| 881 Goto(&debug_async_event_enqueue_recurring); |
| 882 |
| 883 Bind(&debug_async_event_enqueue_recurring); |
| 884 { |
| 885 GotoUnless(IsDebugActive(), &do_promisereset); |
| 886 CallRuntime(Runtime::kDebugAsyncEventEnqueueRecurring, context, promise, |
| 887 status_smi); |
| 888 Goto(&do_promisereset); |
| 889 } |
881 | 890 |
882 Bind(&do_promisereset); | 891 Bind(&do_promisereset); |
883 { | 892 { |
884 StoreObjectField(promise, JSPromise::kStatusOffset, status_smi); | 893 StoreObjectField(promise, JSPromise::kStatusOffset, status_smi); |
885 StoreObjectField(promise, JSPromise::kResultOffset, result); | 894 StoreObjectField(promise, JSPromise::kResultOffset, result); |
886 StoreObjectFieldRoot(promise, JSPromise::kDeferredPromiseOffset, | 895 StoreObjectFieldRoot(promise, JSPromise::kDeferredPromiseOffset, |
887 Heap::kUndefinedValueRootIndex); | 896 Heap::kUndefinedValueRootIndex); |
888 StoreObjectFieldRoot(promise, JSPromise::kDeferredOnResolveOffset, | 897 StoreObjectFieldRoot(promise, JSPromise::kDeferredOnResolveOffset, |
889 Heap::kUndefinedValueRootIndex); | 898 Heap::kUndefinedValueRootIndex); |
890 StoreObjectFieldRoot(promise, JSPromise::kDeferredOnRejectOffset, | 899 StoreObjectFieldRoot(promise, JSPromise::kDeferredOnRejectOffset, |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 | 1450 |
1442 // 5. Return promiseCapability.[[Promise]]. | 1451 // 5. Return promiseCapability.[[Promise]]. |
1443 Node* const promise = | 1452 Node* const promise = |
1444 LoadObjectField(capability, JSPromiseCapability::kPromiseOffset); | 1453 LoadObjectField(capability, JSPromiseCapability::kPromiseOffset); |
1445 Return(promise); | 1454 Return(promise); |
1446 } | 1455 } |
1447 } | 1456 } |
1448 | 1457 |
1449 } // namespace internal | 1458 } // namespace internal |
1450 } // namespace v8 | 1459 } // namespace v8 |
OLD | NEW |