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 out(&a), 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.Goto(&out); | |
Igor Sheludko
2016/12/13 23:09:00
Maybe a.Return(a.UndefinedConstant()); ?
gsathya
2016/12/13 23:51:02
Done.
| |
920 } | |
921 | |
922 a.Bind(&if_customhandler); | |
923 { | |
924 Node* const maybe_exception = a.CallJS(call_callable, context, on_reject, | |
925 a.UndefinedConstant(), exception); | |
926 // This doesn't do anything | |
927 a.GotoIfException(maybe_exception, &out, &var_unused); | |
928 a.Goto(&out); | |
Igor Sheludko
2016/12/13 23:09:00
Same here.
gsathya
2016/12/13 23:51:03
Done.
| |
929 } | |
930 | |
931 a.Bind(&out); | |
932 a.Return(a.UndefinedConstant()); | |
933 } | |
934 | |
935 void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) { | |
936 CodeStubAssembler a(state); | |
937 typedef compiler::Node Node; | |
938 typedef CodeStubAssembler::Label Label; | |
939 typedef CodeStubAssembler::Variable Variable; | |
940 | |
941 Node* const value = a.Parameter(1); | |
942 Node* const handler = a.Parameter(2); | |
943 Node* const deferred = a.Parameter(3); | |
944 Node* const context = a.Parameter(6); | |
945 Isolate* isolate = a.isolate(); | |
946 | |
947 // Get promise from deferred | |
948 Callable getproperty_callable = CodeFactory::GetProperty(isolate); | |
949 Node* const key = | |
950 a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked("promise")); | |
Igor Sheludko
2016/12/13 23:09:00
The lookup will work faster if you create an inter
gsathya
2016/12/13 23:51:03
Done.
| |
951 Node* const promise = | |
952 a.CallStub(getproperty_callable, context, deferred, key); | |
953 | |
954 Variable var_reason(&a, MachineRepresentation::kTagged); | |
955 | |
956 Node* const is_debug_active = a.IsDebugActive(); | |
957 Label run_handler(&a), if_rejectpromise(&a), debug_push(&a, Label::kDeferred), | |
958 debug_pop(&a, Label::kDeferred); | |
959 a.Branch(is_debug_active, &debug_push, &run_handler); | |
960 | |
961 a.Bind(&debug_push); | |
962 { | |
963 a.CallRuntime(Runtime::kDebugPushPromise, context, promise); | |
964 a.Goto(&run_handler); | |
965 } | |
966 | |
967 a.Bind(&run_handler); | |
968 { | |
969 Callable call_callable = CodeFactory::Call(isolate); | |
970 | |
971 Node* const result = | |
972 a.CallJS(call_callable, context, handler, a.UndefinedConstant(), value); | |
973 | |
974 a.GotoIfException(result, &if_rejectpromise, &var_reason); | |
975 | |
976 Node* const key = a.HeapConstant( | |
977 isolate->factory()->NewStringFromAsciiChecked("resolve")); | |
Igor Sheludko
2016/12/13 23:09:00
Same here.
gsathya
2016/12/13 23:51:02
Done.
| |
978 Node* const on_resolve = | |
979 a.CallStub(getproperty_callable, context, deferred, key); | |
980 | |
981 Label if_internalhandler(&a), if_customhandler(&a, Label::kDeferred); | |
982 a.Branch(a.IsUndefined(on_resolve), &if_internalhandler, &if_customhandler); | |
983 | |
984 a.Bind(&if_internalhandler); | |
985 InternalResolvePromise(&a, context, promise, result, &debug_pop); | |
986 | |
987 a.Bind(&if_customhandler); | |
988 { | |
989 Node* const maybe_exception = a.CallJS(call_callable, context, on_resolve, | |
990 a.UndefinedConstant(), result); | |
991 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason); | |
992 a.Goto(&debug_pop); | |
993 } | |
994 } | |
995 | |
996 a.Bind(&if_rejectpromise); | |
997 { | |
998 Node* const key = | |
999 a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked("reject")); | |
1000 Node* const on_reject = | |
1001 a.CallStub(getproperty_callable, context, deferred, key); | |
1002 | |
1003 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate); | |
1004 a.CallStub(promise_handle_reject, context, promise, on_reject, | |
1005 var_reason.value()); | |
1006 a.Goto(&debug_pop); | |
1007 } | |
1008 | |
1009 a.Bind(&debug_pop); | |
1010 { | |
1011 Label out(&a); | |
1012 | |
1013 a.GotoUnless(is_debug_active, &out); | |
1014 a.CallRuntime(Runtime::kDebugPopPromise, context); | |
1015 a.Goto(&out); | |
1016 | |
1017 a.Bind(&out); | |
1018 a.Return(a.UndefinedConstant()); | |
1019 } | |
1020 } | |
1021 | |
895 } // namespace internal | 1022 } // namespace internal |
896 } // namespace v8 | 1023 } // namespace v8 |
OLD | NEW |