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

Side by Side Diff: src/runtime/runtime-array.cc

Issue 2540593003: Move desugaring of super calls with trailing spread to one runtime call. (Closed)
Patch Set: Simplify parser files by removing PrepareSpreadArguments from preparser Created 4 years 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/elements.h" 10 #include "src/elements.h"
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element_k, 628 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element_k,
629 Object::GetProperty(&it)); 629 Object::GetProperty(&it));
630 if (search_element->StrictEquals(*element_k)) { 630 if (search_element->StrictEquals(*element_k)) {
631 return *index_obj; 631 return *index_obj;
632 } 632 }
633 } 633 }
634 } 634 }
635 return Smi::FromInt(-1); 635 return Smi::FromInt(-1);
636 } 636 }
637 637
638 RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) { 638 namespace {
639 HandleScope scope(isolate);
640 DCHECK_EQ(1, args.length());
641 CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0);
642 639
640 bool MustIterate(Isolate* isolate, Handle<Object> spread) {
643 if (spread->IsJSArray()) { 641 if (spread->IsJSArray()) {
644 // Check that the spread arg has fast elements 642 // Check that the spread arg has fast elements
645 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread); 643 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread);
646 ElementsKind array_kind = spread_array->GetElementsKind(); 644 ElementsKind array_kind = spread_array->GetElementsKind();
647 645
648 // And that it has the orignal ArrayPrototype 646 // And that it has the orignal ArrayPrototype
649 JSObject* array_proto = JSObject::cast(spread_array->map()->prototype()); 647 JSObject* array_proto = JSObject::cast(spread_array->map()->prototype());
650 Map* iterator_map = isolate->initial_array_iterator_prototype()->map(); 648 Map* iterator_map = isolate->initial_array_iterator_prototype()->map();
651 649
652 // Check that the iterator acts as expected. 650 // Check that the iterator acts as expected.
653 // If IsArrayIteratorLookupChainIntact(), then we know that the initial 651 // If IsArrayIteratorLookupChainIntact(), then we know that the initial
654 // ArrayIterator is being used. If the map of the prototype has changed, 652 // ArrayIterator is being used. If the map of the prototype has changed,
655 // then take the slow path. 653 // then take the slow path.
656
657 if (isolate->is_initial_array_prototype(array_proto) && 654 if (isolate->is_initial_array_prototype(array_proto) &&
658 isolate->IsArrayIteratorLookupChainIntact() && 655 isolate->IsArrayIteratorLookupChainIntact() &&
659 isolate->is_initial_array_iterator_prototype_map(iterator_map)) { 656 isolate->is_initial_array_iterator_prototype_map(iterator_map)) {
660 if (IsFastPackedElementsKind(array_kind)) { 657 if (IsFastPackedElementsKind(array_kind)) {
661 return *spread; 658 return false;
662 } 659 }
663 if (IsFastHoleyElementsKind(array_kind) && 660 if (IsFastHoleyElementsKind(array_kind) &&
664 isolate->IsFastArrayConstructorPrototypeChainIntact()) { 661 isolate->IsFastArrayConstructorPrototypeChainIntact()) {
665 return *spread; 662 return false;
666 } 663 }
667 } 664 }
668 } 665 }
666 return true;
667 }
669 668
670 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); 669 } // namespace
671 670
672 Handle<Object> spreaded; 671 RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) {
673 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 672 HandleScope scope(isolate);
674 isolate, spreaded, 673 DCHECK_EQ(1, args.length());
675 Execution::Call(isolate, spread_iterable_function, 674 CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0);
676 isolate->factory()->undefined_value(), 1, &spread));
677 675
678 return *spreaded; 676 // Iterate over the spread if we need to.
677 if (MustIterate(isolate, spread)) {
678 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
679 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
680 isolate, spread,
681 Execution::Call(isolate, spread_iterable_function,
682 isolate->factory()->undefined_value(), 1, &spread));
683 }
684
685 return *spread;
686 }
687
688 RUNTIME_FUNCTION(Runtime_SpreadIterablePrepareVarargs) {
689 HandleScope scope(isolate);
690 DCHECK_LE(1, args.length());
691 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1);
692
693 // Iterate over the spread if we need to.
694 if (MustIterate(isolate, spread)) {
695 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
696 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
697 isolate, spread,
698 Execution::Call(isolate, spread_iterable_function,
699 isolate->factory()->undefined_value(), 1, &spread));
700 }
701
702 if (args.length() == 1) return *spread;
703
704 JSArray* spread_array = JSArray::cast(*spread);
705 uint32_t spread_length;
706 CHECK(spread_array->length()->ToArrayIndex(&spread_length));
707
708 // Append each of the individual args to the result.
709 int result_length = args.length() - 1 + spread_length;
710 Handle<FixedArray> result = isolate->factory()->NewFixedArray(result_length);
711 for (int i = 0; i < args.length() - 1; i++) {
712 result->set(i, *args.at<Object>(i));
713 }
714
715 // Append element of the spread to the result.
716 for (uint32_t i = 0; i < spread_length; i++) {
717 LookupIterator it(isolate, spread, i);
718 result->set(args.length() - 1 + i, *spread_array->GetDataProperty(&it));
719 }
720
721 Handle<JSArray> r = isolate->factory()->NewJSArrayWithElements(
722 result, FAST_ELEMENTS, result_length);
723 return *r;
679 } 724 }
680 725
681 } // namespace internal 726 } // namespace internal
682 } // namespace v8 727 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698