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-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" |
9 #include "src/promise-utils.h" | 9 #include "src/promise-utils.h" |
10 | 10 |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 Node* const result = a.Parameter(2); | 885 Node* const result = a.Parameter(2); |
886 Node* const context = a.Parameter(5); | 886 Node* const context = a.Parameter(5); |
887 | 887 |
888 Label out(&a); | 888 Label out(&a); |
889 InternalResolvePromise(&a, context, promise, result, &out); | 889 InternalResolvePromise(&a, context, promise, result, &out); |
890 | 890 |
891 a.Bind(&out); | 891 a.Bind(&out); |
892 a.Return(a.UndefinedConstant()); | 892 a.Return(a.UndefinedConstant()); |
893 } | 893 } |
894 | 894 |
| 895 void Builtins::Generate_PromiseHandleReject( |
| 896 compiler::CodeAssemblerState* state) { |
| 897 CodeStubAssembler a(state); |
| 898 typedef compiler::Node Node; |
| 899 typedef CodeStubAssembler::Label Label; |
| 900 typedef CodeStubAssembler::Variable Variable; |
| 901 typedef PromiseHandleRejectDescriptor Descriptor; |
| 902 |
| 903 Node* const promise = a.Parameter(Descriptor::kPromise); |
| 904 Node* const on_reject = a.Parameter(Descriptor::kOnReject); |
| 905 Node* const exception = a.Parameter(Descriptor::kException); |
| 906 Node* const context = a.Parameter(Descriptor::kContext); |
| 907 Isolate* isolate = a.isolate(); |
| 908 |
| 909 Callable call_callable = CodeFactory::Call(isolate); |
| 910 Variable var_unused(&a, MachineRepresentation::kTagged); |
| 911 |
| 912 Label if_internalhandler(&a), if_customhandler(&a, Label::kDeferred); |
| 913 a.Branch(a.IsUndefined(on_reject), &if_internalhandler, &if_customhandler); |
| 914 |
| 915 a.Bind(&if_internalhandler); |
| 916 { |
| 917 a.CallRuntime(Runtime::kPromiseReject, context, promise, exception, |
| 918 a.FalseConstant()); |
| 919 a.Return(a.UndefinedConstant()); |
| 920 } |
| 921 |
| 922 a.Bind(&if_customhandler); |
| 923 { |
| 924 a.CallJS(call_callable, context, on_reject, a.UndefinedConstant(), |
| 925 exception); |
| 926 a.Return(a.UndefinedConstant()); |
| 927 } |
| 928 } |
| 929 |
| 930 void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) { |
| 931 CodeStubAssembler a(state); |
| 932 typedef compiler::Node Node; |
| 933 typedef CodeStubAssembler::Label Label; |
| 934 typedef CodeStubAssembler::Variable Variable; |
| 935 |
| 936 Node* const value = a.Parameter(1); |
| 937 Node* const handler = a.Parameter(2); |
| 938 Node* const deferred = a.Parameter(3); |
| 939 Node* const context = a.Parameter(6); |
| 940 Isolate* isolate = a.isolate(); |
| 941 |
| 942 // Get promise from deferred |
| 943 // TODO(gsathya): Remove this lookup by getting rid of the deferred object. |
| 944 Callable getproperty_callable = CodeFactory::GetProperty(isolate); |
| 945 Node* const key = a.HeapConstant(isolate->factory()->promise_string()); |
| 946 Node* const promise = |
| 947 a.CallStub(getproperty_callable, context, deferred, key); |
| 948 |
| 949 Variable var_reason(&a, MachineRepresentation::kTagged); |
| 950 |
| 951 Node* const is_debug_active = a.IsDebugActive(); |
| 952 Label run_handler(&a), if_rejectpromise(&a), debug_push(&a, Label::kDeferred), |
| 953 debug_pop(&a, Label::kDeferred); |
| 954 a.Branch(is_debug_active, &debug_push, &run_handler); |
| 955 |
| 956 a.Bind(&debug_push); |
| 957 { |
| 958 a.CallRuntime(Runtime::kDebugPushPromise, context, promise); |
| 959 a.Goto(&run_handler); |
| 960 } |
| 961 |
| 962 a.Bind(&run_handler); |
| 963 { |
| 964 Callable call_callable = CodeFactory::Call(isolate); |
| 965 |
| 966 Node* const result = |
| 967 a.CallJS(call_callable, context, handler, a.UndefinedConstant(), value); |
| 968 |
| 969 a.GotoIfException(result, &if_rejectpromise, &var_reason); |
| 970 |
| 971 // TODO(gsathya): Remove this lookup by getting rid of the deferred object. |
| 972 Node* const key = a.HeapConstant(isolate->factory()->resolve_string()); |
| 973 Node* const on_resolve = |
| 974 a.CallStub(getproperty_callable, context, deferred, key); |
| 975 |
| 976 Label if_internalhandler(&a), if_customhandler(&a, Label::kDeferred); |
| 977 a.Branch(a.IsUndefined(on_resolve), &if_internalhandler, &if_customhandler); |
| 978 |
| 979 a.Bind(&if_internalhandler); |
| 980 InternalResolvePromise(&a, context, promise, result, &debug_pop); |
| 981 |
| 982 a.Bind(&if_customhandler); |
| 983 { |
| 984 Node* const maybe_exception = a.CallJS(call_callable, context, on_resolve, |
| 985 a.UndefinedConstant(), result); |
| 986 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason); |
| 987 a.Goto(&debug_pop); |
| 988 } |
| 989 } |
| 990 |
| 991 a.Bind(&if_rejectpromise); |
| 992 { |
| 993 // TODO(gsathya): Remove this lookup by getting rid of the deferred object. |
| 994 Node* const key = a.HeapConstant(isolate->factory()->reject_string()); |
| 995 Node* const on_reject = |
| 996 a.CallStub(getproperty_callable, context, deferred, key); |
| 997 |
| 998 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate); |
| 999 a.CallStub(promise_handle_reject, context, promise, on_reject, |
| 1000 var_reason.value()); |
| 1001 a.Goto(&debug_pop); |
| 1002 } |
| 1003 |
| 1004 a.Bind(&debug_pop); |
| 1005 { |
| 1006 Label out(&a); |
| 1007 |
| 1008 a.GotoUnless(is_debug_active, &out); |
| 1009 a.CallRuntime(Runtime::kDebugPopPromise, context); |
| 1010 a.Goto(&out); |
| 1011 |
| 1012 a.Bind(&out); |
| 1013 a.Return(a.UndefinedConstant()); |
| 1014 } |
| 1015 } |
| 1016 |
895 } // namespace internal | 1017 } // namespace internal |
896 } // namespace v8 | 1018 } // namespace v8 |
OLD | NEW |