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

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

Issue 2630593004: [promises] Remove runtime call from fastpath in PromiseReject (Closed)
Patch Set: add comment Created 3 years, 11 months 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-promise.h ('k') | src/contexts.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-promise.h" 5 #include "src/builtins/builtins-promise.h"
6 #include "src/builtins/builtins-constructor.h" 6 #include "src/builtins/builtins-constructor.h"
7 #include "src/builtins/builtins-utils.h" 7 #include "src/builtins/builtins-utils.h"
8 #include "src/builtins/builtins.h" 8 #include "src/builtins/builtins.h"
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/code-stub-assembler.h" 10 #include "src/code-stub-assembler.h"
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 Node* const has_handler = PromiseHasHandler(result); 741 Node* const has_handler = PromiseHasHandler(result);
742 742
743 // Promise has already been rejected, but had no handler. 743 // Promise has already been rejected, but had no handler.
744 // Revoke previously triggered reject event. 744 // Revoke previously triggered reject event.
745 GotoIf(has_handler, &reject); 745 GotoIf(has_handler, &reject);
746 CallRuntime(Runtime::kPromiseRevokeReject, context, result); 746 CallRuntime(Runtime::kPromiseRevokeReject, context, result);
747 Goto(&reject); 747 Goto(&reject);
748 748
749 Bind(&reject); 749 Bind(&reject);
750 // Don't cause a debug event as this case is forwarding a rejection 750 // Don't cause a debug event as this case is forwarding a rejection
751 CallRuntime(Runtime::kPromiseReject, context, promise, thenable_value, 751 InternalPromiseReject(context, promise, thenable_value,
752 FalseConstant()); 752 FalseConstant());
753 PromiseSetHasHandler(result); 753 PromiseSetHasHandler(result);
754 Goto(&out); 754 Goto(&out);
755 } 755 }
756 } 756 }
757 } 757 }
758 758
759 Bind(&if_notnativepromise); 759 Bind(&if_notnativepromise);
760 { 760 {
761 // 8. Let then be Get(resolution, "then"). 761 // 8. Let then be Get(resolution, "then").
762 Node* const then_str = HeapConstant(isolate->factory()->then_string()); 762 Node* const then_str = HeapConstant(isolate->factory()->then_string());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 CallRuntime(Runtime::kNewTypeError, context, message_id, result); 829 CallRuntime(Runtime::kNewTypeError, context, message_id, result);
830 var_reason.Bind(error); 830 var_reason.Bind(error);
831 831
832 // 6.b Return RejectPromise(promise, selfResolutionError). 832 // 6.b Return RejectPromise(promise, selfResolutionError).
833 Goto(&if_rejectpromise); 833 Goto(&if_rejectpromise);
834 } 834 }
835 835
836 // 9.a Return RejectPromise(promise, then.[[Value]]). 836 // 9.a Return RejectPromise(promise, then.[[Value]]).
837 Bind(&if_rejectpromise); 837 Bind(&if_rejectpromise);
838 { 838 {
839 CallRuntime(Runtime::kPromiseReject, context, promise, var_reason.value(), 839 InternalPromiseReject(context, promise, var_reason.value(), TrueConstant());
840 TrueConstant());
841 Goto(&out); 840 Goto(&out);
842 } 841 }
843 842
844 Bind(&out); 843 Bind(&out);
845 } 844 }
846 845
847 void PromiseBuiltinsAssembler::PromiseFulfill( 846 void PromiseBuiltinsAssembler::PromiseFulfill(
848 Node* context, Node* promise, Node* result, 847 Node* context, Node* promise, Node* result,
849 v8::Promise::PromiseState status) { 848 v8::Promise::PromiseState status) {
850 Label do_promisereset(this), debug_async_event_enqueue_recurring(this); 849 Label do_promisereset(this), debug_async_event_enqueue_recurring(this);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 { 935 {
937 Branch(WordEqual(CallRuntime(Runtime::kAllowDynamicFunction, context, 936 Branch(WordEqual(CallRuntime(Runtime::kAllowDynamicFunction, context,
938 promise_constructor), 937 promise_constructor),
939 BooleanConstant(true)), 938 BooleanConstant(true)),
940 &has_access, if_noaccess); 939 &has_access, if_noaccess);
941 } 940 }
942 941
943 Bind(&has_access); 942 Bind(&has_access);
944 } 943 }
945 944
945 // This duplicates a lot of logic from PromiseRejectEvent in
946 // runtime-promise.cc
947 void PromiseBuiltinsAssembler::InternalPromiseReject(Node* context,
948 Node* promise, Node* value,
949 Node* debug_event) {
950 Label fulfill(this), report_unhandledpromise(this), run_debughandler(this),
951 run_promise_hook(this, Label::kDeferred);
952 Branch(IsPromiseHookEnabled(), &run_promise_hook, &run_debughandler);
953
954 Bind(&run_promise_hook);
955 {
956 CallRuntime(Runtime::kPromiseHookResolve, context, promise);
957 Goto(&run_debughandler);
958 }
959
960 Bind(&run_debughandler);
961 {
962 GotoUnless(IsDebugActive(), &report_unhandledpromise);
963 GotoUnless(WordEqual(debug_event, TrueConstant()),
964 &report_unhandledpromise);
965 CallRuntime(Runtime::kDebugPromiseReject, context, promise, value);
966 Goto(&report_unhandledpromise);
967 }
968
969 Bind(&report_unhandledpromise);
970 {
971 GotoIf(PromiseHasHandler(promise), &fulfill);
972 CallRuntime(Runtime::kReportPromiseReject, context, promise, value);
973 Goto(&fulfill);
974 }
975
976 Bind(&fulfill);
977 PromiseFulfill(context, promise, value, v8::Promise::kRejected);
978 }
979
946 // ES#sec-promise-reject-functions 980 // ES#sec-promise-reject-functions
947 // Promise Reject Functions 981 // Promise Reject Functions
948 TF_BUILTIN(PromiseRejectClosure, PromiseBuiltinsAssembler) { 982 TF_BUILTIN(PromiseRejectClosure, PromiseBuiltinsAssembler) {
949 Node* const value = Parameter(1); 983 Node* const value = Parameter(1);
950 Node* const context = Parameter(4); 984 Node* const context = Parameter(4);
951 985
952 Label out(this); 986 Label out(this);
953 987
954 // 3. Let alreadyResolved be F.[[AlreadyResolved]]. 988 // 3. Let alreadyResolved be F.[[AlreadyResolved]].
955 int has_already_visited_slot = PromiseUtils::kAlreadyVisitedSlot; 989 int has_already_visited_slot = PromiseUtils::kAlreadyVisitedSlot;
956 990
957 Node* const has_already_visited = 991 Node* const has_already_visited =
958 LoadContextElement(context, has_already_visited_slot); 992 LoadContextElement(context, has_already_visited_slot);
959 993
960 // 4. If alreadyResolved.[[Value]] is true, return undefined. 994 // 4. If alreadyResolved.[[Value]] is true, return undefined.
961 GotoIf(SmiEqual(has_already_visited, SmiConstant(1)), &out); 995 GotoIf(SmiEqual(has_already_visited, SmiConstant(1)), &out);
962 996
963 // 5.Set alreadyResolved.[[Value]] to true. 997 // 5.Set alreadyResolved.[[Value]] to true.
964 StoreContextElementNoWriteBarrier(context, has_already_visited_slot, 998 StoreContextElementNoWriteBarrier(context, has_already_visited_slot,
965 SmiConstant(1)); 999 SmiConstant(1));
966 1000
967 // 2. Let promise be F.[[Promise]]. 1001 // 2. Let promise be F.[[Promise]].
968 Node* const promise = 1002 Node* const promise =
969 LoadContextElement(context, IntPtrConstant(PromiseUtils::kPromiseSlot)); 1003 LoadContextElement(context, IntPtrConstant(PromiseUtils::kPromiseSlot));
970 Node* const debug_event = LoadContextElement( 1004 Node* const debug_event = LoadContextElement(
971 context, IntPtrConstant(PromiseUtils::kDebugEventSlot)); 1005 context, IntPtrConstant(PromiseUtils::kDebugEventSlot));
972 1006
973 CallRuntime(Runtime::kPromiseReject, context, promise, value, debug_event); 1007 InternalPromiseReject(context, promise, value, debug_event);
Igor Sheludko 2017/01/16 11:43:18 This is the only case where debug_event value is r
gsathya 2017/01/17 06:33:18 There's another dynamic call in TF_BUILTIN(Interna
974 Return(UndefinedConstant()); 1008 Return(UndefinedConstant());
975 1009
976 Bind(&out); 1010 Bind(&out);
977 Return(UndefinedConstant()); 1011 Return(UndefinedConstant());
978 } 1012 }
979 1013
980 TF_BUILTIN(PromiseConstructor, PromiseBuiltinsAssembler) { 1014 TF_BUILTIN(PromiseConstructor, PromiseBuiltinsAssembler) {
981 Node* const executor = Parameter(1); 1015 Node* const executor = Parameter(1);
982 Node* const new_target = Parameter(2); 1016 Node* const new_target = Parameter(2);
983 Node* const context = Parameter(4); 1017 Node* const context = Parameter(4);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 Node* const context = Parameter(Descriptor::kContext); 1234 Node* const context = Parameter(Descriptor::kContext);
1201 1235
1202 Callable call_callable = CodeFactory::Call(isolate()); 1236 Callable call_callable = CodeFactory::Call(isolate());
1203 Variable var_unused(this, MachineRepresentation::kTagged); 1237 Variable var_unused(this, MachineRepresentation::kTagged);
1204 1238
1205 Label if_internalhandler(this), if_customhandler(this, Label::kDeferred); 1239 Label if_internalhandler(this), if_customhandler(this, Label::kDeferred);
1206 Branch(IsUndefined(on_reject), &if_internalhandler, &if_customhandler); 1240 Branch(IsUndefined(on_reject), &if_internalhandler, &if_customhandler);
1207 1241
1208 Bind(&if_internalhandler); 1242 Bind(&if_internalhandler);
1209 { 1243 {
1210 CallRuntime(Runtime::kPromiseReject, context, promise, exception, 1244 InternalPromiseReject(context, promise, exception, FalseConstant());
1211 FalseConstant());
1212 Return(UndefinedConstant()); 1245 Return(UndefinedConstant());
1213 } 1246 }
1214 1247
1215 Bind(&if_customhandler); 1248 Bind(&if_customhandler);
1216 { 1249 {
1217 CallJS(call_callable, context, on_reject, UndefinedConstant(), exception); 1250 CallJS(call_callable, context, on_reject, UndefinedConstant(), exception);
1218 Return(UndefinedConstant()); 1251 Return(UndefinedConstant());
1219 } 1252 }
1220 } 1253 }
1221 1254
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 Callable call_callable = CodeFactory::Call(isolate()); 1530 Callable call_callable = CodeFactory::Call(isolate());
1498 CallJS(call_callable, context, reject, UndefinedConstant(), reason); 1531 CallJS(call_callable, context, reject, UndefinedConstant(), reason);
1499 1532
1500 // 5. Return promiseCapability.[[Promise]]. 1533 // 5. Return promiseCapability.[[Promise]].
1501 Node* const promise = 1534 Node* const promise =
1502 LoadObjectField(capability, JSPromiseCapability::kPromiseOffset); 1535 LoadObjectField(capability, JSPromiseCapability::kPromiseOffset);
1503 Return(promise); 1536 Return(promise);
1504 } 1537 }
1505 } 1538 }
1506 1539
1540 TF_BUILTIN(InternalPromiseReject, PromiseBuiltinsAssembler) {
1541 Node* const promise = Parameter(1);
1542 Node* const reason = Parameter(2);
1543 Node* const debug_event = Parameter(3);
1544 Node* const context = Parameter(6);
1545
1546 InternalPromiseReject(context, promise, reason, debug_event);
1547 Return(UndefinedConstant());
1548 }
1549
1507 } // namespace internal 1550 } // namespace internal
1508 } // namespace v8 1551 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-promise.h ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698