Chromium Code Reviews| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 SmiConstant(MessageTemplate::kReduceNoInitial)); | 121 SmiConstant(MessageTemplate::kReduceNoInitial)); |
| 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* MapResultGenerator() { | |
| 132 // 7. Let A be ArraySpeciesCreate(O, 0). | |
| 133 return ArraySpeciesCreate(context(), o(), len_); | |
| 134 } | |
| 135 | |
|
danno
2017/03/23 12:25:04
Nit: Elsewhere we group the *Generator/*Filters to
mvstanton
2017/03/24 09:37:08
Done.
| |
| 131 Node* FilterProcessor(Node* k_value, Node* k) { | 136 Node* FilterProcessor(Node* k_value, Node* k) { |
| 132 Node* callback_result = CallJS(CodeFactory::Call(isolate()), context(), | 137 Node* callback_result = CallJS(CodeFactory::Call(isolate()), context(), |
| 133 callbackfn(), this_arg(), k_value, k, o()); | 138 callbackfn(), this_arg(), k_value, k, o()); |
| 134 Label true_continue(this, &to_), false_continue(this); | 139 Label true_continue(this, &to_), false_continue(this); |
| 135 BranchIfToBooleanIsTrue(callback_result, &true_continue, &false_continue); | 140 BranchIfToBooleanIsTrue(callback_result, &true_continue, &false_continue); |
| 136 Bind(&true_continue); | 141 Bind(&true_continue); |
| 137 | 142 |
| 138 // 1. let status be CreateDataPropertyOrThrow(A, ToString(to), kValue). | 143 // 1. let status be CreateDataPropertyOrThrow(A, ToString(to), kValue). |
| 139 // 2. ReturnIfAbrupt(status) | 144 // 2. ReturnIfAbrupt(status) |
| 140 Node* const p_to = ToString(context(), to_.value()); | 145 Node* const p_to = ToString(context(), to_.value()); |
| 141 CallRuntime(Runtime::kCreateDataProperty, context(), a(), p_to, k_value); | 146 CallRuntime(Runtime::kCreateDataProperty, context(), a(), p_to, k_value); |
| 142 | 147 |
| 143 // 3. Increase to by 1. | 148 // 3. Increase to by 1. |
| 144 to_.Bind(NumberInc(to_.value())); | 149 to_.Bind(NumberInc(to_.value())); |
| 145 Goto(&false_continue); | 150 Goto(&false_continue); |
| 146 Bind(&false_continue); | 151 Bind(&false_continue); |
| 147 return a(); | 152 return a(); |
| 148 } | 153 } |
| 149 | 154 |
| 155 Node* MapProcessor(Node* k_value, Node* k) { | |
| 156 Node* callback_result = CallJS(CodeFactory::Call(isolate()), context(), | |
| 157 callbackfn(), this_arg(), k_value, k, o()); | |
| 158 // TODO(mvstanton): in some cases we have the ToString version of k, | |
| 159 // in the continuation. | |
| 160 Node* const p_k = ToString(context(), k); | |
|
danno
2017/03/23 12:25:04
I wonder if you really need the ToString here, bec
mvstanton
2017/03/24 09:37:08
Done. This prompted some comment cleanup, to annot
| |
| 161 CallRuntime(Runtime::kCreateDataProperty, context(), a(), p_k, | |
| 162 callback_result); | |
| 163 return a(); | |
| 164 } | |
| 165 | |
| 150 void NullPostLoopAction() {} | 166 void NullPostLoopAction() {} |
| 151 | 167 |
| 152 protected: | 168 protected: |
| 153 Node* context() { return context_; } | 169 Node* context() { return context_; } |
| 154 Node* receiver() { return receiver_; } | 170 Node* receiver() { return receiver_; } |
| 155 Node* new_target() { return new_target_; } | 171 Node* new_target() { return new_target_; } |
| 156 Node* o() { return o_; } | 172 Node* o() { return o_; } |
| 157 Node* len() { return len_; } | 173 Node* len() { return len_; } |
| 158 Node* callbackfn() { return callbackfn_; } | 174 Node* callbackfn() { return callbackfn_; } |
| 159 Node* this_arg() { return this_arg_; } | 175 Node* this_arg() { return this_arg_; } |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 Node* context = Parameter(Descriptor::kContext); | 779 Node* context = Parameter(Descriptor::kContext); |
| 764 Node* receiver = Parameter(Descriptor::kReceiver); | 780 Node* receiver = Parameter(Descriptor::kReceiver); |
| 765 Node* callbackfn = Parameter(Descriptor::kCallbackFn); | 781 Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
| 766 Node* this_arg = Parameter(Descriptor::kThisArg); | 782 Node* this_arg = Parameter(Descriptor::kThisArg); |
| 767 Node* new_target = Parameter(Descriptor::kNewTarget); | 783 Node* new_target = Parameter(Descriptor::kNewTarget); |
| 768 | 784 |
| 769 InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, | 785 InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
| 770 new_target); | 786 new_target); |
| 771 | 787 |
| 772 GenerateIteratingArrayBuiltinBody( | 788 GenerateIteratingArrayBuiltinBody( |
| 773 "Array.prototype.reduce", | 789 "Array.prototype.filter", |
| 774 &ArrayBuiltinCodeStubAssembler::FilterResultGenerator, | 790 &ArrayBuiltinCodeStubAssembler::FilterResultGenerator, |
| 775 &ArrayBuiltinCodeStubAssembler::FilterProcessor, | 791 &ArrayBuiltinCodeStubAssembler::FilterProcessor, |
| 776 &ArrayBuiltinCodeStubAssembler::NullPostLoopAction, | 792 &ArrayBuiltinCodeStubAssembler::NullPostLoopAction, |
| 777 CodeFactory::ArrayFilterLoopContinuation(isolate())); | 793 CodeFactory::ArrayFilterLoopContinuation(isolate())); |
| 778 } | 794 } |
| 779 | 795 |
| 796 TF_BUILTIN(ArrayMapLoopContinuation, ArrayBuiltinCodeStubAssembler) { | |
| 797 Node* context = Parameter(Descriptor::kContext); | |
| 798 Node* receiver = Parameter(Descriptor::kReceiver); | |
| 799 Node* callbackfn = Parameter(Descriptor::kCallbackFn); | |
| 800 Node* this_arg = Parameter(Descriptor::kThisArg); | |
| 801 Node* array = Parameter(Descriptor::kArray); | |
| 802 Node* object = Parameter(Descriptor::kObject); | |
| 803 Node* initial_k = Parameter(Descriptor::kInitialK); | |
| 804 Node* len = Parameter(Descriptor::kLength); | |
| 805 Node* to = Parameter(Descriptor::kTo); | |
| 806 | |
| 807 InitIteratingArrayBuiltinLoopContinuation(context, receiver, callbackfn, | |
| 808 this_arg, array, object, initial_k, | |
| 809 len, to); | |
| 810 | |
| 811 GenerateIteratingArrayBuiltinLoopContinuation( | |
| 812 &ArrayBuiltinCodeStubAssembler::MapProcessor, | |
| 813 &ArrayBuiltinCodeStubAssembler::NullPostLoopAction); | |
| 814 } | |
| 815 | |
| 816 TF_BUILTIN(ArrayMap, ArrayBuiltinCodeStubAssembler) { | |
| 817 Node* context = Parameter(Descriptor::kContext); | |
| 818 Node* receiver = Parameter(Descriptor::kReceiver); | |
| 819 Node* callbackfn = Parameter(Descriptor::kCallbackFn); | |
| 820 Node* this_arg = Parameter(Descriptor::kThisArg); | |
| 821 Node* new_target = Parameter(Descriptor::kNewTarget); | |
| 822 | |
| 823 InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, | |
| 824 new_target); | |
| 825 | |
| 826 GenerateIteratingArrayBuiltinBody( | |
| 827 "Array.prototype.map", &ArrayBuiltinCodeStubAssembler::MapResultGenerator, | |
| 828 &ArrayBuiltinCodeStubAssembler::MapProcessor, | |
| 829 &ArrayBuiltinCodeStubAssembler::NullPostLoopAction, | |
| 830 CodeFactory::ArrayMapLoopContinuation(isolate())); | |
| 831 } | |
| 832 | |
| 780 TF_BUILTIN(ArrayIsArray, CodeStubAssembler) { | 833 TF_BUILTIN(ArrayIsArray, CodeStubAssembler) { |
| 781 Node* object = Parameter(Descriptor::kArg); | 834 Node* object = Parameter(Descriptor::kArg); |
| 782 Node* context = Parameter(Descriptor::kContext); | 835 Node* context = Parameter(Descriptor::kContext); |
| 783 | 836 |
| 784 Label call_runtime(this), return_true(this), return_false(this); | 837 Label call_runtime(this), return_true(this), return_false(this); |
| 785 | 838 |
| 786 GotoIf(TaggedIsSmi(object), &return_false); | 839 GotoIf(TaggedIsSmi(object), &return_false); |
| 787 Node* instance_type = LoadInstanceType(object); | 840 Node* instance_type = LoadInstanceType(object); |
| 788 | 841 |
| 789 GotoIf(Word32Equal(instance_type, Int32Constant(JS_ARRAY_TYPE)), | 842 GotoIf(Word32Equal(instance_type, Int32Constant(JS_ARRAY_TYPE)), |
| (...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1831 { | 1884 { |
| 1832 Node* message = SmiConstant(MessageTemplate::kDetachedOperation); | 1885 Node* message = SmiConstant(MessageTemplate::kDetachedOperation); |
| 1833 CallRuntime(Runtime::kThrowTypeError, context, message, | 1886 CallRuntime(Runtime::kThrowTypeError, context, message, |
| 1834 HeapConstant(operation)); | 1887 HeapConstant(operation)); |
| 1835 Unreachable(); | 1888 Unreachable(); |
| 1836 } | 1889 } |
| 1837 } | 1890 } |
| 1838 | 1891 |
| 1839 } // namespace internal | 1892 } // namespace internal |
| 1840 } // namespace v8 | 1893 } // namespace v8 |
| OLD | NEW |