| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 ASSERT(array_proto->GetPrototype()->IsNull()); | 378 ASSERT(array_proto->GetPrototype()->IsNull()); |
| 379 return true; | 379 return true; |
| 380 } | 380 } |
| 381 | 381 |
| 382 | 382 |
| 383 MUST_USE_RESULT | 383 MUST_USE_RESULT |
| 384 static inline MaybeObject* EnsureJSArrayWithWritableFastElements( | 384 static inline MaybeObject* EnsureJSArrayWithWritableFastElements( |
| 385 Heap* heap, Object* receiver) { | 385 Heap* heap, Object* receiver) { |
| 386 if (!receiver->IsJSArray()) return NULL; | 386 if (!receiver->IsJSArray()) return NULL; |
| 387 JSArray* array = JSArray::cast(receiver); | 387 JSArray* array = JSArray::cast(receiver); |
| 388 HeapObject* elms = HeapObject::cast(array->elements()); | 388 HeapObject* elms = array->elements(); |
| 389 if (elms->map() == heap->fixed_array_map()) return elms; | 389 if (elms->map() == heap->fixed_array_map()) return elms; |
| 390 if (elms->map() == heap->fixed_cow_array_map()) { | 390 if (elms->map() == heap->fixed_cow_array_map()) { |
| 391 return array->EnsureWritableFastElements(); | 391 return array->EnsureWritableFastElements(); |
| 392 } | 392 } |
| 393 return NULL; | 393 return NULL; |
| 394 } | 394 } |
| 395 | 395 |
| 396 | 396 |
| 397 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, | 397 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, |
| 398 JSArray* receiver) { | 398 JSArray* receiver) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 array->set_length(Smi::FromInt(new_length)); | 623 array->set_length(Smi::FromInt(new_length)); |
| 624 return Smi::FromInt(new_length); | 624 return Smi::FromInt(new_length); |
| 625 } | 625 } |
| 626 | 626 |
| 627 | 627 |
| 628 BUILTIN(ArraySlice) { | 628 BUILTIN(ArraySlice) { |
| 629 Heap* heap = isolate->heap(); | 629 Heap* heap = isolate->heap(); |
| 630 Object* receiver = *args.receiver(); | 630 Object* receiver = *args.receiver(); |
| 631 FixedArray* elms; | 631 FixedArray* elms; |
| 632 int len = -1; | 632 int len = -1; |
| 633 { MaybeObject* maybe_elms_obj = | 633 if (receiver->IsJSArray()) { |
| 634 EnsureJSArrayWithWritableFastElements(heap, receiver); | 634 JSArray* array = JSArray::cast(receiver); |
| 635 Object* elms_obj; | 635 if (!array->HasFastElements() || |
| 636 if (maybe_elms_obj != NULL && maybe_elms_obj->ToObject(&elms_obj)) { | 636 !IsJSArrayFastElementMovingAllowed(heap, array)) { |
| 637 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | 637 return CallJsBuiltin(isolate, "ArraySlice", args); |
| 638 } |
| 639 |
| 640 elms = FixedArray::cast(array->elements()); |
| 641 len = Smi::cast(array->length())->value(); |
| 642 } else { |
| 643 // Array.slice(arguments, ...) is quite a common idiom (notably more |
| 644 // than 50% of invocations in Web apps). Treat it in C++ as well. |
| 645 Map* arguments_map = |
| 646 isolate->context()->global_context()->arguments_boilerplate()->map(); |
| 647 |
| 648 bool is_arguments_object_with_fast_elements = |
| 649 receiver->IsJSObject() |
| 650 && JSObject::cast(receiver)->map() == arguments_map |
| 651 && JSObject::cast(receiver)->HasFastElements(); |
| 652 if (!is_arguments_object_with_fast_elements) { |
| 653 return CallJsBuiltin(isolate, "ArraySlice", args); |
| 654 } |
| 655 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); |
| 656 Object* len_obj = JSObject::cast(receiver) |
| 657 ->InObjectPropertyAt(Heap::arguments_length_index); |
| 658 if (!len_obj->IsSmi()) { |
| 659 return CallJsBuiltin(isolate, "ArraySlice", args); |
| 660 } |
| 661 len = Smi::cast(len_obj)->value(); |
| 662 if (len > elms->length()) { |
| 663 return CallJsBuiltin(isolate, "ArraySlice", args); |
| 664 } |
| 665 for (int i = 0; i < len; i++) { |
| 666 if (elms->get(i) == heap->the_hole_value()) { |
| 638 return CallJsBuiltin(isolate, "ArraySlice", args); | 667 return CallJsBuiltin(isolate, "ArraySlice", args); |
| 639 } | 668 } |
| 640 elms = FixedArray::cast(elms_obj); | |
| 641 JSArray* array = JSArray::cast(receiver); | |
| 642 ASSERT(array->HasFastElements()); | |
| 643 | |
| 644 len = Smi::cast(array->length())->value(); | |
| 645 } else { | |
| 646 // Array.slice(arguments, ...) is quite a common idiom (notably more | |
| 647 // than 50% of invocations in Web apps). Treat it in C++ as well. | |
| 648 Map* arguments_map = | |
| 649 isolate->context()->global_context()->arguments_boilerplate()->map(); | |
| 650 | |
| 651 bool is_arguments_object_with_fast_elements = | |
| 652 receiver->IsJSObject() | |
| 653 && JSObject::cast(receiver)->map() == arguments_map | |
| 654 && JSObject::cast(receiver)->HasFastElements(); | |
| 655 if (!is_arguments_object_with_fast_elements) { | |
| 656 return CallJsBuiltin(isolate, "ArraySlice", args); | |
| 657 } | |
| 658 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); | |
| 659 len = elms->length(); | |
| 660 #ifdef DEBUG | |
| 661 // Arguments object by construction should have no holes, check it. | |
| 662 if (FLAG_enable_slow_asserts) { | |
| 663 for (int i = 0; i < len; i++) { | |
| 664 ASSERT(elms->get(i) != heap->the_hole_value()); | |
| 665 } | |
| 666 } | |
| 667 #endif | |
| 668 } | 669 } |
| 669 } | 670 } |
| 670 ASSERT(len >= 0); | 671 ASSERT(len >= 0); |
| 671 int n_arguments = args.length() - 1; | 672 int n_arguments = args.length() - 1; |
| 672 | 673 |
| 673 // Note carefully choosen defaults---if argument is missing, | 674 // Note carefully choosen defaults---if argument is missing, |
| 674 // it's undefined which gets converted to 0 for relative_start | 675 // it's undefined which gets converted to 0 for relative_start |
| 675 // and to len for relative_end. | 676 // and to len for relative_end. |
| 676 int relative_start = 0; | 677 int relative_start = 0; |
| 677 int relative_end = len; | 678 int relative_end = len; |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 if (entry->contains(pc)) { | 1669 if (entry->contains(pc)) { |
| 1669 return names_[i]; | 1670 return names_[i]; |
| 1670 } | 1671 } |
| 1671 } | 1672 } |
| 1672 } | 1673 } |
| 1673 return NULL; | 1674 return NULL; |
| 1674 } | 1675 } |
| 1675 | 1676 |
| 1676 | 1677 |
| 1677 } } // namespace v8::internal | 1678 } } // namespace v8::internal |
| OLD | NEW |