OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 UNREACHABLE(); | 188 UNREACHABLE(); |
189 return isolate->heap()->undefined_value(); // Make compiler happy. | 189 return isolate->heap()->undefined_value(); // Make compiler happy. |
190 } | 190 } |
191 | 191 |
192 | 192 |
193 BUILTIN(EmptyFunction) { | 193 BUILTIN(EmptyFunction) { |
194 return isolate->heap()->undefined_value(); | 194 return isolate->heap()->undefined_value(); |
195 } | 195 } |
196 | 196 |
197 | 197 |
198 static MaybeObject* ArrayCodeGenericCommon(Arguments* args, | |
199 Isolate* isolate, | |
200 JSFunction* constructor) { | |
201 ASSERT(args->length() >= 1); | |
202 Heap* heap = isolate->heap(); | |
203 isolate->counters()->array_function_runtime()->Increment(); | |
204 | |
205 JSArray* array; | |
206 if (CalledAsConstructor(isolate)) { | |
207 array = JSArray::cast((*args)[0]); | |
208 // Initialize elements and length in case later allocations fail so that the | |
209 // array object is initialized in a valid state. | |
210 MaybeObject* maybe_array = array->Initialize(0); | |
211 if (maybe_array->IsFailure()) return maybe_array; | |
212 | |
213 AllocationMemento* memento = AllocationMemento::FindForJSObject(array); | |
214 if (memento != NULL && memento->IsValid()) { | |
215 AllocationSite* site = memento->GetAllocationSite(); | |
216 ElementsKind to_kind = site->GetElementsKind(); | |
217 if (IsMoreGeneralElementsKindTransition(array->GetElementsKind(), | |
218 to_kind)) { | |
219 // We have advice that we should change the elements kind | |
220 if (FLAG_trace_track_allocation_sites) { | |
221 PrintF("AllocationSite: pre-transitioning array %p(%s->%s)\n", | |
222 reinterpret_cast<void*>(array), | |
223 ElementsKindToString(array->GetElementsKind()), | |
224 ElementsKindToString(to_kind)); | |
225 } | |
226 | |
227 maybe_array = array->TransitionElementsKind(to_kind); | |
228 if (maybe_array->IsFailure()) return maybe_array; | |
229 } | |
230 } | |
231 | |
232 if (!FLAG_smi_only_arrays) { | |
233 Context* native_context = isolate->context()->native_context(); | |
234 if (array->GetElementsKind() == GetInitialFastElementsKind() && | |
235 !native_context->js_array_maps()->IsUndefined()) { | |
236 FixedArray* map_array = | |
237 FixedArray::cast(native_context->js_array_maps()); | |
238 array->set_map(Map::cast(map_array-> | |
239 get(TERMINAL_FAST_ELEMENTS_KIND))); | |
240 } | |
241 } | |
242 } else { | |
243 // Allocate the JS Array | |
244 MaybeObject* maybe_obj = heap->AllocateJSObject(constructor); | |
245 if (!maybe_obj->To(&array)) return maybe_obj; | |
246 } | |
247 | |
248 Arguments adjusted_arguments(args->length() - 1, args->arguments() - 1); | |
249 ASSERT(adjusted_arguments.length() < 1 || | |
250 adjusted_arguments[0] == (*args)[1]); | |
251 return ArrayConstructInitializeElements(array, &adjusted_arguments); | |
252 } | |
253 | |
254 | |
255 BUILTIN(InternalArrayCodeGeneric) { | |
256 return ArrayCodeGenericCommon( | |
257 &args, | |
258 isolate, | |
259 isolate->context()->native_context()->internal_array_function()); | |
260 } | |
261 | |
262 | |
263 BUILTIN(ArrayCodeGeneric) { | |
264 return ArrayCodeGenericCommon( | |
265 &args, | |
266 isolate, | |
267 isolate->context()->native_context()->array_function()); | |
268 } | |
269 | |
270 | |
271 static void MoveDoubleElements(FixedDoubleArray* dst, | 198 static void MoveDoubleElements(FixedDoubleArray* dst, |
272 int dst_index, | 199 int dst_index, |
273 FixedDoubleArray* src, | 200 FixedDoubleArray* src, |
274 int src_index, | 201 int src_index, |
275 int len) { | 202 int len) { |
276 if (len == 0) return; | 203 if (len == 0) return; |
277 OS::MemMove(dst->data_start() + dst_index, | 204 OS::MemMove(dst->data_start() + dst_index, |
278 src->data_start() + src_index, | 205 src->data_start() + src_index, |
279 len * kDoubleSize); | 206 len * kDoubleSize); |
280 } | 207 } |
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 return Handle<Code>(code_address); \ | 1782 return Handle<Code>(code_address); \ |
1856 } | 1783 } |
1857 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1784 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1858 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1785 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1859 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1786 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1860 #undef DEFINE_BUILTIN_ACCESSOR_C | 1787 #undef DEFINE_BUILTIN_ACCESSOR_C |
1861 #undef DEFINE_BUILTIN_ACCESSOR_A | 1788 #undef DEFINE_BUILTIN_ACCESSOR_A |
1862 | 1789 |
1863 | 1790 |
1864 } } // namespace v8::internal | 1791 } } // namespace v8::internal |
OLD | NEW |