OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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-gen.h" | 5 #include "src/builtins/builtins-utils-gen.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 Unreachable(); | 122 Unreachable(); |
123 Bind(&ok); | 123 Bind(&ok); |
124 } | 124 } |
125 | 125 |
126 Node* FilterResultGenerator() { | 126 Node* FilterResultGenerator() { |
127 // 7. Let A be ArraySpeciesCreate(O, 0). | 127 // 7. Let A be ArraySpeciesCreate(O, 0). |
128 return ArraySpeciesCreate(context(), o(), SmiConstant(0)); | 128 return ArraySpeciesCreate(context(), o(), SmiConstant(0)); |
129 } | 129 } |
130 | 130 |
131 Node* FilterProcessor(Node* k_value, Node* k) { | 131 Node* FilterProcessor(Node* k_value, Node* k) { |
132 Node* callback_result = CallJS(CodeFactory::Call(isolate()), context(), | 132 // ii. Let selected be ToBoolean(? Call(callbackfn, T, kValue, k, O)). |
133 callbackfn(), this_arg(), k_value, k, o()); | 133 Node* selected = CallJS(CodeFactory::Call(isolate()), context(), |
| 134 callbackfn(), this_arg(), k_value, k, o()); |
134 Label true_continue(this, &to_), false_continue(this); | 135 Label true_continue(this, &to_), false_continue(this); |
135 BranchIfToBooleanIsTrue(callback_result, &true_continue, &false_continue); | 136 BranchIfToBooleanIsTrue(selected, &true_continue, &false_continue); |
136 Bind(&true_continue); | 137 Bind(&true_continue); |
| 138 // iii. If selected is true, then... |
| 139 { |
| 140 // 1. Perform ? CreateDataPropertyOrThrow(A, ToString(to), kValue). |
| 141 CallRuntime(Runtime::kCreateDataProperty, context(), a(), to_.value(), |
| 142 k_value); |
137 | 143 |
138 // 1. let status be CreateDataPropertyOrThrow(A, ToString(to), kValue). | 144 // 2. Increase to by 1. |
139 // 2. ReturnIfAbrupt(status) | 145 to_.Bind(NumberInc(to_.value())); |
140 Node* const p_to = ToString(context(), to_.value()); | 146 Goto(&false_continue); |
141 CallRuntime(Runtime::kCreateDataProperty, context(), a(), p_to, k_value); | 147 } |
| 148 Bind(&false_continue); |
| 149 return a(); |
| 150 } |
142 | 151 |
143 // 3. Increase to by 1. | 152 Node* MapResultGenerator() { |
144 to_.Bind(NumberInc(to_.value())); | 153 // 5. Let A be ? ArraySpeciesCreate(O, len). |
145 Goto(&false_continue); | 154 return ArraySpeciesCreate(context(), o(), len_); |
146 Bind(&false_continue); | 155 } |
| 156 |
| 157 Node* MapProcessor(Node* k_value, Node* k) { |
| 158 // i. Let kValue be ? Get(O, Pk). Performed by the caller of MapProcessor. |
| 159 // ii. Let mappedValue be ? Call(callbackfn, T, kValue, k, O). |
| 160 Node* mappedValue = CallJS(CodeFactory::Call(isolate()), context(), |
| 161 callbackfn(), this_arg(), k_value, k, o()); |
| 162 |
| 163 // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). |
| 164 CallRuntime(Runtime::kCreateDataProperty, context(), a(), k, mappedValue); |
147 return a(); | 165 return a(); |
148 } | 166 } |
149 | 167 |
150 void NullPostLoopAction() {} | 168 void NullPostLoopAction() {} |
151 | 169 |
152 protected: | 170 protected: |
153 Node* context() { return context_; } | 171 Node* context() { return context_; } |
154 Node* receiver() { return receiver_; } | 172 Node* receiver() { return receiver_; } |
155 Node* new_target() { return new_target_; } | 173 Node* new_target() { return new_target_; } |
156 Node* o() { return o_; } | 174 Node* o() { return o_; } |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 Node* context = Parameter(Descriptor::kContext); | 781 Node* context = Parameter(Descriptor::kContext); |
764 Node* receiver = Parameter(Descriptor::kReceiver); | 782 Node* receiver = Parameter(Descriptor::kReceiver); |
765 Node* callbackfn = Parameter(Descriptor::kCallbackFn); | 783 Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
766 Node* this_arg = Parameter(Descriptor::kThisArg); | 784 Node* this_arg = Parameter(Descriptor::kThisArg); |
767 Node* new_target = Parameter(Descriptor::kNewTarget); | 785 Node* new_target = Parameter(Descriptor::kNewTarget); |
768 | 786 |
769 InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, | 787 InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
770 new_target); | 788 new_target); |
771 | 789 |
772 GenerateIteratingArrayBuiltinBody( | 790 GenerateIteratingArrayBuiltinBody( |
773 "Array.prototype.reduce", | 791 "Array.prototype.filter", |
774 &ArrayBuiltinCodeStubAssembler::FilterResultGenerator, | 792 &ArrayBuiltinCodeStubAssembler::FilterResultGenerator, |
775 &ArrayBuiltinCodeStubAssembler::FilterProcessor, | 793 &ArrayBuiltinCodeStubAssembler::FilterProcessor, |
776 &ArrayBuiltinCodeStubAssembler::NullPostLoopAction, | 794 &ArrayBuiltinCodeStubAssembler::NullPostLoopAction, |
777 CodeFactory::ArrayFilterLoopContinuation(isolate())); | 795 CodeFactory::ArrayFilterLoopContinuation(isolate())); |
778 } | 796 } |
779 | 797 |
| 798 TF_BUILTIN(ArrayMapLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
| 799 Node* context = Parameter(Descriptor::kContext); |
| 800 Node* receiver = Parameter(Descriptor::kReceiver); |
| 801 Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
| 802 Node* this_arg = Parameter(Descriptor::kThisArg); |
| 803 Node* array = Parameter(Descriptor::kArray); |
| 804 Node* object = Parameter(Descriptor::kObject); |
| 805 Node* initial_k = Parameter(Descriptor::kInitialK); |
| 806 Node* len = Parameter(Descriptor::kLength); |
| 807 Node* to = Parameter(Descriptor::kTo); |
| 808 |
| 809 InitIteratingArrayBuiltinLoopContinuation(context, receiver, callbackfn, |
| 810 this_arg, array, object, initial_k, |
| 811 len, to); |
| 812 |
| 813 GenerateIteratingArrayBuiltinLoopContinuation( |
| 814 &ArrayBuiltinCodeStubAssembler::MapProcessor, |
| 815 &ArrayBuiltinCodeStubAssembler::NullPostLoopAction); |
| 816 } |
| 817 |
| 818 TF_BUILTIN(ArrayMap, ArrayBuiltinCodeStubAssembler) { |
| 819 Node* context = Parameter(Descriptor::kContext); |
| 820 Node* receiver = Parameter(Descriptor::kReceiver); |
| 821 Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
| 822 Node* this_arg = Parameter(Descriptor::kThisArg); |
| 823 Node* new_target = Parameter(Descriptor::kNewTarget); |
| 824 |
| 825 InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
| 826 new_target); |
| 827 |
| 828 GenerateIteratingArrayBuiltinBody( |
| 829 "Array.prototype.map", &ArrayBuiltinCodeStubAssembler::MapResultGenerator, |
| 830 &ArrayBuiltinCodeStubAssembler::MapProcessor, |
| 831 &ArrayBuiltinCodeStubAssembler::NullPostLoopAction, |
| 832 CodeFactory::ArrayMapLoopContinuation(isolate())); |
| 833 } |
| 834 |
780 TF_BUILTIN(ArrayIsArray, CodeStubAssembler) { | 835 TF_BUILTIN(ArrayIsArray, CodeStubAssembler) { |
781 Node* object = Parameter(Descriptor::kArg); | 836 Node* object = Parameter(Descriptor::kArg); |
782 Node* context = Parameter(Descriptor::kContext); | 837 Node* context = Parameter(Descriptor::kContext); |
783 | 838 |
784 Label call_runtime(this), return_true(this), return_false(this); | 839 Label call_runtime(this), return_true(this), return_false(this); |
785 | 840 |
786 GotoIf(TaggedIsSmi(object), &return_false); | 841 GotoIf(TaggedIsSmi(object), &return_false); |
787 Node* instance_type = LoadInstanceType(object); | 842 Node* instance_type = LoadInstanceType(object); |
788 | 843 |
789 GotoIf(Word32Equal(instance_type, Int32Constant(JS_ARRAY_TYPE)), | 844 GotoIf(Word32Equal(instance_type, Int32Constant(JS_ARRAY_TYPE)), |
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 { | 1886 { |
1832 Node* message = SmiConstant(MessageTemplate::kDetachedOperation); | 1887 Node* message = SmiConstant(MessageTemplate::kDetachedOperation); |
1833 CallRuntime(Runtime::kThrowTypeError, context, message, | 1888 CallRuntime(Runtime::kThrowTypeError, context, message, |
1834 HeapConstant(operation)); | 1889 HeapConstant(operation)); |
1835 Unreachable(); | 1890 Unreachable(); |
1836 } | 1891 } |
1837 } | 1892 } |
1838 | 1893 |
1839 } // namespace internal | 1894 } // namespace internal |
1840 } // namespace v8 | 1895 } // namespace v8 |
OLD | NEW |