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-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 #include "src/builtins/builtins.h" | 7 #include "src/builtins/builtins.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/code-stub-assembler.h" | 9 #include "src/code-stub-assembler.h" |
10 #include "src/promise-utils.h" | 10 #include "src/promise-utils.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 typedef compiler::Node Node; | 15 typedef compiler::Node Node; |
16 typedef CodeStubAssembler::ParameterMode ParameterMode; | 16 typedef CodeStubAssembler::ParameterMode ParameterMode; |
17 typedef compiler::CodeAssemblerState CodeAssemblerState; | 17 typedef compiler::CodeAssemblerState CodeAssemblerState; |
18 | 18 |
19 Node* PromiseBuiltinsAssembler::AllocateAndInitPromise(Node* context, | 19 Node* PromiseBuiltinsAssembler::AllocateAndInitJSPromise(Node* context, |
20 Node* parent) { | 20 Node* parent) { |
21 Node* const instance = AllocateJSPromise(context); | 21 Node* const instance = CodeStubAssembler::AllocateAndInitJSPromise(context); |
22 PromiseInit(instance); | |
23 | 22 |
24 Label out(this); | 23 Label out(this); |
25 GotoUnless(IsPromiseHookEnabled(), &out); | 24 GotoUnless(IsPromiseHookEnabled(), &out); |
| 25 CallRuntime(Runtime::kPromiseHookInit, context, instance, parent); |
| 26 Goto(&out); |
| 27 |
| 28 Bind(&out); |
| 29 return instance; |
| 30 } |
| 31 |
| 32 Node* PromiseBuiltinsAssembler::AllocateAndSetJSPromise(Node* context, |
| 33 Node* status, |
| 34 Node* result, |
| 35 Node* parent) { |
| 36 Node* const instance = |
| 37 CodeStubAssembler::AllocateAndSetJSPromise(context, status, result); |
| 38 |
| 39 Label out(this); |
| 40 GotoUnless(IsPromiseHookEnabled(), &out); |
26 CallRuntime(Runtime::kPromiseHookInit, context, instance, parent); | 41 CallRuntime(Runtime::kPromiseHookInit, context, instance, parent); |
27 Goto(&out); | 42 Goto(&out); |
28 | 43 |
29 Bind(&out); | 44 Bind(&out); |
30 return instance; | 45 return instance; |
31 } | 46 } |
32 | 47 |
33 Node* PromiseBuiltinsAssembler::CreatePromiseResolvingFunctionsContext( | 48 Node* PromiseBuiltinsAssembler::CreatePromiseResolvingFunctionsContext( |
34 Node* promise, Node* debug_event, Node* native_context) { | 49 Node* promise, Node* debug_event, Node* native_context) { |
35 Node* const context = | 50 Node* const context = |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 perform_promise_then(this); | 232 perform_promise_then(this); |
218 Variable var_deferred_promise(this, MachineRepresentation::kTagged), | 233 Variable var_deferred_promise(this, MachineRepresentation::kTagged), |
219 var_deferred_on_resolve(this, MachineRepresentation::kTagged), | 234 var_deferred_on_resolve(this, MachineRepresentation::kTagged), |
220 var_deferred_on_reject(this, MachineRepresentation::kTagged); | 235 var_deferred_on_reject(this, MachineRepresentation::kTagged); |
221 | 236 |
222 Branch(WordEqual(promise_fun, constructor), &fast_promise_capability, | 237 Branch(WordEqual(promise_fun, constructor), &fast_promise_capability, |
223 &promise_capability); | 238 &promise_capability); |
224 | 239 |
225 Bind(&fast_promise_capability); | 240 Bind(&fast_promise_capability); |
226 { | 241 { |
227 Node* const deferred_promise = AllocateAndInitPromise(context, promise); | 242 Node* const deferred_promise = AllocateAndInitJSPromise(context, promise); |
228 var_deferred_promise.Bind(deferred_promise); | 243 var_deferred_promise.Bind(deferred_promise); |
229 var_deferred_on_resolve.Bind(UndefinedConstant()); | 244 var_deferred_on_resolve.Bind(UndefinedConstant()); |
230 var_deferred_on_reject.Bind(UndefinedConstant()); | 245 var_deferred_on_reject.Bind(UndefinedConstant()); |
231 Goto(&perform_promise_then); | 246 Goto(&perform_promise_then); |
232 } | 247 } |
233 | 248 |
234 Bind(&promise_capability); | 249 Bind(&promise_capability); |
235 { | 250 { |
236 // TODO(gsathya): Move this to TF. | 251 // TODO(gsathya): Move this to TF. |
237 Node* const new_promise_capability = LoadContextElement( | 252 Node* const new_promise_capability = LoadContextElement( |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 | 732 |
718 Node* const executor_map = LoadMap(executor); | 733 Node* const executor_map = LoadMap(executor); |
719 GotoUnless(IsCallableMap(executor_map), &if_notcallable); | 734 GotoUnless(IsCallableMap(executor_map), &if_notcallable); |
720 | 735 |
721 Node* const native_context = LoadNativeContext(context); | 736 Node* const native_context = LoadNativeContext(context); |
722 Node* const promise_fun = | 737 Node* const promise_fun = |
723 LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); | 738 LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); |
724 Node* const is_debug_active = IsDebugActive(); | 739 Node* const is_debug_active = IsDebugActive(); |
725 Label if_targetisnotmodified(this), | 740 Label if_targetisnotmodified(this), |
726 if_targetismodified(this, Label::kDeferred), run_executor(this), | 741 if_targetismodified(this, Label::kDeferred), run_executor(this), |
727 debug_push(this), init(this); | 742 debug_push(this); |
728 | 743 |
729 Branch(WordEqual(promise_fun, new_target), &if_targetisnotmodified, | 744 Branch(WordEqual(promise_fun, new_target), &if_targetisnotmodified, |
730 &if_targetismodified); | 745 &if_targetismodified); |
731 | 746 |
732 Variable var_result(this, MachineRepresentation::kTagged), | 747 Variable var_result(this, MachineRepresentation::kTagged), |
733 var_reject_call(this, MachineRepresentation::kTagged), | 748 var_reject_call(this, MachineRepresentation::kTagged), |
734 var_reason(this, MachineRepresentation::kTagged); | 749 var_reason(this, MachineRepresentation::kTagged); |
735 | 750 |
736 Bind(&if_targetisnotmodified); | 751 Bind(&if_targetisnotmodified); |
737 { | 752 { |
738 Node* const instance = AllocateJSPromise(context); | 753 Node* const instance = |
| 754 AllocateAndInitJSPromise(context, UndefinedConstant()); |
739 var_result.Bind(instance); | 755 var_result.Bind(instance); |
740 Goto(&init); | 756 Goto(&debug_push); |
741 } | 757 } |
742 | 758 |
743 Bind(&if_targetismodified); | 759 Bind(&if_targetismodified); |
744 { | 760 { |
745 Callable fast_new_object_stub = CodeFactory::FastNewObject(isolate); | 761 Callable fast_new_object_stub = CodeFactory::FastNewObject(isolate); |
746 Node* const instance = | 762 Node* const instance = |
747 CallStub(fast_new_object_stub, context, promise_fun, new_target); | 763 CallStub(fast_new_object_stub, context, promise_fun, new_target); |
| 764 JSPromiseInit(instance); |
| 765 var_result.Bind(instance); |
748 | 766 |
749 var_result.Bind(instance); | |
750 Goto(&init); | |
751 } | |
752 | |
753 Bind(&init); | |
754 { | |
755 PromiseInit(var_result.value()); | |
756 GotoUnless(IsPromiseHookEnabled(), &debug_push); | 767 GotoUnless(IsPromiseHookEnabled(), &debug_push); |
757 CallRuntime(Runtime::kPromiseHookInit, context, var_result.value(), | 768 CallRuntime(Runtime::kPromiseHookInit, context, instance, |
758 UndefinedConstant()); | 769 UndefinedConstant()); |
759 Goto(&debug_push); | 770 Goto(&debug_push); |
760 } | 771 } |
761 | 772 |
762 Bind(&debug_push); | 773 Bind(&debug_push); |
763 { | 774 { |
764 GotoUnless(is_debug_active, &run_executor); | 775 GotoUnless(is_debug_active, &run_executor); |
765 CallRuntime(Runtime::kDebugPushPromise, context, var_result.value()); | 776 CallRuntime(Runtime::kDebugPushPromise, context, var_result.value()); |
766 Goto(&run_executor); | 777 Goto(&run_executor); |
767 } | 778 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 Node* const message_id = | 823 Node* const message_id = |
813 SmiConstant(MessageTemplate::kResolverNotAFunction); | 824 SmiConstant(MessageTemplate::kResolverNotAFunction); |
814 CallRuntime(Runtime::kThrowTypeError, context, message_id, executor); | 825 CallRuntime(Runtime::kThrowTypeError, context, message_id, executor); |
815 Return(UndefinedConstant()); // Never reached. | 826 Return(UndefinedConstant()); // Never reached. |
816 } | 827 } |
817 } | 828 } |
818 | 829 |
819 TF_BUILTIN(PromiseInternalConstructor, PromiseBuiltinsAssembler) { | 830 TF_BUILTIN(PromiseInternalConstructor, PromiseBuiltinsAssembler) { |
820 Node* const parent = Parameter(1); | 831 Node* const parent = Parameter(1); |
821 Node* const context = Parameter(4); | 832 Node* const context = Parameter(4); |
822 Return(AllocateAndInitPromise(context, parent)); | 833 Return(AllocateAndInitJSPromise(context, parent)); |
823 } | 834 } |
824 | 835 |
825 TF_BUILTIN(PromiseCreateAndSet, PromiseBuiltinsAssembler) { | 836 TF_BUILTIN(PromiseCreateAndSet, PromiseBuiltinsAssembler) { |
826 Node* const status = Parameter(1); | 837 Node* const status = Parameter(1); |
827 Node* const result = Parameter(2); | 838 Node* const result = Parameter(2); |
828 Node* const context = Parameter(5); | 839 Node* const context = Parameter(5); |
829 | 840 |
830 Node* const instance = AllocateJSPromise(context); | 841 Node* const instance = |
831 PromiseSet(instance, status, result); | 842 AllocateAndSetJSPromise(context, status, result, UndefinedConstant()); |
832 | |
833 Label out(this); | |
834 GotoUnless(IsPromiseHookEnabled(), &out); | |
835 CallRuntime(Runtime::kPromiseHookInit, context, instance, | |
836 UndefinedConstant()); | |
837 Goto(&out); | |
838 Bind(&out); | |
839 Return(instance); | 843 Return(instance); |
840 } | 844 } |
841 | 845 |
842 TF_BUILTIN(IsPromise, PromiseBuiltinsAssembler) { | 846 TF_BUILTIN(IsPromise, PromiseBuiltinsAssembler) { |
843 Node* const maybe_promise = Parameter(1); | 847 Node* const maybe_promise = Parameter(1); |
844 Label if_notpromise(this, Label::kDeferred); | 848 Label if_notpromise(this, Label::kDeferred); |
845 | 849 |
846 GotoIf(TaggedIsSmi(maybe_promise), &if_notpromise); | 850 GotoIf(TaggedIsSmi(maybe_promise), &if_notpromise); |
847 | 851 |
848 Node* const result = | 852 Node* const result = |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 CallStub(getproperty_callable, context, promise, then_str); | 1067 CallStub(getproperty_callable, context, promise, then_str); |
1064 Callable call_callable = CodeFactory::Call(isolate); | 1068 Callable call_callable = CodeFactory::Call(isolate); |
1065 Node* const result = | 1069 Node* const result = |
1066 CallJS(call_callable, context, then, promise, on_resolve, on_reject); | 1070 CallJS(call_callable, context, then, promise, on_resolve, on_reject); |
1067 Return(result); | 1071 Return(result); |
1068 } | 1072 } |
1069 } | 1073 } |
1070 | 1074 |
1071 } // namespace internal | 1075 } // namespace internal |
1072 } // namespace v8 | 1076 } // namespace v8 |
OLD | NEW |