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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 ASSERT(array_proto->GetPrototype()->IsNull()); | 373 ASSERT(array_proto->GetPrototype()->IsNull()); |
374 return true; | 374 return true; |
375 } | 375 } |
376 | 376 |
377 | 377 |
378 MUST_USE_RESULT | 378 MUST_USE_RESULT |
379 static inline MaybeObject* EnsureJSArrayWithWritableFastElements( | 379 static inline MaybeObject* EnsureJSArrayWithWritableFastElements( |
380 Object* receiver) { | 380 Object* receiver) { |
381 if (!receiver->IsJSArray()) return NULL; | 381 if (!receiver->IsJSArray()) return NULL; |
382 JSArray* array = JSArray::cast(receiver); | 382 JSArray* array = JSArray::cast(receiver); |
383 HeapObject* elms = HeapObject::cast(array->elements()); | 383 HeapObject* elms = array->elements(); |
384 if (elms->map() == Heap::fixed_array_map()) return elms; | 384 if (elms->map() == Heap::fixed_array_map()) return elms; |
385 if (elms->map() == Heap::fixed_cow_array_map()) { | 385 if (elms->map() == Heap::fixed_cow_array_map()) { |
386 return array->EnsureWritableFastElements(); | 386 return array->EnsureWritableFastElements(); |
387 } | 387 } |
388 return NULL; | 388 return NULL; |
389 } | 389 } |
390 | 390 |
391 | 391 |
392 static inline bool IsJSArrayFastElementMovingAllowed(JSArray* receiver) { | 392 static inline bool IsJSArrayFastElementMovingAllowed(JSArray* receiver) { |
393 Context* global_context = Top::context()->global_context(); | 393 Context* global_context = Top::context()->global_context(); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 // Set the length. | 606 // Set the length. |
607 array->set_length(Smi::FromInt(new_length)); | 607 array->set_length(Smi::FromInt(new_length)); |
608 return Smi::FromInt(new_length); | 608 return Smi::FromInt(new_length); |
609 } | 609 } |
610 | 610 |
611 | 611 |
612 BUILTIN(ArraySlice) { | 612 BUILTIN(ArraySlice) { |
613 Object* receiver = *args.receiver(); | 613 Object* receiver = *args.receiver(); |
614 FixedArray* elms; | 614 FixedArray* elms; |
615 int len = -1; | 615 int len = -1; |
616 { MaybeObject* maybe_elms_obj = | 616 if (receiver->IsJSArray()) { |
617 EnsureJSArrayWithWritableFastElements(receiver); | 617 JSArray* array = JSArray::cast(receiver); |
618 Object* elms_obj; | 618 if (!array->HasFastElements() || |
619 if (maybe_elms_obj != NULL && maybe_elms_obj->ToObject(&elms_obj)) { | 619 !IsJSArrayFastElementMovingAllowed(array)) { |
620 if (!IsJSArrayFastElementMovingAllowed(JSArray::cast(receiver))) { | 620 return CallJsBuiltin("ArraySlice", args); |
621 return CallJsBuiltin("ArraySlice", args); | 621 } |
| 622 |
| 623 elms = FixedArray::cast(array->elements()); |
| 624 len = Smi::cast(array->length())->value(); |
| 625 } else { |
| 626 // Array.slice(arguments, ...) is quite a common idiom (notably more |
| 627 // than 50% of invocations in Web apps). Treat it in C++ as well. |
| 628 Map* arguments_map = |
| 629 Top::context()->global_context()->arguments_boilerplate()->map(); |
| 630 |
| 631 bool is_arguments_object_with_fast_elements = |
| 632 receiver->IsJSObject() |
| 633 && JSObject::cast(receiver)->map() == arguments_map |
| 634 && JSObject::cast(receiver)->HasFastElements(); |
| 635 if (!is_arguments_object_with_fast_elements) { |
| 636 return CallJsBuiltin("ArraySlice", args); |
| 637 } |
| 638 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); |
| 639 len = elms->length(); |
| 640 #ifdef DEBUG |
| 641 // Arguments object by construction should have no holes, check it. |
| 642 if (FLAG_enable_slow_asserts) { |
| 643 for (int i = 0; i < len; i++) { |
| 644 ASSERT(elms->get(i) != Heap::the_hole_value()); |
622 } | 645 } |
623 elms = FixedArray::cast(elms_obj); | 646 } |
624 JSArray* array = JSArray::cast(receiver); | |
625 ASSERT(array->HasFastElements()); | |
626 | |
627 len = Smi::cast(array->length())->value(); | |
628 } else { | |
629 // Array.slice(arguments, ...) is quite a common idiom (notably more | |
630 // than 50% of invocations in Web apps). Treat it in C++ as well. | |
631 Map* arguments_map = | |
632 Top::context()->global_context()->arguments_boilerplate()->map(); | |
633 | |
634 bool is_arguments_object_with_fast_elements = | |
635 receiver->IsJSObject() | |
636 && JSObject::cast(receiver)->map() == arguments_map | |
637 && JSObject::cast(receiver)->HasFastElements(); | |
638 if (!is_arguments_object_with_fast_elements) { | |
639 return CallJsBuiltin("ArraySlice", args); | |
640 } | |
641 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); | |
642 len = elms->length(); | |
643 #ifdef DEBUG | |
644 // Arguments object by construction should have no holes, check it. | |
645 if (FLAG_enable_slow_asserts) { | |
646 for (int i = 0; i < len; i++) { | |
647 ASSERT(elms->get(i) != Heap::the_hole_value()); | |
648 } | |
649 } | |
650 #endif | 647 #endif |
651 } | |
652 } | 648 } |
653 ASSERT(len >= 0); | 649 ASSERT(len >= 0); |
654 int n_arguments = args.length() - 1; | 650 int n_arguments = args.length() - 1; |
655 | 651 |
656 // Note carefully choosen defaults---if argument is missing, | 652 // Note carefully choosen defaults---if argument is missing, |
657 // it's undefined which gets converted to 0 for relative_start | 653 // it's undefined which gets converted to 0 for relative_start |
658 // and to len for relative_end. | 654 // and to len for relative_end. |
659 int relative_start = 0; | 655 int relative_start = 0; |
660 int relative_end = len; | 656 int relative_end = len; |
661 if (n_arguments > 0) { | 657 if (n_arguments > 0) { |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 if (entry->contains(pc)) { | 1597 if (entry->contains(pc)) { |
1602 return names_[i]; | 1598 return names_[i]; |
1603 } | 1599 } |
1604 } | 1600 } |
1605 } | 1601 } |
1606 return NULL; | 1602 return NULL; |
1607 } | 1603 } |
1608 | 1604 |
1609 | 1605 |
1610 } } // namespace v8::internal | 1606 } } // namespace v8::internal |
OLD | NEW |