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-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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 } | 562 } |
563 | 563 |
564 Bind(&fulfilled_check); | 564 Bind(&fulfilled_check); |
565 { | 565 { |
566 Label reject(this); | 566 Label reject(this); |
567 Node* const result = LoadObjectField(promise, JSPromise::kResultOffset); | 567 Node* const result = LoadObjectField(promise, JSPromise::kResultOffset); |
568 GotoUnless(WordEqual(status, SmiConstant(v8::Promise::kFulfilled)), | 568 GotoUnless(WordEqual(status, SmiConstant(v8::Promise::kFulfilled)), |
569 &reject); | 569 &reject); |
570 | 570 |
571 Node* info = AllocatePromiseReactionJobInfo( | 571 Node* info = AllocatePromiseReactionJobInfo( |
572 promise, result, var_on_resolve.value(), deferred_promise, | 572 result, var_on_resolve.value(), deferred_promise, deferred_on_resolve, |
573 deferred_on_resolve, deferred_on_reject, context); | 573 deferred_on_reject, context); |
574 // TODO(gsathya): Move this to TF | 574 // TODO(gsathya): Move this to TF |
575 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, | 575 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, promise, info, |
576 SmiConstant(v8::Promise::kFulfilled)); | 576 SmiConstant(v8::Promise::kFulfilled)); |
577 Goto(&out); | 577 Goto(&out); |
578 | 578 |
579 Bind(&reject); | 579 Bind(&reject); |
580 { | 580 { |
581 Node* const has_handler = PromiseHasHandler(promise); | 581 Node* const has_handler = PromiseHasHandler(promise); |
582 Label enqueue(this); | 582 Label enqueue(this); |
583 | 583 |
584 // TODO(gsathya): Fold these runtime calls and move to TF. | 584 // TODO(gsathya): Fold these runtime calls and move to TF. |
585 GotoIf(has_handler, &enqueue); | 585 GotoIf(has_handler, &enqueue); |
586 CallRuntime(Runtime::kPromiseRevokeReject, context, promise); | 586 CallRuntime(Runtime::kPromiseRevokeReject, context, promise); |
587 Goto(&enqueue); | 587 Goto(&enqueue); |
588 | 588 |
589 Bind(&enqueue); | 589 Bind(&enqueue); |
590 { | 590 { |
591 Node* info = AllocatePromiseReactionJobInfo( | 591 Node* info = AllocatePromiseReactionJobInfo( |
592 promise, result, var_on_reject.value(), deferred_promise, | 592 result, var_on_reject.value(), deferred_promise, |
593 deferred_on_resolve, deferred_on_reject, context); | 593 deferred_on_resolve, deferred_on_reject, context); |
594 // TODO(gsathya): Move this to TF | 594 // TODO(gsathya): Move this to TF |
595 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, | 595 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, promise, |
596 SmiConstant(v8::Promise::kRejected)); | 596 info, SmiConstant(v8::Promise::kRejected)); |
597 Goto(&out); | 597 Goto(&out); |
598 } | 598 } |
599 } | 599 } |
600 } | 600 } |
601 } | 601 } |
602 | 602 |
603 Bind(&out); | 603 Bind(&out); |
604 PromiseSetHasHandler(promise); | 604 PromiseSetHasHandler(promise); |
605 return deferred_promise; | 605 return deferred_promise; |
606 } | 606 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 status == v8::Promise::kFulfilled | 866 status == v8::Promise::kFulfilled |
867 ? LoadObjectField(promise, JSPromise::kFulfillReactionsOffset) | 867 ? LoadObjectField(promise, JSPromise::kFulfillReactionsOffset) |
868 : LoadObjectField(promise, JSPromise::kRejectReactionsOffset); | 868 : LoadObjectField(promise, JSPromise::kRejectReactionsOffset); |
869 | 869 |
870 Node* const deferred_on_resolve = | 870 Node* const deferred_on_resolve = |
871 LoadObjectField(promise, JSPromise::kDeferredOnResolveOffset); | 871 LoadObjectField(promise, JSPromise::kDeferredOnResolveOffset); |
872 Node* const deferred_on_reject = | 872 Node* const deferred_on_reject = |
873 LoadObjectField(promise, JSPromise::kDeferredOnRejectOffset); | 873 LoadObjectField(promise, JSPromise::kDeferredOnRejectOffset); |
874 | 874 |
875 Node* const info = AllocatePromiseReactionJobInfo( | 875 Node* const info = AllocatePromiseReactionJobInfo( |
876 promise, result, tasks, deferred_promise, deferred_on_resolve, | 876 result, tasks, deferred_promise, deferred_on_resolve, deferred_on_reject, |
877 deferred_on_reject, context); | 877 context); |
878 | 878 |
879 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, status_smi); | 879 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, promise, info, |
| 880 status_smi); |
880 Goto(&debug_async_event_enqueue_recurring); | 881 Goto(&debug_async_event_enqueue_recurring); |
881 | 882 |
882 Bind(&debug_async_event_enqueue_recurring); | 883 Bind(&debug_async_event_enqueue_recurring); |
883 { | 884 { |
884 GotoUnless(IsDebugActive(), &do_promisereset); | 885 GotoUnless(IsDebugActive(), &do_promisereset); |
885 CallRuntime(Runtime::kDebugAsyncEventEnqueueRecurring, context, promise, | 886 CallRuntime(Runtime::kDebugAsyncEventEnqueueRecurring, context, promise, |
886 status_smi); | 887 status_smi); |
887 Goto(&do_promisereset); | 888 Goto(&do_promisereset); |
888 } | 889 } |
889 | 890 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 } | 1163 } |
1163 | 1164 |
1164 Bind(&if_customhandler); | 1165 Bind(&if_customhandler); |
1165 { | 1166 { |
1166 CallJS(call_callable, context, on_reject, UndefinedConstant(), exception); | 1167 CallJS(call_callable, context, on_reject, UndefinedConstant(), exception); |
1167 Return(UndefinedConstant()); | 1168 Return(UndefinedConstant()); |
1168 } | 1169 } |
1169 } | 1170 } |
1170 | 1171 |
1171 TF_BUILTIN(PromiseHandle, PromiseBuiltinsAssembler) { | 1172 TF_BUILTIN(PromiseHandle, PromiseBuiltinsAssembler) { |
1172 Node* const promise = Parameter(1); | 1173 Node* const value = Parameter(1); |
1173 Node* const value = Parameter(2); | 1174 Node* const handler = Parameter(2); |
1174 Node* const handler = Parameter(3); | 1175 Node* const deferred_promise = Parameter(3); |
1175 Node* const deferred_promise = Parameter(4); | 1176 Node* const deferred_on_resolve = Parameter(4); |
1176 Node* const deferred_on_resolve = Parameter(5); | 1177 Node* const deferred_on_reject = Parameter(5); |
1177 Node* const deferred_on_reject = Parameter(6); | 1178 Node* const context = Parameter(8); |
1178 Node* const context = Parameter(9); | |
1179 Isolate* isolate = this->isolate(); | 1179 Isolate* isolate = this->isolate(); |
1180 | 1180 |
1181 Variable var_reason(this, MachineRepresentation::kTagged); | 1181 Variable var_reason(this, MachineRepresentation::kTagged); |
1182 | 1182 |
1183 Node* const is_debug_active = IsDebugActive(); | 1183 Node* const is_debug_active = IsDebugActive(); |
1184 Label run_handler(this), if_rejectpromise(this), promisehook_before(this), | 1184 Label run_handler(this), if_rejectpromise(this), promisehook_before(this), |
1185 promisehook_after(this), debug_pop(this); | 1185 promisehook_after(this), debug_pop(this); |
1186 | 1186 |
1187 GotoUnless(is_debug_active, &promisehook_before); | 1187 GotoUnless(is_debug_active, &promisehook_before); |
1188 CallRuntime(Runtime::kDebugPushPromise, context, deferred_promise); | 1188 CallRuntime(Runtime::kDebugPushPromise, context, deferred_promise); |
1189 Goto(&promisehook_before); | 1189 Goto(&promisehook_before); |
1190 | 1190 |
1191 Bind(&promisehook_before); | 1191 Bind(&promisehook_before); |
1192 { | 1192 { |
1193 GotoUnless(IsPromiseHookEnabled(), &run_handler); | 1193 GotoUnless(IsPromiseHookEnabled(), &run_handler); |
1194 CallRuntime(Runtime::kPromiseHookBefore, context, promise); | 1194 CallRuntime(Runtime::kPromiseHookBefore, context, deferred_promise); |
1195 Goto(&run_handler); | 1195 Goto(&run_handler); |
1196 } | 1196 } |
1197 | 1197 |
1198 Bind(&run_handler); | 1198 Bind(&run_handler); |
1199 { | 1199 { |
1200 Callable call_callable = CodeFactory::Call(isolate); | 1200 Callable call_callable = CodeFactory::Call(isolate); |
1201 Node* const result = | 1201 Node* const result = |
1202 CallJS(call_callable, context, handler, UndefinedConstant(), value); | 1202 CallJS(call_callable, context, handler, UndefinedConstant(), value); |
1203 | 1203 |
1204 GotoIfException(result, &if_rejectpromise, &var_reason); | 1204 GotoIfException(result, &if_rejectpromise, &var_reason); |
(...skipping 20 matching lines...) Expand all Loading... |
1225 { | 1225 { |
1226 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate); | 1226 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate); |
1227 CallStub(promise_handle_reject, context, deferred_promise, | 1227 CallStub(promise_handle_reject, context, deferred_promise, |
1228 deferred_on_reject, var_reason.value()); | 1228 deferred_on_reject, var_reason.value()); |
1229 Goto(&promisehook_after); | 1229 Goto(&promisehook_after); |
1230 } | 1230 } |
1231 | 1231 |
1232 Bind(&promisehook_after); | 1232 Bind(&promisehook_after); |
1233 { | 1233 { |
1234 GotoUnless(IsPromiseHookEnabled(), &debug_pop); | 1234 GotoUnless(IsPromiseHookEnabled(), &debug_pop); |
1235 CallRuntime(Runtime::kPromiseHookAfter, context, promise); | 1235 CallRuntime(Runtime::kPromiseHookAfter, context, deferred_promise); |
1236 Goto(&debug_pop); | 1236 Goto(&debug_pop); |
1237 } | 1237 } |
1238 | 1238 |
1239 Bind(&debug_pop); | 1239 Bind(&debug_pop); |
1240 { | 1240 { |
1241 Label out(this); | 1241 Label out(this); |
1242 | 1242 |
1243 GotoUnless(is_debug_active, &out); | 1243 GotoUnless(is_debug_active, &out); |
1244 CallRuntime(Runtime::kDebugPopPromise, context); | 1244 CallRuntime(Runtime::kDebugPopPromise, context); |
1245 Goto(&out); | 1245 Goto(&out); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 | 1449 |
1450 // 5. Return promiseCapability.[[Promise]]. | 1450 // 5. Return promiseCapability.[[Promise]]. |
1451 Node* const promise = | 1451 Node* const promise = |
1452 LoadObjectField(capability, JSPromiseCapability::kPromiseOffset); | 1452 LoadObjectField(capability, JSPromiseCapability::kPromiseOffset); |
1453 Return(promise); | 1453 Return(promise); |
1454 } | 1454 } |
1455 } | 1455 } |
1456 | 1456 |
1457 } // namespace internal | 1457 } // namespace internal |
1458 } // namespace v8 | 1458 } // namespace v8 |
OLD | NEW |