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

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

Issue 2581503003: [promisehook] Store promise in PromiseReactionJob (Closed)
Patch Set: rebase correctly 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-stub-assembler.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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 493
494 a->Bind(&fulfilled_check); 494 a->Bind(&fulfilled_check);
495 { 495 {
496 Label reject(a); 496 Label reject(a);
497 Node* const result = 497 Node* const result =
498 a->LoadObjectField(promise, JSPromise::kResultOffset); 498 a->LoadObjectField(promise, JSPromise::kResultOffset);
499 a->GotoUnless(a->WordEqual(status, a->SmiConstant(kPromiseFulfilled)), 499 a->GotoUnless(a->WordEqual(status, a->SmiConstant(kPromiseFulfilled)),
500 &reject); 500 &reject);
501 501
502 // TODO(gsathya): Move this to TF. 502 // TODO(gsathya): Move this to TF.
503 a->CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, result, 503 a->CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, promise,
kozy 2016/12/15 16:07:58 Does it mean that before promise can be collected
504 var_on_resolve.value(), deferred, 504 result, var_on_resolve.value(), deferred,
505 a->SmiConstant(kPromiseFulfilled)); 505 a->SmiConstant(kPromiseFulfilled));
506 a->Goto(&out); 506 a->Goto(&out);
507 507
508 a->Bind(&reject); 508 a->Bind(&reject);
509 { 509 {
510 Node* const has_handler = PromiseHasHandler(a, promise); 510 Node* const has_handler = PromiseHasHandler(a, promise);
511 Label enqueue(a); 511 Label enqueue(a);
512 512
513 // TODO(gsathya): Fold these runtime calls and move to TF. 513 // TODO(gsathya): Fold these runtime calls and move to TF.
514 a->GotoIf(has_handler, &enqueue); 514 a->GotoIf(has_handler, &enqueue);
515 a->CallRuntime(Runtime::kPromiseRevokeReject, context, promise); 515 a->CallRuntime(Runtime::kPromiseRevokeReject, context, promise);
516 a->Goto(&enqueue); 516 a->Goto(&enqueue);
517 517
518 a->Bind(&enqueue); 518 a->Bind(&enqueue);
519 { 519 {
520 a->CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, result, 520 a->CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, promise,
521 var_on_reject.value(), deferred, 521 result, var_on_reject.value(), deferred,
522 a->SmiConstant(kPromiseRejected)); 522 a->SmiConstant(kPromiseRejected));
523 523
524 a->Goto(&out); 524 a->Goto(&out);
525 } 525 }
526 } 526 }
527 } 527 }
528 } 528 }
529 529
530 a->Bind(&out); 530 a->Bind(&out);
531 PromiseSetHasHandler(a, promise); 531 PromiseSetHasHandler(a, promise);
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 a.Return(a.UndefinedConstant()); 902 a.Return(a.UndefinedConstant());
903 } 903 }
904 } 904 }
905 905
906 void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) { 906 void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
907 CodeStubAssembler a(state); 907 CodeStubAssembler a(state);
908 typedef compiler::Node Node; 908 typedef compiler::Node Node;
909 typedef CodeStubAssembler::Label Label; 909 typedef CodeStubAssembler::Label Label;
910 typedef CodeStubAssembler::Variable Variable; 910 typedef CodeStubAssembler::Variable Variable;
911 911
912 Node* const value = a.Parameter(1); 912 Node* const value = a.Parameter(2);
913 Node* const handler = a.Parameter(2); 913 Node* const handler = a.Parameter(3);
914 Node* const deferred = a.Parameter(3); 914 Node* const deferred = a.Parameter(4);
915 Node* const context = a.Parameter(6); 915 Node* const context = a.Parameter(7);
916 Isolate* isolate = a.isolate(); 916 Isolate* isolate = a.isolate();
917 917
918 // Get promise from deferred 918 // Get promise from deferred
919 // TODO(gsathya): Remove this lookup by getting rid of the deferred object. 919 // TODO(gsathya): Remove this lookup by getting rid of the deferred object.
920 Callable getproperty_callable = CodeFactory::GetProperty(isolate); 920 Callable getproperty_callable = CodeFactory::GetProperty(isolate);
921 Node* const key = a.HeapConstant(isolate->factory()->promise_string()); 921 Node* const key = a.HeapConstant(isolate->factory()->promise_string());
922 Node* const promise = 922 Node* const deferred_promise =
923 a.CallStub(getproperty_callable, context, deferred, key); 923 a.CallStub(getproperty_callable, context, deferred, key);
924 924
925 Variable var_reason(&a, MachineRepresentation::kTagged); 925 Variable var_reason(&a, MachineRepresentation::kTagged);
926 926
927 Node* const is_debug_active = a.IsDebugActive(); 927 Node* const is_debug_active = a.IsDebugActive();
928 Label run_handler(&a), if_rejectpromise(&a), debug_push(&a, Label::kDeferred), 928 Label run_handler(&a), if_rejectpromise(&a), debug_push(&a, Label::kDeferred),
929 debug_pop(&a, Label::kDeferred); 929 debug_pop(&a, Label::kDeferred);
930 a.Branch(is_debug_active, &debug_push, &run_handler); 930 a.Branch(is_debug_active, &debug_push, &run_handler);
931 931
932 a.Bind(&debug_push); 932 a.Bind(&debug_push);
933 { 933 {
934 a.CallRuntime(Runtime::kDebugPushPromise, context, promise); 934 a.CallRuntime(Runtime::kDebugPushPromise, context, deferred_promise);
935 a.Goto(&run_handler); 935 a.Goto(&run_handler);
936 } 936 }
937 937
938 a.Bind(&run_handler); 938 a.Bind(&run_handler);
939 { 939 {
940 Callable call_callable = CodeFactory::Call(isolate); 940 Callable call_callable = CodeFactory::Call(isolate);
941 941
942 Node* const result = 942 Node* const result =
943 a.CallJS(call_callable, context, handler, a.UndefinedConstant(), value); 943 a.CallJS(call_callable, context, handler, a.UndefinedConstant(), value);
944 944
945 a.GotoIfException(result, &if_rejectpromise, &var_reason); 945 a.GotoIfException(result, &if_rejectpromise, &var_reason);
946 946
947 // TODO(gsathya): Remove this lookup by getting rid of the deferred object. 947 // TODO(gsathya): Remove this lookup by getting rid of the deferred object.
948 Node* const key = a.HeapConstant(isolate->factory()->resolve_string()); 948 Node* const key = a.HeapConstant(isolate->factory()->resolve_string());
949 Node* const on_resolve = 949 Node* const on_resolve =
950 a.CallStub(getproperty_callable, context, deferred, key); 950 a.CallStub(getproperty_callable, context, deferred, key);
951 951
952 Label if_internalhandler(&a), if_customhandler(&a, Label::kDeferred); 952 Label if_internalhandler(&a), if_customhandler(&a, Label::kDeferred);
953 a.Branch(a.IsUndefined(on_resolve), &if_internalhandler, &if_customhandler); 953 a.Branch(a.IsUndefined(on_resolve), &if_internalhandler, &if_customhandler);
954 954
955 a.Bind(&if_internalhandler); 955 a.Bind(&if_internalhandler);
956 InternalResolvePromise(&a, context, promise, result, &debug_pop); 956 InternalResolvePromise(&a, context, deferred_promise, result, &debug_pop);
957 957
958 a.Bind(&if_customhandler); 958 a.Bind(&if_customhandler);
959 { 959 {
960 Node* const maybe_exception = a.CallJS(call_callable, context, on_resolve, 960 Node* const maybe_exception = a.CallJS(call_callable, context, on_resolve,
961 a.UndefinedConstant(), result); 961 a.UndefinedConstant(), result);
962 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason); 962 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason);
963 a.Goto(&debug_pop); 963 a.Goto(&debug_pop);
964 } 964 }
965 } 965 }
966 966
967 a.Bind(&if_rejectpromise); 967 a.Bind(&if_rejectpromise);
968 { 968 {
969 // TODO(gsathya): Remove this lookup by getting rid of the deferred object. 969 // TODO(gsathya): Remove this lookup by getting rid of the deferred object.
970 Node* const key = a.HeapConstant(isolate->factory()->reject_string()); 970 Node* const key = a.HeapConstant(isolate->factory()->reject_string());
971 Node* const on_reject = 971 Node* const on_reject =
972 a.CallStub(getproperty_callable, context, deferred, key); 972 a.CallStub(getproperty_callable, context, deferred, key);
973 973
974 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate); 974 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate);
975 a.CallStub(promise_handle_reject, context, promise, on_reject, 975 a.CallStub(promise_handle_reject, context, deferred_promise, on_reject,
976 var_reason.value()); 976 var_reason.value());
977 a.Goto(&debug_pop); 977 a.Goto(&debug_pop);
978 } 978 }
979 979
980 a.Bind(&debug_pop); 980 a.Bind(&debug_pop);
981 { 981 {
982 Label out(&a); 982 Label out(&a);
983 983
984 a.GotoUnless(is_debug_active, &out); 984 a.GotoUnless(is_debug_active, &out);
985 a.CallRuntime(Runtime::kDebugPopPromise, context); 985 a.CallRuntime(Runtime::kDebugPopPromise, context);
986 a.Goto(&out); 986 a.Goto(&out);
987 987
988 a.Bind(&out); 988 a.Bind(&out);
989 a.Return(a.UndefinedConstant()); 989 a.Return(a.UndefinedConstant());
990 } 990 }
991 } 991 }
992 992
993 } // namespace internal 993 } // namespace internal
994 } // namespace v8 994 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-stub-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698