 Chromium Code Reviews
 Chromium Code Reviews Issue 2614603003:
  [promises] Move PromiseFulfill to TF  (Closed)
    
  
    Issue 2614603003:
  [promises] Move PromiseFulfill to TF  (Closed) 
  | 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 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 Goto(&do_enqueue); | 636 Goto(&do_enqueue); | 
| 637 | 637 | 
| 638 Bind(&if_isnotpending); | 638 Bind(&if_isnotpending); | 
| 639 { | 639 { | 
| 640 Label if_fulfilled(this), if_rejected(this); | 640 Label if_fulfilled(this), if_rejected(this); | 
| 641 Branch(SmiEqual(SmiConstant(v8::Promise::kFulfilled), thenable_status), | 641 Branch(SmiEqual(SmiConstant(v8::Promise::kFulfilled), thenable_status), | 
| 642 &if_fulfilled, &if_rejected); | 642 &if_fulfilled, &if_rejected); | 
| 643 | 643 | 
| 644 Bind(&if_fulfilled); | 644 Bind(&if_fulfilled); | 
| 645 { | 645 { | 
| 646 CallRuntime(Runtime::kPromiseFulfill, context, promise, | 646 PromiseFulfill(context, promise, thenable_value, | 
| 647 SmiConstant(v8::Promise::kFulfilled), thenable_value); | 647 v8::Promise::kFulfilled); | 
| 648 PromiseSetHasHandler(promise); | 648 PromiseSetHasHandler(promise); | 
| 649 Goto(&out); | 649 Goto(&out); | 
| 650 } | 650 } | 
| 651 | 651 | 
| 652 Bind(&if_rejected); | 652 Bind(&if_rejected); | 
| 653 { | 653 { | 
| 654 Label reject(this); | 654 Label reject(this); | 
| 655 Node* const has_handler = PromiseHasHandler(result); | 655 Node* const has_handler = PromiseHasHandler(result); | 
| 656 | 656 | 
| 657 // Promise has already been rejected, but had no handler. | 657 // Promise has already been rejected, but had no handler. | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 Bind(&enqueue); | 708 Bind(&enqueue); | 
| 709 // TODO(gsathya): Move this to TF | 709 // TODO(gsathya): Move this to TF | 
| 710 CallRuntime(Runtime::kEnqueuePromiseResolveThenableJob, context, promise, | 710 CallRuntime(Runtime::kEnqueuePromiseResolveThenableJob, context, promise, | 
| 711 result, var_then.value()); | 711 result, var_then.value()); | 
| 712 Goto(&out); | 712 Goto(&out); | 
| 713 } | 713 } | 
| 714 | 714 | 
| 715 // 7.b Return FulfillPromise(promise, resolution). | 715 // 7.b Return FulfillPromise(promise, resolution). | 
| 716 Bind(&fulfill); | 716 Bind(&fulfill); | 
| 717 { | 717 { | 
| 718 CallRuntime(Runtime::kPromiseFulfill, context, promise, | 718 PromiseFulfill(context, promise, result, v8::Promise::kFulfilled); | 
| 719 SmiConstant(v8::Promise::kFulfilled), result); | |
| 720 Goto(&out); | 719 Goto(&out); | 
| 721 } | 720 } | 
| 722 | 721 | 
| 723 Bind(&if_cycle); | 722 Bind(&if_cycle); | 
| 724 { | 723 { | 
| 725 // 6.a Let selfResolutionError be a newly created TypeError object. | 724 // 6.a Let selfResolutionError be a newly created TypeError object. | 
| 726 Node* const message_id = SmiConstant(MessageTemplate::kPromiseCyclic); | 725 Node* const message_id = SmiConstant(MessageTemplate::kPromiseCyclic); | 
| 727 Node* const error = | 726 Node* const error = | 
| 728 CallRuntime(Runtime::kNewTypeError, context, message_id, result); | 727 CallRuntime(Runtime::kNewTypeError, context, message_id, result); | 
| 729 var_reason.Bind(error); | 728 var_reason.Bind(error); | 
| 730 | 729 | 
| 731 // 6.b Return RejectPromise(promise, selfResolutionError). | 730 // 6.b Return RejectPromise(promise, selfResolutionError). | 
| 732 Goto(&if_rejectpromise); | 731 Goto(&if_rejectpromise); | 
| 733 } | 732 } | 
| 734 | 733 | 
| 735 // 9.a Return RejectPromise(promise, then.[[Value]]). | 734 // 9.a Return RejectPromise(promise, then.[[Value]]). | 
| 736 Bind(&if_rejectpromise); | 735 Bind(&if_rejectpromise); | 
| 737 { | 736 { | 
| 738 CallRuntime(Runtime::kPromiseReject, context, promise, var_reason.value(), | 737 CallRuntime(Runtime::kPromiseReject, context, promise, var_reason.value(), | 
| 739 TrueConstant()); | 738 TrueConstant()); | 
| 740 Goto(&out); | 739 Goto(&out); | 
| 741 } | 740 } | 
| 742 | 741 | 
| 743 Bind(&out); | 742 Bind(&out); | 
| 744 } | 743 } | 
| 745 | 744 | 
| 745 void PromiseBuiltinsAssembler::PromiseFulfill( | |
| 746 Node* context, Node* promise, Node* result, | |
| 747 v8::Promise::PromiseState status) { | |
| 748 Label do_promisereset(this); | |
| 749 | |
| 750 Node* const status_smi = SmiConstant(static_cast<int>(status)); | |
| 751 Node* const deferred_promise = | |
| 752 LoadObjectField(promise, JSPromise::kDeferredPromiseOffset); | |
| 753 | |
| 754 GotoIf(IsUndefined(deferred_promise), &do_promisereset); | |
| 755 | |
| 756 Node* const tasks = SelectConstant( | |
| 
Igor Sheludko
2017/01/04 08:39:32
Please use Select() here otherwise both Fulfill an
 
gsathya
2017/01/04 19:51:01
Done.
 | |
| 757 SmiEqual(status_smi, SmiConstant(v8::Promise::kFulfilled)), | |
| 
Igor Sheludko
2017/01/04 08:39:32
BTW, this check looks like a compile-time one.
 
gsathya
2017/01/04 19:51:01
Done.
 | |
| 758 LoadObjectField(promise, JSPromise::kFulfillReactionsOffset), | |
| 759 LoadObjectField(promise, JSPromise::kRejectReactionsOffset), | |
| 760 MachineRepresentation::kTaggedPointer); | |
| 761 Node* const deferred_on_resolve = | |
| 762 LoadObjectField(promise, JSPromise::kDeferredOnResolveOffset); | |
| 763 Node* const deferred_on_reject = | |
| 764 LoadObjectField(promise, JSPromise::kDeferredOnRejectOffset); | |
| 765 | |
| 766 Node* const info = AllocatePromiseReactionJobInfo( | |
| 767 promise, result, tasks, deferred_promise, deferred_on_resolve, | |
| 768 deferred_on_reject, context); | |
| 769 CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, status_smi); | |
| 770 Goto(&do_promisereset); | |
| 771 | |
| 772 Bind(&do_promisereset); | |
| 773 { | |
| 774 StoreObjectField(promise, JSPromise::kStatusOffset, status_smi); | |
| 775 StoreObjectField(promise, JSPromise::kResultOffset, result); | |
| 776 StoreObjectFieldRoot(promise, JSPromise::kDeferredPromiseOffset, | |
| 777 Heap::kUndefinedValueRootIndex); | |
| 778 StoreObjectFieldRoot(promise, JSPromise::kDeferredOnResolveOffset, | |
| 779 Heap::kUndefinedValueRootIndex); | |
| 780 StoreObjectFieldRoot(promise, JSPromise::kDeferredOnRejectOffset, | |
| 781 Heap::kUndefinedValueRootIndex); | |
| 782 StoreObjectFieldRoot(promise, JSPromise::kFulfillReactionsOffset, | |
| 783 Heap::kUndefinedValueRootIndex); | |
| 784 StoreObjectFieldRoot(promise, JSPromise::kRejectReactionsOffset, | |
| 785 Heap::kUndefinedValueRootIndex); | |
| 786 } | |
| 787 } | |
| 788 | |
| 746 // ES#sec-promise-reject-functions | 789 // ES#sec-promise-reject-functions | 
| 747 // Promise Reject Functions | 790 // Promise Reject Functions | 
| 748 BUILTIN(PromiseRejectClosure) { | 791 BUILTIN(PromiseRejectClosure) { | 
| 749 HandleScope scope(isolate); | 792 HandleScope scope(isolate); | 
| 750 | 793 | 
| 751 Handle<Context> context(isolate->context(), isolate); | 794 Handle<Context> context(isolate->context(), isolate); | 
| 752 | 795 | 
| 753 if (PromiseUtils::HasAlreadyVisited(context)) { | 796 if (PromiseUtils::HasAlreadyVisited(context)) { | 
| 754 return isolate->heap()->undefined_value(); | 797 return isolate->heap()->undefined_value(); | 
| 755 } | 798 } | 
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 Node* debug_event = Parameter(2); | 1211 Node* debug_event = Parameter(2); | 
| 1169 Node* context = Parameter(5); | 1212 Node* context = Parameter(5); | 
| 1170 | 1213 | 
| 1171 CSA_ASSERT_JS_ARGC_EQ(this, 2); | 1214 CSA_ASSERT_JS_ARGC_EQ(this, 2); | 
| 1172 | 1215 | 
| 1173 Return(NewPromiseCapability(context, constructor, debug_event)); | 1216 Return(NewPromiseCapability(context, constructor, debug_event)); | 
| 1174 } | 1217 } | 
| 1175 | 1218 | 
| 1176 } // namespace internal | 1219 } // namespace internal | 
| 1177 } // namespace v8 | 1220 } // namespace v8 | 
| OLD | NEW |