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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 isolate->counters()->array_function_runtime()->Increment(); | 192 isolate->counters()->array_function_runtime()->Increment(); |
193 | 193 |
194 JSArray* array; | 194 JSArray* array; |
195 if (CalledAsConstructor(isolate)) { | 195 if (CalledAsConstructor(isolate)) { |
196 array = JSArray::cast((*args)[0]); | 196 array = JSArray::cast((*args)[0]); |
197 // Initialize elements and length in case later allocations fail so that the | 197 // Initialize elements and length in case later allocations fail so that the |
198 // array object is initialized in a valid state. | 198 // array object is initialized in a valid state. |
199 array->set_length(Smi::FromInt(0)); | 199 array->set_length(Smi::FromInt(0)); |
200 array->set_elements(heap->empty_fixed_array()); | 200 array->set_elements(heap->empty_fixed_array()); |
201 if (!FLAG_smi_only_arrays) { | 201 if (!FLAG_smi_only_arrays) { |
202 Context* global_context = isolate->context()->global_context(); | 202 Context* native_context = isolate->context()->native_context(); |
203 if (array->GetElementsKind() == GetInitialFastElementsKind() && | 203 if (array->GetElementsKind() == GetInitialFastElementsKind() && |
204 !global_context->js_array_maps()->IsUndefined()) { | 204 !native_context->js_array_maps()->IsUndefined()) { |
205 FixedArray* map_array = | 205 FixedArray* map_array = |
206 FixedArray::cast(global_context->js_array_maps()); | 206 FixedArray::cast(native_context->js_array_maps()); |
207 array->set_map(Map::cast(map_array-> | 207 array->set_map(Map::cast(map_array-> |
208 get(TERMINAL_FAST_ELEMENTS_KIND))); | 208 get(TERMINAL_FAST_ELEMENTS_KIND))); |
209 } | 209 } |
210 } | 210 } |
211 } else { | 211 } else { |
212 // Allocate the JS Array | 212 // Allocate the JS Array |
213 MaybeObject* maybe_obj = heap->AllocateJSObject(constructor); | 213 MaybeObject* maybe_obj = heap->AllocateJSObject(constructor); |
214 if (!maybe_obj->To(&array)) return maybe_obj; | 214 if (!maybe_obj->To(&array)) return maybe_obj; |
215 } | 215 } |
216 | 216 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 array->set_elements(elms); | 305 array->set_elements(elms); |
306 array->set_length(Smi::FromInt(number_of_elements)); | 306 array->set_length(Smi::FromInt(number_of_elements)); |
307 return array; | 307 return array; |
308 } | 308 } |
309 | 309 |
310 | 310 |
311 BUILTIN(InternalArrayCodeGeneric) { | 311 BUILTIN(InternalArrayCodeGeneric) { |
312 return ArrayCodeGenericCommon( | 312 return ArrayCodeGenericCommon( |
313 &args, | 313 &args, |
314 isolate, | 314 isolate, |
315 isolate->context()->global_context()->internal_array_function()); | 315 isolate->context()->native_context()->internal_array_function()); |
316 } | 316 } |
317 | 317 |
318 | 318 |
319 BUILTIN(ArrayCodeGeneric) { | 319 BUILTIN(ArrayCodeGeneric) { |
320 return ArrayCodeGenericCommon( | 320 return ArrayCodeGenericCommon( |
321 &args, | 321 &args, |
322 isolate, | 322 isolate, |
323 isolate->context()->global_context()->array_function()); | 323 isolate->context()->native_context()->array_function()); |
324 } | 324 } |
325 | 325 |
326 | 326 |
327 static void MoveElements(Heap* heap, | 327 static void MoveElements(Heap* heap, |
328 AssertNoAllocation* no_gc, | 328 AssertNoAllocation* no_gc, |
329 FixedArray* dst, | 329 FixedArray* dst, |
330 int dst_index, | 330 int dst_index, |
331 FixedArray* src, | 331 FixedArray* src, |
332 int src_index, | 332 int src_index, |
333 int len) { | 333 int len) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 } | 395 } |
396 | 396 |
397 HEAP_PROFILE(heap, ObjectMoveEvent(elms->address(), | 397 HEAP_PROFILE(heap, ObjectMoveEvent(elms->address(), |
398 elms->address() + size_delta)); | 398 elms->address() + size_delta)); |
399 return FixedArray::cast(HeapObject::FromAddress( | 399 return FixedArray::cast(HeapObject::FromAddress( |
400 elms->address() + to_trim * kPointerSize)); | 400 elms->address() + to_trim * kPointerSize)); |
401 } | 401 } |
402 | 402 |
403 | 403 |
404 static bool ArrayPrototypeHasNoElements(Heap* heap, | 404 static bool ArrayPrototypeHasNoElements(Heap* heap, |
405 Context* global_context, | 405 Context* native_context, |
406 JSObject* array_proto) { | 406 JSObject* array_proto) { |
407 // This method depends on non writability of Object and Array prototype | 407 // This method depends on non writability of Object and Array prototype |
408 // fields. | 408 // fields. |
409 if (array_proto->elements() != heap->empty_fixed_array()) return false; | 409 if (array_proto->elements() != heap->empty_fixed_array()) return false; |
410 // Object.prototype | 410 // Object.prototype |
411 Object* proto = array_proto->GetPrototype(); | 411 Object* proto = array_proto->GetPrototype(); |
412 if (proto == heap->null_value()) return false; | 412 if (proto == heap->null_value()) return false; |
413 array_proto = JSObject::cast(proto); | 413 array_proto = JSObject::cast(proto); |
414 if (array_proto != global_context->initial_object_prototype()) return false; | 414 if (array_proto != native_context->initial_object_prototype()) return false; |
415 if (array_proto->elements() != heap->empty_fixed_array()) return false; | 415 if (array_proto->elements() != heap->empty_fixed_array()) return false; |
416 return array_proto->GetPrototype()->IsNull(); | 416 return array_proto->GetPrototype()->IsNull(); |
417 } | 417 } |
418 | 418 |
419 | 419 |
420 MUST_USE_RESULT | 420 MUST_USE_RESULT |
421 static inline MaybeObject* EnsureJSArrayWithWritableFastElements( | 421 static inline MaybeObject* EnsureJSArrayWithWritableFastElements( |
422 Heap* heap, Object* receiver, Arguments* args, int first_added_arg) { | 422 Heap* heap, Object* receiver, Arguments* args, int first_added_arg) { |
423 if (!receiver->IsJSArray()) return NULL; | 423 if (!receiver->IsJSArray()) return NULL; |
424 JSArray* array = JSArray::cast(receiver); | 424 JSArray* array = JSArray::cast(receiver); |
(...skipping 29 matching lines...) Expand all Loading... |
454 args_length - first_added_arg, | 454 args_length - first_added_arg, |
455 DONT_ALLOW_DOUBLE_ELEMENTS); | 455 DONT_ALLOW_DOUBLE_ELEMENTS); |
456 if (maybe_array->IsFailure()) return maybe_array; | 456 if (maybe_array->IsFailure()) return maybe_array; |
457 return array->elements(); | 457 return array->elements(); |
458 } | 458 } |
459 | 459 |
460 | 460 |
461 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, | 461 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, |
462 JSArray* receiver) { | 462 JSArray* receiver) { |
463 if (!FLAG_clever_optimizations) return false; | 463 if (!FLAG_clever_optimizations) return false; |
464 Context* global_context = heap->isolate()->context()->global_context(); | 464 Context* native_context = heap->isolate()->context()->native_context(); |
465 JSObject* array_proto = | 465 JSObject* array_proto = |
466 JSObject::cast(global_context->array_function()->prototype()); | 466 JSObject::cast(native_context->array_function()->prototype()); |
467 return receiver->GetPrototype() == array_proto && | 467 return receiver->GetPrototype() == array_proto && |
468 ArrayPrototypeHasNoElements(heap, global_context, array_proto); | 468 ArrayPrototypeHasNoElements(heap, native_context, array_proto); |
469 } | 469 } |
470 | 470 |
471 | 471 |
472 MUST_USE_RESULT static MaybeObject* CallJsBuiltin( | 472 MUST_USE_RESULT static MaybeObject* CallJsBuiltin( |
473 Isolate* isolate, | 473 Isolate* isolate, |
474 const char* name, | 474 const char* name, |
475 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { | 475 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { |
476 HandleScope handleScope(isolate); | 476 HandleScope handleScope(isolate); |
477 | 477 |
478 Handle<Object> js_builtin = | 478 Handle<Object> js_builtin = |
479 GetProperty(Handle<JSObject>(isolate->global_context()->builtins()), | 479 GetProperty(Handle<JSObject>(isolate->native_context()->builtins()), |
480 name); | 480 name); |
481 Handle<JSFunction> function = Handle<JSFunction>::cast(js_builtin); | 481 Handle<JSFunction> function = Handle<JSFunction>::cast(js_builtin); |
482 int argc = args.length() - 1; | 482 int argc = args.length() - 1; |
483 ScopedVector<Handle<Object> > argv(argc); | 483 ScopedVector<Handle<Object> > argv(argc); |
484 for (int i = 0; i < argc; ++i) { | 484 for (int i = 0; i < argc; ++i) { |
485 argv[i] = args.at<Object>(i + 1); | 485 argv[i] = args.at<Object>(i + 1); |
486 } | 486 } |
487 bool pending_exception; | 487 bool pending_exception; |
488 Handle<Object> result = Execution::Call(function, | 488 Handle<Object> result = Execution::Call(function, |
489 args.receiver(), | 489 args.receiver(), |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 !IsJSArrayFastElementMovingAllowed(heap, array)) { | 699 !IsJSArrayFastElementMovingAllowed(heap, array)) { |
700 return CallJsBuiltin(isolate, "ArraySlice", args); | 700 return CallJsBuiltin(isolate, "ArraySlice", args); |
701 } | 701 } |
702 | 702 |
703 elms = FixedArray::cast(array->elements()); | 703 elms = FixedArray::cast(array->elements()); |
704 len = Smi::cast(array->length())->value(); | 704 len = Smi::cast(array->length())->value(); |
705 } else { | 705 } else { |
706 // Array.slice(arguments, ...) is quite a common idiom (notably more | 706 // Array.slice(arguments, ...) is quite a common idiom (notably more |
707 // than 50% of invocations in Web apps). Treat it in C++ as well. | 707 // than 50% of invocations in Web apps). Treat it in C++ as well. |
708 Map* arguments_map = | 708 Map* arguments_map = |
709 isolate->context()->global_context()->arguments_boilerplate()->map(); | 709 isolate->context()->native_context()->arguments_boilerplate()->map(); |
710 | 710 |
711 bool is_arguments_object_with_fast_elements = | 711 bool is_arguments_object_with_fast_elements = |
712 receiver->IsJSObject() | 712 receiver->IsJSObject() |
713 && JSObject::cast(receiver)->map() == arguments_map | 713 && JSObject::cast(receiver)->map() == arguments_map |
714 && JSObject::cast(receiver)->HasFastSmiOrObjectElements(); | 714 && JSObject::cast(receiver)->HasFastSmiOrObjectElements(); |
715 if (!is_arguments_object_with_fast_elements) { | 715 if (!is_arguments_object_with_fast_elements) { |
716 return CallJsBuiltin(isolate, "ArraySlice", args); | 716 return CallJsBuiltin(isolate, "ArraySlice", args); |
717 } | 717 } |
718 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); | 718 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); |
719 Object* len_obj = JSObject::cast(receiver) | 719 Object* len_obj = JSObject::cast(receiver) |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 | 936 |
937 // Set the length. | 937 // Set the length. |
938 array->set_length(Smi::FromInt(new_length)); | 938 array->set_length(Smi::FromInt(new_length)); |
939 | 939 |
940 return result_array; | 940 return result_array; |
941 } | 941 } |
942 | 942 |
943 | 943 |
944 BUILTIN(ArrayConcat) { | 944 BUILTIN(ArrayConcat) { |
945 Heap* heap = isolate->heap(); | 945 Heap* heap = isolate->heap(); |
946 Context* global_context = isolate->context()->global_context(); | 946 Context* native_context = isolate->context()->native_context(); |
947 JSObject* array_proto = | 947 JSObject* array_proto = |
948 JSObject::cast(global_context->array_function()->prototype()); | 948 JSObject::cast(native_context->array_function()->prototype()); |
949 if (!ArrayPrototypeHasNoElements(heap, global_context, array_proto)) { | 949 if (!ArrayPrototypeHasNoElements(heap, native_context, array_proto)) { |
950 return CallJsBuiltin(isolate, "ArrayConcat", args); | 950 return CallJsBuiltin(isolate, "ArrayConcat", args); |
951 } | 951 } |
952 | 952 |
953 // Iterate through all the arguments performing checks | 953 // Iterate through all the arguments performing checks |
954 // and calculating total length. | 954 // and calculating total length. |
955 int n_arguments = args.length(); | 955 int n_arguments = args.length(); |
956 int result_len = 0; | 956 int result_len = 0; |
957 ElementsKind elements_kind = GetInitialFastElementsKind(); | 957 ElementsKind elements_kind = GetInitialFastElementsKind(); |
958 for (int i = 0; i < n_arguments; i++) { | 958 for (int i = 0; i < n_arguments; i++) { |
959 Object* arg = args[i]; | 959 Object* arg = args[i]; |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 return Handle<Code>(code_address); \ | 1703 return Handle<Code>(code_address); \ |
1704 } | 1704 } |
1705 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1705 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1706 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1706 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1707 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1707 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1708 #undef DEFINE_BUILTIN_ACCESSOR_C | 1708 #undef DEFINE_BUILTIN_ACCESSOR_C |
1709 #undef DEFINE_BUILTIN_ACCESSOR_A | 1709 #undef DEFINE_BUILTIN_ACCESSOR_A |
1710 | 1710 |
1711 | 1711 |
1712 } } // namespace v8::internal | 1712 } } // namespace v8::internal |
OLD | NEW |