OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 UNREACHABLE(); | 177 UNREACHABLE(); |
178 return isolate->heap()->undefined_value(); // Make compiler happy. | 178 return isolate->heap()->undefined_value(); // Make compiler happy. |
179 } | 179 } |
180 | 180 |
181 | 181 |
182 BUILTIN(EmptyFunction) { | 182 BUILTIN(EmptyFunction) { |
183 return isolate->heap()->undefined_value(); | 183 return isolate->heap()->undefined_value(); |
184 } | 184 } |
185 | 185 |
186 | 186 |
187 BUILTIN(ArrayCodeGeneric) { | 187 static MaybeObject* ArrayCodeGenericCommon(Arguments* args, |
| 188 Isolate* isolate, |
| 189 JSFunction* constructor) { |
188 Heap* heap = isolate->heap(); | 190 Heap* heap = isolate->heap(); |
189 isolate->counters()->array_function_runtime()->Increment(); | 191 isolate->counters()->array_function_runtime()->Increment(); |
190 | 192 |
191 JSArray* array; | 193 JSArray* array; |
192 if (CalledAsConstructor(isolate)) { | 194 if (CalledAsConstructor(isolate)) { |
193 array = JSArray::cast(*args.receiver()); | 195 array = JSArray::cast((*args)[0]); |
194 } else { | 196 } else { |
195 // Allocate the JS Array | 197 // Allocate the JS Array |
196 JSFunction* constructor = | |
197 isolate->context()->global_context()->array_function(); | |
198 Object* obj; | 198 Object* obj; |
199 { MaybeObject* maybe_obj = heap->AllocateJSObject(constructor); | 199 { MaybeObject* maybe_obj = heap->AllocateJSObject(constructor); |
200 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 200 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
201 } | 201 } |
202 array = JSArray::cast(obj); | 202 array = JSArray::cast(obj); |
203 } | 203 } |
204 | 204 |
205 // 'array' now contains the JSArray we should initialize. | |
206 ASSERT(array->HasFastTypeElements()); | |
207 | |
208 // Optimize the case where there is one argument and the argument is a | 205 // Optimize the case where there is one argument and the argument is a |
209 // small smi. | 206 // small smi. |
210 if (args.length() == 2) { | 207 if (args->length() == 2) { |
211 Object* obj = args[1]; | 208 Object* obj = (*args)[1]; |
212 if (obj->IsSmi()) { | 209 if (obj->IsSmi()) { |
213 int len = Smi::cast(obj)->value(); | 210 int len = Smi::cast(obj)->value(); |
214 if (len >= 0 && len < JSObject::kInitialMaxFastElementArray) { | 211 if (len >= 0 && len < JSObject::kInitialMaxFastElementArray) { |
215 Object* obj; | 212 Object* obj; |
216 { MaybeObject* maybe_obj = heap->AllocateFixedArrayWithHoles(len); | 213 { MaybeObject* maybe_obj = heap->AllocateFixedArrayWithHoles(len); |
217 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 214 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
218 } | 215 } |
219 MaybeObject* maybe_obj = array->SetContent(FixedArray::cast(obj)); | 216 MaybeObject* maybe_obj = array->SetContent(FixedArray::cast(obj)); |
220 if (maybe_obj->IsFailure()) return maybe_obj; | 217 if (maybe_obj->IsFailure()) return maybe_obj; |
221 return array; | 218 return array; |
222 } | 219 } |
223 } | 220 } |
224 // Take the argument as the length. | 221 // Take the argument as the length. |
225 { MaybeObject* maybe_obj = array->Initialize(0); | 222 { MaybeObject* maybe_obj = array->Initialize(0); |
226 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 223 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
227 } | 224 } |
228 return array->SetElementsLength(args[1]); | 225 return array->SetElementsLength((*args)[1]); |
229 } | 226 } |
230 | 227 |
231 // Optimize the case where there are no parameters passed. | 228 // Optimize the case where there are no parameters passed. |
232 if (args.length() == 1) { | 229 if (args->length() == 1) { |
233 return array->Initialize(JSArray::kPreallocatedArrayElements); | 230 return array->Initialize(JSArray::kPreallocatedArrayElements); |
234 } | 231 } |
235 | 232 |
236 // Set length and elements on the array. | 233 // Set length and elements on the array. |
237 int number_of_elements = args.length() - 1; | 234 int number_of_elements = args->length() - 1; |
238 MaybeObject* maybe_object = | 235 MaybeObject* maybe_object = |
239 array->EnsureCanContainElements(&args, 1, number_of_elements, | 236 array->EnsureCanContainElements(args, 1, number_of_elements, |
240 ALLOW_CONVERTED_DOUBLE_ELEMENTS); | 237 ALLOW_CONVERTED_DOUBLE_ELEMENTS); |
241 if (maybe_object->IsFailure()) return maybe_object; | 238 if (maybe_object->IsFailure()) return maybe_object; |
242 | 239 |
243 // Allocate an appropriately typed elements array. | 240 // Allocate an appropriately typed elements array. |
244 MaybeObject* maybe_elms; | 241 MaybeObject* maybe_elms; |
245 ElementsKind elements_kind = array->GetElementsKind(); | 242 ElementsKind elements_kind = array->GetElementsKind(); |
246 if (elements_kind == FAST_DOUBLE_ELEMENTS) { | 243 if (elements_kind == FAST_DOUBLE_ELEMENTS) { |
247 maybe_elms = heap->AllocateUninitializedFixedDoubleArray( | 244 maybe_elms = heap->AllocateUninitializedFixedDoubleArray( |
248 number_of_elements); | 245 number_of_elements); |
249 } else { | 246 } else { |
250 maybe_elms = heap->AllocateFixedArrayWithHoles(number_of_elements); | 247 maybe_elms = heap->AllocateFixedArrayWithHoles(number_of_elements); |
251 } | 248 } |
252 FixedArrayBase* elms; | 249 FixedArrayBase* elms; |
253 if (!maybe_elms->To<FixedArrayBase>(&elms)) return maybe_elms; | 250 if (!maybe_elms->To<FixedArrayBase>(&elms)) return maybe_elms; |
254 | 251 |
255 // Fill in the content | 252 // Fill in the content |
256 switch (array->GetElementsKind()) { | 253 switch (array->GetElementsKind()) { |
257 case FAST_SMI_ONLY_ELEMENTS: { | 254 case FAST_SMI_ONLY_ELEMENTS: { |
258 FixedArray* smi_elms = FixedArray::cast(elms); | 255 FixedArray* smi_elms = FixedArray::cast(elms); |
259 for (int index = 0; index < number_of_elements; index++) { | 256 for (int index = 0; index < number_of_elements; index++) { |
260 smi_elms->set(index, args[index+1], SKIP_WRITE_BARRIER); | 257 smi_elms->set(index, (*args)[index+1], SKIP_WRITE_BARRIER); |
261 } | 258 } |
262 break; | 259 break; |
263 } | 260 } |
264 case FAST_ELEMENTS: { | 261 case FAST_ELEMENTS: { |
265 AssertNoAllocation no_gc; | 262 AssertNoAllocation no_gc; |
266 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); | 263 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); |
267 FixedArray* object_elms = FixedArray::cast(elms); | 264 FixedArray* object_elms = FixedArray::cast(elms); |
268 for (int index = 0; index < number_of_elements; index++) { | 265 for (int index = 0; index < number_of_elements; index++) { |
269 object_elms->set(index, args[index+1], mode); | 266 object_elms->set(index, (*args)[index+1], mode); |
270 } | 267 } |
271 break; | 268 break; |
272 } | 269 } |
273 case FAST_DOUBLE_ELEMENTS: { | 270 case FAST_DOUBLE_ELEMENTS: { |
274 FixedDoubleArray* double_elms = FixedDoubleArray::cast(elms); | 271 FixedDoubleArray* double_elms = FixedDoubleArray::cast(elms); |
275 for (int index = 0; index < number_of_elements; index++) { | 272 for (int index = 0; index < number_of_elements; index++) { |
276 double_elms->set(index, args[index+1]->Number()); | 273 double_elms->set(index, (*args)[index+1]->Number()); |
277 } | 274 } |
278 break; | 275 break; |
279 } | 276 } |
280 default: | 277 default: |
281 UNREACHABLE(); | 278 UNREACHABLE(); |
282 break; | 279 break; |
283 } | 280 } |
284 | 281 |
285 array->set_elements(elms); | 282 array->set_elements(elms); |
286 array->set_length(Smi::FromInt(number_of_elements)); | 283 array->set_length(Smi::FromInt(number_of_elements)); |
287 return array; | 284 return array; |
288 } | 285 } |
289 | 286 |
290 | 287 |
| 288 BUILTIN(InternalArrayCodeGeneric) { |
| 289 return ArrayCodeGenericCommon( |
| 290 &args, |
| 291 isolate, |
| 292 isolate->context()->global_context()->internal_array_function()); |
| 293 } |
| 294 |
| 295 |
| 296 BUILTIN(ArrayCodeGeneric) { |
| 297 return ArrayCodeGenericCommon( |
| 298 &args, |
| 299 isolate, |
| 300 isolate->context()->global_context()->array_function()); |
| 301 } |
| 302 |
| 303 |
291 MUST_USE_RESULT static MaybeObject* AllocateJSArray(Heap* heap) { | 304 MUST_USE_RESULT static MaybeObject* AllocateJSArray(Heap* heap) { |
292 JSFunction* array_function = | 305 JSFunction* array_function = |
293 heap->isolate()->context()->global_context()->array_function(); | 306 heap->isolate()->context()->global_context()->array_function(); |
294 Object* result; | 307 Object* result; |
295 { MaybeObject* maybe_result = heap->AllocateJSObject(array_function); | 308 { MaybeObject* maybe_result = heap->AllocateJSObject(array_function); |
296 if (!maybe_result->ToObject(&result)) return maybe_result; | 309 if (!maybe_result->ToObject(&result)) return maybe_result; |
297 } | 310 } |
298 return result; | 311 return result; |
299 } | 312 } |
300 | 313 |
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 return Handle<Code>(code_address); \ | 1828 return Handle<Code>(code_address); \ |
1816 } | 1829 } |
1817 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1830 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1818 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1831 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1819 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1832 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1820 #undef DEFINE_BUILTIN_ACCESSOR_C | 1833 #undef DEFINE_BUILTIN_ACCESSOR_C |
1821 #undef DEFINE_BUILTIN_ACCESSOR_A | 1834 #undef DEFINE_BUILTIN_ACCESSOR_A |
1822 | 1835 |
1823 | 1836 |
1824 } } // namespace v8::internal | 1837 } } // namespace v8::internal |
OLD | NEW |