Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: src/builtins/builtins-promise.cc

Issue 2572623002: PromiseHandle port to TF (Closed)
Patch Set: Address comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698