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/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return false; | 192 return false; |
193 } | 193 } |
194 } | 194 } |
195 return true; | 195 return true; |
196 } | 196 } |
197 | 197 |
198 | 198 |
199 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, | 199 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, |
200 JSArray* receiver) { | 200 JSArray* receiver) { |
201 DisallowHeapAllocation no_gc; | 201 DisallowHeapAllocation no_gc; |
202 PrototypeIterator iter(heap->isolate(), receiver); | 202 Isolate* isolate = heap->isolate(); |
| 203 if (!isolate->IsFastArrayConstructorPrototypeChainIntact()) { |
| 204 return false; |
| 205 } |
| 206 |
| 207 // If the array prototype chain is intact (and free of elements), and if the |
| 208 // receiver's prototype is the array prototype, then we are done. |
| 209 Object* prototype = receiver->map()->prototype(); |
| 210 if (prototype->IsJSArray() && |
| 211 isolate->is_initial_array_prototype(JSArray::cast(prototype))) { |
| 212 return true; |
| 213 } |
| 214 |
| 215 // Slow case. |
| 216 PrototypeIterator iter(isolate, receiver); |
203 return ArrayPrototypeHasNoElements(heap, &iter); | 217 return ArrayPrototypeHasNoElements(heap, &iter); |
204 } | 218 } |
205 | 219 |
206 | 220 |
207 // Returns empty handle if not applicable. | 221 // Returns empty handle if not applicable. |
208 MUST_USE_RESULT | 222 MUST_USE_RESULT |
209 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( | 223 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( |
210 Isolate* isolate, | 224 Isolate* isolate, |
211 Handle<Object> receiver, | 225 Handle<Object> receiver, |
212 Arguments* args, | 226 Arguments* args, |
(...skipping 16 matching lines...) Expand all Loading... |
229 elms = JSObject::EnsureWritableFastElements(array); | 243 elms = JSObject::EnsureWritableFastElements(array); |
230 if (args == NULL || array->HasFastObjectElements()) return elms; | 244 if (args == NULL || array->HasFastObjectElements()) return elms; |
231 } else if (map == heap->fixed_double_array_map()) { | 245 } else if (map == heap->fixed_double_array_map()) { |
232 if (args == NULL) return elms; | 246 if (args == NULL) return elms; |
233 } else { | 247 } else { |
234 return MaybeHandle<FixedArrayBase>(); | 248 return MaybeHandle<FixedArrayBase>(); |
235 } | 249 } |
236 | 250 |
237 // Adding elements to the array prototype would break code that makes sure | 251 // Adding elements to the array prototype would break code that makes sure |
238 // it has no elements. Handle that elsewhere. | 252 // it has no elements. Handle that elsewhere. |
239 if (array->GetIsolate()->is_initial_array_prototype(*array)) { | 253 if (isolate->IsAnyInitialArrayPrototype(array)) { |
240 return MaybeHandle<FixedArrayBase>(); | 254 return MaybeHandle<FixedArrayBase>(); |
241 } | 255 } |
242 | 256 |
243 // Need to ensure that the arguments passed in args can be contained in | 257 // Need to ensure that the arguments passed in args can be contained in |
244 // the array. | 258 // the array. |
245 int args_length = args->length(); | 259 int args_length = args->length(); |
246 if (first_added_arg >= args_length) return handle(array->elements(), isolate); | 260 if (first_added_arg >= args_length) return handle(array->elements(), isolate); |
247 | 261 |
248 ElementsKind origin_kind = array->map()->elements_kind(); | 262 ElementsKind origin_kind = array->map()->elements_kind(); |
249 DCHECK(!IsFastObjectElementsKind(origin_kind)); | 263 DCHECK(!IsFastObjectElementsKind(origin_kind)); |
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 } | 1672 } |
1659 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1673 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1660 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1674 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1661 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1675 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
1662 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1676 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1663 #undef DEFINE_BUILTIN_ACCESSOR_C | 1677 #undef DEFINE_BUILTIN_ACCESSOR_C |
1664 #undef DEFINE_BUILTIN_ACCESSOR_A | 1678 #undef DEFINE_BUILTIN_ACCESSOR_A |
1665 | 1679 |
1666 | 1680 |
1667 } } // namespace v8::internal | 1681 } } // namespace v8::internal |
OLD | NEW |