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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 Label ok(this); | 84 Label ok(this); |
85 GotoIf(WordNotEqual(a(), TheHoleConstant()), &ok); | 85 GotoIf(WordNotEqual(a(), TheHoleConstant()), &ok); |
86 CallRuntime(Runtime::kThrowTypeError, context(), | 86 CallRuntime(Runtime::kThrowTypeError, context(), |
87 SmiConstant(MessageTemplate::kReduceNoInitial)); | 87 SmiConstant(MessageTemplate::kReduceNoInitial)); |
88 Unreachable(); | 88 Unreachable(); |
89 BIND(&ok); | 89 BIND(&ok); |
90 } | 90 } |
91 | 91 |
92 void FilterResultGenerator() { | 92 void FilterResultGenerator() { |
93 // 7. Let A be ArraySpeciesCreate(O, 0). | 93 // 7. Let A be ArraySpeciesCreate(O, 0). |
94 a_.Bind(ArraySpeciesCreate(context(), o(), SmiConstant(0))); | 94 Node* len = SmiConstant(0); |
| 95 ArraySpeciesCreate(len); |
95 } | 96 } |
96 | 97 |
97 Node* FilterProcessor(Node* k_value, Node* k) { | 98 Node* FilterProcessor(Node* k_value, Node* k) { |
98 // ii. Let selected be ToBoolean(? Call(callbackfn, T, kValue, k, O)). | 99 // ii. Let selected be ToBoolean(? Call(callbackfn, T, kValue, k, O)). |
99 Node* selected = CallJS(CodeFactory::Call(isolate()), context(), | 100 Node* selected = CallJS(CodeFactory::Call(isolate()), context(), |
100 callbackfn(), this_arg(), k_value, k, o()); | 101 callbackfn(), this_arg(), k_value, k, o()); |
101 Label true_continue(this, &to_), false_continue(this); | 102 Label true_continue(this, &to_), false_continue(this); |
102 BranchIfToBooleanIsTrue(selected, &true_continue, &false_continue); | 103 BranchIfToBooleanIsTrue(selected, &true_continue, &false_continue); |
103 BIND(&true_continue); | 104 BIND(&true_continue); |
104 // iii. If selected is true, then... | 105 // iii. If selected is true, then... |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 { | 154 { |
154 // 2. Increase to by 1. | 155 // 2. Increase to by 1. |
155 to_.Bind(NumberInc(to_.value())); | 156 to_.Bind(NumberInc(to_.value())); |
156 Goto(&false_continue); | 157 Goto(&false_continue); |
157 } | 158 } |
158 } | 159 } |
159 BIND(&false_continue); | 160 BIND(&false_continue); |
160 return a(); | 161 return a(); |
161 } | 162 } |
162 | 163 |
163 void MapResultGenerator() { | 164 void MapResultGenerator() { ArraySpeciesCreate(len_); } |
164 Label runtime(this), done(this, {&a_}); | |
165 GotoIf(DoesntHaveInstanceType(o(), JS_ARRAY_TYPE), &runtime); | |
166 Node* o_map = LoadMap(o()); | |
167 Node* const initial_array_prototype = LoadContextElement( | |
168 LoadNativeContext(context()), Context::INITIAL_ARRAY_PROTOTYPE_INDEX); | |
169 Node* proto = LoadMapPrototype(o_map); | |
170 GotoIf(WordNotEqual(proto, initial_array_prototype), &runtime); | |
171 | |
172 Node* species_protector = SpeciesProtectorConstant(); | |
173 Node* value = LoadObjectField(species_protector, Cell::kValueOffset); | |
174 Node* const protector_invalid = SmiConstant(Isolate::kProtectorInvalid); | |
175 GotoIf(WordEqual(value, protector_invalid), &runtime); | |
176 | |
177 Node* const initial_array_constructor = LoadContextElement( | |
178 LoadNativeContext(context()), Context::ARRAY_FUNCTION_INDEX); | |
179 a_.Bind(ConstructJS(CodeFactory::Construct(isolate()), context(), | |
180 initial_array_constructor, len_)); | |
181 Goto(&done); | |
182 | |
183 BIND(&runtime); | |
184 { | |
185 // 5. Let A be ? ArraySpeciesCreate(O, len). | |
186 Node* constructor = | |
187 CallRuntime(Runtime::kArraySpeciesConstructor, context(), o()); | |
188 a_.Bind(ConstructJS(CodeFactory::Construct(isolate()), context(), | |
189 constructor, len_)); | |
190 Goto(&fully_spec_compliant_); | |
191 } | |
192 BIND(&done); | |
193 } | |
194 | 165 |
195 Node* SpecCompliantMapProcessor(Node* k_value, Node* k) { | 166 Node* SpecCompliantMapProcessor(Node* k_value, Node* k) { |
196 // i. Let kValue be ? Get(O, Pk). Performed by the caller of | 167 // i. Let kValue be ? Get(O, Pk). Performed by the caller of |
197 // SpecCompliantMapProcessor. | 168 // SpecCompliantMapProcessor. |
198 // ii. Let mappedValue be ? Call(callbackfn, T, kValue, k, O). | 169 // ii. Let mappedValue be ? Call(callbackfn, T, kValue, k, O). |
199 Node* mappedValue = CallJS(CodeFactory::Call(isolate()), context(), | 170 Node* mappedValue = CallJS(CodeFactory::Call(isolate()), context(), |
200 callbackfn(), this_arg(), k_value, k, o()); | 171 callbackfn(), this_arg(), k_value, k, o()); |
201 | 172 |
202 // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). | 173 // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). |
203 CallRuntime(Runtime::kCreateDataProperty, context(), a(), k, mappedValue); | 174 CallRuntime(Runtime::kCreateDataProperty, context(), a(), k, mappedValue); |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 VisitAllFastElementsOneKind(FAST_DOUBLE_ELEMENTS, processor, slow, mode, | 680 VisitAllFastElementsOneKind(FAST_DOUBLE_ELEMENTS, processor, slow, mode, |
710 direction); | 681 direction); |
711 | 682 |
712 action(this); | 683 action(this); |
713 | 684 |
714 // No exception, return success | 685 // No exception, return success |
715 ReturnFromBuiltin(a_.value()); | 686 ReturnFromBuiltin(a_.value()); |
716 } | 687 } |
717 } | 688 } |
718 | 689 |
| 690 // Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate). |
| 691 void ArraySpeciesCreate(Node* len) { |
| 692 Label runtime(this, Label::kDeferred), done(this); |
| 693 |
| 694 Node* const original_map = LoadMap(o()); |
| 695 GotoIf(Word32NotEqual(LoadMapInstanceType(original_map), |
| 696 Int32Constant(JS_ARRAY_TYPE)), |
| 697 &runtime); |
| 698 |
| 699 Node* const native_context = LoadNativeContext(context()); |
| 700 Node* const initial_array_prototype = LoadContextElement( |
| 701 native_context, Context::INITIAL_ARRAY_PROTOTYPE_INDEX); |
| 702 Node* proto = LoadMapPrototype(original_map); |
| 703 GotoIf(WordNotEqual(proto, initial_array_prototype), &runtime); |
| 704 |
| 705 Node* species_protector = SpeciesProtectorConstant(); |
| 706 Node* value = LoadObjectField(species_protector, Cell::kValueOffset); |
| 707 Node* const protector_invalid = SmiConstant(Isolate::kProtectorInvalid); |
| 708 GotoIf(WordEqual(value, protector_invalid), &runtime); |
| 709 |
| 710 GotoIfNot(TaggedIsPositiveSmi(len), &runtime); |
| 711 GotoIf(SmiAbove(len, SmiConstant(JSArray::kInitialMaxFastElementArray)), |
| 712 &runtime); |
| 713 |
| 714 const ElementsKind elements_kind = |
| 715 GetHoleyElementsKind(GetInitialFastElementsKind()); |
| 716 Node* array_map = LoadJSArrayElementsMap(elements_kind, native_context); |
| 717 a_.Bind(AllocateJSArray(FAST_SMI_ELEMENTS, array_map, len, len, nullptr, |
| 718 CodeStubAssembler::SMI_PARAMETERS)); |
| 719 |
| 720 Goto(&done); |
| 721 |
| 722 BIND(&runtime); |
| 723 { |
| 724 // 5. Let A be ? ArraySpeciesCreate(O, len). |
| 725 Node* constructor = |
| 726 CallRuntime(Runtime::kArraySpeciesConstructor, context(), o()); |
| 727 a_.Bind(ConstructJS(CodeFactory::Construct(isolate()), context(), |
| 728 constructor, len)); |
| 729 Goto(&fully_spec_compliant_); |
| 730 } |
| 731 |
| 732 BIND(&done); |
| 733 } |
| 734 |
719 Node* callbackfn_ = nullptr; | 735 Node* callbackfn_ = nullptr; |
720 Node* o_ = nullptr; | 736 Node* o_ = nullptr; |
721 Node* this_arg_ = nullptr; | 737 Node* this_arg_ = nullptr; |
722 Node* len_ = nullptr; | 738 Node* len_ = nullptr; |
723 Node* context_ = nullptr; | 739 Node* context_ = nullptr; |
724 Node* receiver_ = nullptr; | 740 Node* receiver_ = nullptr; |
725 Node* new_target_ = nullptr; | 741 Node* new_target_ = nullptr; |
726 Node* argc_ = nullptr; | 742 Node* argc_ = nullptr; |
727 Variable k_; | 743 Variable k_; |
728 Variable a_; | 744 Variable a_; |
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2400 { | 2416 { |
2401 Node* message = SmiConstant(MessageTemplate::kDetachedOperation); | 2417 Node* message = SmiConstant(MessageTemplate::kDetachedOperation); |
2402 CallRuntime(Runtime::kThrowTypeError, context, message, | 2418 CallRuntime(Runtime::kThrowTypeError, context, message, |
2403 HeapConstant(operation)); | 2419 HeapConstant(operation)); |
2404 Unreachable(); | 2420 Unreachable(); |
2405 } | 2421 } |
2406 } | 2422 } |
2407 | 2423 |
2408 } // namespace internal | 2424 } // namespace internal |
2409 } // namespace v8 | 2425 } // namespace v8 |
OLD | NEW |