OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/base/once.h" | 9 #include "src/base/once.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 | 176 |
177 static void MoveDoubleElements(FixedDoubleArray* dst, int dst_index, | 177 static void MoveDoubleElements(FixedDoubleArray* dst, int dst_index, |
178 FixedDoubleArray* src, int src_index, int len) { | 178 FixedDoubleArray* src, int src_index, int len) { |
179 if (len == 0) return; | 179 if (len == 0) return; |
180 MemMove(dst->data_start() + dst_index, src->data_start() + src_index, | 180 MemMove(dst->data_start() + dst_index, src->data_start() + src_index, |
181 len * kDoubleSize); | 181 len * kDoubleSize); |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 static bool ArrayPrototypeHasNoElements(Heap* heap, | 185 static bool ArrayPrototypeHasNoElements(Heap* heap, PrototypeIterator* iter) { |
186 Context* native_context, | |
187 JSObject* array_proto) { | |
188 DisallowHeapAllocation no_gc; | 186 DisallowHeapAllocation no_gc; |
189 // This method depends on non writability of Object and Array prototype | 187 for (; !iter->IsAtEnd(); iter->Advance()) { |
190 // fields. | 188 if (iter->GetCurrent()->IsJSProxy()) return false; |
191 if (array_proto->elements() != heap->empty_fixed_array()) return false; | 189 if (JSObject::cast(iter->GetCurrent())->elements() != |
192 // Object.prototype | 190 heap->empty_fixed_array()) { |
193 PrototypeIterator iter(heap->isolate(), array_proto); | 191 return false; |
194 if (iter.IsAtEnd()) { | 192 } |
195 return false; | |
196 } | 193 } |
197 array_proto = JSObject::cast(iter.GetCurrent()); | 194 return true; |
198 if (array_proto != native_context->initial_object_prototype()) return false; | |
199 if (array_proto->elements() != heap->empty_fixed_array()) return false; | |
200 iter.Advance(); | |
201 return iter.IsAtEnd(); | |
202 } | 195 } |
203 | 196 |
204 | 197 |
205 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, | 198 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, |
206 JSArray* receiver) { | 199 JSArray* receiver) { |
207 if (!FLAG_clever_optimizations) return false; | 200 if (!FLAG_clever_optimizations) return false; |
208 DisallowHeapAllocation no_gc; | 201 DisallowHeapAllocation no_gc; |
209 Context* native_context = heap->isolate()->context()->native_context(); | |
210 JSObject* array_proto = | |
211 JSObject::cast(native_context->array_function()->prototype()); | |
212 PrototypeIterator iter(heap->isolate(), receiver); | 202 PrototypeIterator iter(heap->isolate(), receiver); |
213 return iter.GetCurrent() == array_proto && | 203 return ArrayPrototypeHasNoElements(heap, &iter); |
214 ArrayPrototypeHasNoElements(heap, native_context, array_proto); | |
215 } | 204 } |
216 | 205 |
217 | 206 |
218 // Returns empty handle if not applicable. | 207 // Returns empty handle if not applicable. |
219 MUST_USE_RESULT | 208 MUST_USE_RESULT |
220 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( | 209 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( |
221 Isolate* isolate, | 210 Isolate* isolate, |
222 Handle<Object> receiver, | 211 Handle<Object> receiver, |
223 Arguments* args, | 212 Arguments* args, |
224 int first_added_arg) { | 213 int first_added_arg) { |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 HandleScope scope(isolate); | 902 HandleScope scope(isolate); |
914 | 903 |
915 int n_arguments = args.length(); | 904 int n_arguments = args.length(); |
916 int result_len = 0; | 905 int result_len = 0; |
917 ElementsKind elements_kind = GetInitialFastElementsKind(); | 906 ElementsKind elements_kind = GetInitialFastElementsKind(); |
918 bool has_double = false; | 907 bool has_double = false; |
919 { | 908 { |
920 DisallowHeapAllocation no_gc; | 909 DisallowHeapAllocation no_gc; |
921 Heap* heap = isolate->heap(); | 910 Heap* heap = isolate->heap(); |
922 Context* native_context = isolate->context()->native_context(); | 911 Context* native_context = isolate->context()->native_context(); |
923 JSObject* array_proto = | 912 Object* array_proto = native_context->array_function()->prototype(); |
924 JSObject::cast(native_context->array_function()->prototype()); | 913 PrototypeIterator iter(isolate, array_proto, |
925 if (!ArrayPrototypeHasNoElements(heap, native_context, array_proto)) { | 914 PrototypeIterator::START_AT_RECEIVER); |
| 915 if (!ArrayPrototypeHasNoElements(heap, &iter)) { |
926 AllowHeapAllocation allow_allocation; | 916 AllowHeapAllocation allow_allocation; |
927 return CallJsBuiltin(isolate, "ArrayConcatJS", args); | 917 return CallJsBuiltin(isolate, "ArrayConcatJS", args); |
928 } | 918 } |
929 | 919 |
930 // Iterate through all the arguments performing checks | 920 // Iterate through all the arguments performing checks |
931 // and calculating total length. | 921 // and calculating total length. |
932 bool is_holey = false; | 922 bool is_holey = false; |
933 for (int i = 0; i < n_arguments; i++) { | 923 for (int i = 0; i < n_arguments; i++) { |
934 Object* arg = args[i]; | 924 Object* arg = args[i]; |
935 PrototypeIterator iter(isolate, arg); | 925 PrototypeIterator iter(isolate, arg); |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 } | 1632 } |
1643 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1633 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1644 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1634 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1645 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1635 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
1646 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1636 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1647 #undef DEFINE_BUILTIN_ACCESSOR_C | 1637 #undef DEFINE_BUILTIN_ACCESSOR_C |
1648 #undef DEFINE_BUILTIN_ACCESSOR_A | 1638 #undef DEFINE_BUILTIN_ACCESSOR_A |
1649 | 1639 |
1650 | 1640 |
1651 } } // namespace v8::internal | 1641 } } // namespace v8::internal |
OLD | NEW |