Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(814)

Side by Side Diff: src/builtins.cc

Issue 11369151: Minimal implementation and tests of observable array methods (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 { MaybeObject* maybe_elms_obj = 503 { MaybeObject* maybe_elms_obj =
504 EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 1); 504 EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 1);
505 if (maybe_elms_obj == NULL) { 505 if (maybe_elms_obj == NULL) {
506 return CallJsBuiltin(isolate, "ArrayPush", args); 506 return CallJsBuiltin(isolate, "ArrayPush", args);
507 } 507 }
508 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; 508 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
509 } 509 }
510 FixedArray* elms = FixedArray::cast(elms_obj); 510 FixedArray* elms = FixedArray::cast(elms_obj);
511 JSArray* array = JSArray::cast(receiver); 511 JSArray* array = JSArray::cast(receiver);
512 512
513 if (FLAG_harmony_observation && array->map()->is_observed()) {
514 return CallJsBuiltin(isolate, "ArrayPush", args);
515 }
516
513 int len = Smi::cast(array->length())->value(); 517 int len = Smi::cast(array->length())->value();
514 int to_add = args.length() - 1; 518 int to_add = args.length() - 1;
515 if (to_add == 0) { 519 if (to_add == 0) {
516 return Smi::FromInt(len); 520 return Smi::FromInt(len);
517 } 521 }
518 // Currently fixed arrays cannot grow too big, so 522 // Currently fixed arrays cannot grow too big, so
519 // we should never hit this case. 523 // we should never hit this case.
520 ASSERT(to_add <= (Smi::kMaxValue - len)); 524 ASSERT(to_add <= (Smi::kMaxValue - len));
521 525
522 int new_length = len + to_add; 526 int new_length = len + to_add;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 Object* receiver = *args.receiver(); 563 Object* receiver = *args.receiver();
560 Object* elms_obj; 564 Object* elms_obj;
561 { MaybeObject* maybe_elms_obj = 565 { MaybeObject* maybe_elms_obj =
562 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); 566 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0);
563 if (maybe_elms_obj == NULL) return CallJsBuiltin(isolate, "ArrayPop", args); 567 if (maybe_elms_obj == NULL) return CallJsBuiltin(isolate, "ArrayPop", args);
564 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; 568 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
565 } 569 }
566 FixedArray* elms = FixedArray::cast(elms_obj); 570 FixedArray* elms = FixedArray::cast(elms_obj);
567 JSArray* array = JSArray::cast(receiver); 571 JSArray* array = JSArray::cast(receiver);
568 572
573 if (FLAG_harmony_observation && array->map()->is_observed()) {
574 return CallJsBuiltin(isolate, "ArrayPop", args);
575 }
576
569 int len = Smi::cast(array->length())->value(); 577 int len = Smi::cast(array->length())->value();
570 if (len == 0) return heap->undefined_value(); 578 if (len == 0) return heap->undefined_value();
571 579
572 // Get top element 580 // Get top element
573 MaybeObject* top = elms->get(len - 1); 581 Object* top = elms->get(len - 1);
574 582
575 // Set the length. 583 // Set the length.
576 array->set_length(Smi::FromInt(len - 1)); 584 array->set_length(Smi::FromInt(len - 1));
577 585
578 if (!top->IsTheHole()) { 586 if (!top->IsTheHole()) {
579 // Delete the top element. 587 // Delete the top element.
580 elms->set_the_hole(len - 1); 588 elms->set_the_hole(len - 1);
581 return top; 589 return top;
582 } 590 }
583 591
584 top = array->GetPrototype()->GetElement(len - 1); 592 return array->GetPrototype()->GetElement(len - 1);
585
586 return top;
587 } 593 }
588 594
589 595
590 BUILTIN(ArrayShift) { 596 BUILTIN(ArrayShift) {
591 Heap* heap = isolate->heap(); 597 Heap* heap = isolate->heap();
592 Object* receiver = *args.receiver(); 598 Object* receiver = *args.receiver();
593 Object* elms_obj; 599 Object* elms_obj;
594 { MaybeObject* maybe_elms_obj = 600 { MaybeObject* maybe_elms_obj =
595 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); 601 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0);
596 if (maybe_elms_obj == NULL) 602 if (maybe_elms_obj == NULL)
597 return CallJsBuiltin(isolate, "ArrayShift", args); 603 return CallJsBuiltin(isolate, "ArrayShift", args);
598 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; 604 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
599 } 605 }
600 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { 606 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) {
601 return CallJsBuiltin(isolate, "ArrayShift", args); 607 return CallJsBuiltin(isolate, "ArrayShift", args);
602 } 608 }
603 FixedArray* elms = FixedArray::cast(elms_obj); 609 FixedArray* elms = FixedArray::cast(elms_obj);
604 JSArray* array = JSArray::cast(receiver); 610 JSArray* array = JSArray::cast(receiver);
605 ASSERT(array->HasFastSmiOrObjectElements()); 611 ASSERT(array->HasFastSmiOrObjectElements());
606 612
613 if (FLAG_harmony_observation && array->map()->is_observed()) {
614 return CallJsBuiltin(isolate, "ArrayShift", args);
615 }
616
607 int len = Smi::cast(array->length())->value(); 617 int len = Smi::cast(array->length())->value();
608 if (len == 0) return heap->undefined_value(); 618 if (len == 0) return heap->undefined_value();
609 619
610 // Get first element 620 // Get first element
611 Object* first = elms->get(0); 621 Object* first = elms->get(0);
612 if (first->IsTheHole()) { 622 if (first->IsTheHole()) {
613 first = heap->undefined_value(); 623 first = heap->undefined_value();
614 } 624 }
615 625
616 if (!heap->lo_space()->Contains(elms)) { 626 if (!heap->lo_space()->Contains(elms)) {
(...skipping 22 matching lines...) Expand all
639 return CallJsBuiltin(isolate, "ArrayUnshift", args); 649 return CallJsBuiltin(isolate, "ArrayUnshift", args);
640 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; 650 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
641 } 651 }
642 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { 652 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) {
643 return CallJsBuiltin(isolate, "ArrayUnshift", args); 653 return CallJsBuiltin(isolate, "ArrayUnshift", args);
644 } 654 }
645 FixedArray* elms = FixedArray::cast(elms_obj); 655 FixedArray* elms = FixedArray::cast(elms_obj);
646 JSArray* array = JSArray::cast(receiver); 656 JSArray* array = JSArray::cast(receiver);
647 ASSERT(array->HasFastSmiOrObjectElements()); 657 ASSERT(array->HasFastSmiOrObjectElements());
648 658
659 if (FLAG_harmony_observation && array->map()->is_observed()) {
660 return CallJsBuiltin(isolate, "ArrayUnshift", args);
661 }
662
649 int len = Smi::cast(array->length())->value(); 663 int len = Smi::cast(array->length())->value();
650 int to_add = args.length() - 1; 664 int to_add = args.length() - 1;
651 int new_length = len + to_add; 665 int new_length = len + to_add;
652 // Currently fixed arrays cannot grow too big, so 666 // Currently fixed arrays cannot grow too big, so
653 // we should never hit this case. 667 // we should never hit this case.
654 ASSERT(to_add <= (Smi::kMaxValue - len)); 668 ASSERT(to_add <= (Smi::kMaxValue - len));
655 669
656 MaybeObject* maybe_object = 670 MaybeObject* maybe_object =
657 array->EnsureCanContainElements(&args, 1, to_add, 671 array->EnsureCanContainElements(&args, 1, to_add,
658 DONT_ALLOW_DOUBLE_ELEMENTS); 672 DONT_ALLOW_DOUBLE_ELEMENTS);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 return CallJsBuiltin(isolate, "ArraySplice", args); 809 return CallJsBuiltin(isolate, "ArraySplice", args);
796 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; 810 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
797 } 811 }
798 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { 812 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) {
799 return CallJsBuiltin(isolate, "ArraySplice", args); 813 return CallJsBuiltin(isolate, "ArraySplice", args);
800 } 814 }
801 FixedArray* elms = FixedArray::cast(elms_obj); 815 FixedArray* elms = FixedArray::cast(elms_obj);
802 JSArray* array = JSArray::cast(receiver); 816 JSArray* array = JSArray::cast(receiver);
803 ASSERT(array->HasFastSmiOrObjectElements()); 817 ASSERT(array->HasFastSmiOrObjectElements());
804 818
819 if (FLAG_harmony_observation && array->map()->is_observed()) {
820 return CallJsBuiltin(isolate, "ArraySplice", args);
821 }
822
805 int len = Smi::cast(array->length())->value(); 823 int len = Smi::cast(array->length())->value();
806 824
807 int n_arguments = args.length() - 1; 825 int n_arguments = args.length() - 1;
808 826
809 int relative_start = 0; 827 int relative_start = 0;
810 if (n_arguments > 0) { 828 if (n_arguments > 0) {
811 Object* arg1 = args[1]; 829 Object* arg1 = args[1];
812 if (arg1->IsSmi()) { 830 if (arg1->IsSmi()) {
813 relative_start = Smi::cast(arg1)->value(); 831 relative_start = Smi::cast(arg1)->value();
814 } else if (!arg1->IsUndefined()) { 832 } else if (!arg1->IsUndefined()) {
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 return Handle<Code>(code_address); \ 1734 return Handle<Code>(code_address); \
1717 } 1735 }
1718 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1736 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1719 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1737 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1720 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1738 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1721 #undef DEFINE_BUILTIN_ACCESSOR_C 1739 #undef DEFINE_BUILTIN_ACCESSOR_C
1722 #undef DEFINE_BUILTIN_ACCESSOR_A 1740 #undef DEFINE_BUILTIN_ACCESSOR_A
1723 1741
1724 1742
1725 } } // namespace v8::internal 1743 } } // namespace v8::internal
OLDNEW
« src/array.js ('K') | « src/array.js ('k') | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698