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

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

Issue 2572623002: PromiseHandle port to TF (Closed)
Patch Set: create TFS 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(
Benedikt Meurer 2016/12/13 06:20:52 Why do you need to put this into a separate builti
896 compiler::CodeAssemblerState* state) {
897 CodeStubAssembler a(state);
898 typedef compiler::Node Node;
899 typedef CodeStubAssembler::Label Label;
900 typedef CodeStubAssembler::Variable Variable;
901
902 Node* const promise = a.Parameter(1);
903 Node* const on_reject = a.Parameter(2);
904 Node* const exception = a.Parameter(3);
905 Node* const context = a.Parameter(6);
906 Isolate* isolate = a.isolate();
907
908 Callable call_callable = CodeFactory::Call(isolate);
909 Variable var_unused(&a, MachineRepresentation::kTagged);
910
911 Label out(&a), if_internalhandler(&a), if_customhandler(&a, Label::kDeferred);
912 a.Branch(a.IsUndefined(on_reject), &if_internalhandler, &if_customhandler);
913
914 a.Bind(&if_internalhandler);
915 {
916 a.CallRuntime(Runtime::kPromiseReject, context, promise, exception,
917 a.FalseConstant());
918 a.Goto(&out);
919 }
920
921 a.Bind(&if_customhandler);
922 {
923 Node* const maybe_exception = a.CallJS(call_callable, context, on_reject,
924 a.UndefinedConstant(), exception);
925 // This doesn't do anything
926 a.GotoIfException(maybe_exception, &out, &var_unused);
927 a.Goto(&out);
928 }
929
930 a.Bind(&out);
931 a.Return(a.UndefinedConstant());
932 }
933
934 void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
935 CodeStubAssembler a(state);
936 typedef compiler::Node Node;
937 typedef CodeStubAssembler::Label Label;
938 typedef CodeStubAssembler::Variable Variable;
939
940 Node* const value = a.Parameter(1);
941 Node* const handler = a.Parameter(2);
942 Node* const deferred = a.Parameter(3);
943 Node* const context = a.Parameter(6);
944 Isolate* isolate = a.isolate();
945
946 // Get promise from deferred
947 Callable getproperty_callable = CodeFactory::GetProperty(isolate);
948 Node* const key =
949 a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked("promise"));
950 Node* const promise =
951 a.CallStub(getproperty_callable, context, deferred, key);
952
953 Variable var_reason(&a, MachineRepresentation::kTagged);
954
955 Node* const is_debug_active = a.IsDebugActive();
956 Label run_handler(&a), if_rejectpromise(&a), debug_push(&a, Label::kDeferred),
957 debug_pop(&a, Label::kDeferred);
958 a.Branch(is_debug_active, &debug_push, &run_handler);
959
960 a.Bind(&debug_push);
961 {
962 a.CallRuntime(Runtime::kDebugPushPromise, context, promise);
963 a.Goto(&run_handler);
964 }
965
966 a.Bind(&run_handler);
967 {
968 Callable call_callable = CodeFactory::Call(isolate);
969
970 Node* const result =
971 a.CallJS(call_callable, context, handler, a.UndefinedConstant(), value);
972
973 a.GotoIfException(result, &if_rejectpromise, &var_reason);
974
975 Node* const key = a.HeapConstant(
976 isolate->factory()->NewStringFromAsciiChecked("resolve"));
977 Node* const on_resolve =
978 a.CallStub(getproperty_callable, context, deferred, key);
979
980 Label if_internalhandler(&a), if_customhandler(&a, Label::kDeferred);
981 a.Branch(a.IsUndefined(on_resolve), &if_internalhandler, &if_customhandler);
982
983 a.Bind(&if_internalhandler);
984 InternalResolvePromise(&a, context, promise, result, &debug_pop);
985
986 a.Bind(&if_customhandler);
987 {
988 Node* const maybe_exception = a.CallJS(call_callable, context, on_resolve,
989 a.UndefinedConstant(), result);
990 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason);
991 a.Goto(&debug_pop);
992 }
993 }
994
995 a.Bind(&if_rejectpromise);
996 {
997 Node* const key =
998 a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked("reject"));
999 Node* const on_reject =
1000 a.CallStub(getproperty_callable, context, deferred, key);
1001
1002 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate);
1003 a.CallStub(promise_handle_reject, context, promise, on_reject,
1004 var_reason.value());
1005 a.Goto(&debug_pop);
1006 }
1007
1008 a.Bind(&debug_pop);
1009 {
1010 Label out(&a);
1011
1012 a.GotoUnless(is_debug_active, &out);
1013 a.CallRuntime(Runtime::kDebugPopPromise, context);
1014 a.Goto(&out);
1015
1016 a.Bind(&out);
1017 a.Return(a.UndefinedConstant());
1018 }
1019 }
1020
895 } // namespace internal 1021 } // namespace internal
896 } // namespace v8 1022 } // 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