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

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

Issue 2541113004: [Ignition/turbo] Add a NewWithSpread bytecode. (Closed)
Patch Set: Add todo 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
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-classes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element_k, 623 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element_k,
624 Object::GetProperty(&it)); 624 Object::GetProperty(&it));
625 if (search_element->StrictEquals(*element_k)) { 625 if (search_element->StrictEquals(*element_k)) {
626 return *index_obj; 626 return *index_obj;
627 } 627 }
628 } 628 }
629 } 629 }
630 return Smi::FromInt(-1); 630 return Smi::FromInt(-1);
631 } 631 }
632 632
633 namespace {
634
635 bool MustIterate(Isolate* isolate, Handle<Object> spread) {
636 if (spread->IsJSArray()) {
637 // Check that the spread arg has fast elements
638 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread);
639 ElementsKind array_kind = spread_array->GetElementsKind();
640
641 // And that it has the orignal ArrayPrototype
642 JSObject* array_proto = JSObject::cast(spread_array->map()->prototype());
643 Map* iterator_map = isolate->initial_array_iterator_prototype()->map();
644
645 // Check that the iterator acts as expected.
646 // If IsArrayIteratorLookupChainIntact(), then we know that the initial
647 // ArrayIterator is being used. If the map of the prototype has changed,
648 // then take the slow path.
649 if (isolate->is_initial_array_prototype(array_proto) &&
650 isolate->IsArrayIteratorLookupChainIntact() &&
651 isolate->is_initial_array_iterator_prototype_map(iterator_map)) {
652 if (IsFastPackedElementsKind(array_kind)) {
653 return false;
654 }
655 if (IsFastHoleyElementsKind(array_kind) &&
656 isolate->IsFastArrayConstructorPrototypeChainIntact()) {
657 return false;
658 }
659 }
660 }
661 return true;
662 }
663
664 } // namespace
665 633
666 RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) { 634 RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) {
667 HandleScope scope(isolate); 635 HandleScope scope(isolate);
668 DCHECK_EQ(1, args.length()); 636 DCHECK_EQ(1, args.length());
669 CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0); 637 CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0);
670 638
671 // Iterate over the spread if we need to. 639 // Iterate over the spread if we need to.
672 if (MustIterate(isolate, spread)) { 640 if (spread->IterationHasObservableEffects()) {
673 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); 641 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
674 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 642 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
675 isolate, spread, 643 isolate, spread,
676 Execution::Call(isolate, spread_iterable_function, 644 Execution::Call(isolate, spread_iterable_function,
677 isolate->factory()->undefined_value(), 1, &spread)); 645 isolate->factory()->undefined_value(), 1, &spread));
678 } 646 }
679 647
680 return *spread; 648 return *spread;
681 } 649 }
682 650
683 RUNTIME_FUNCTION(Runtime_SpreadIterablePrepareVarargs) {
684 HandleScope scope(isolate);
685 DCHECK_LE(1, args.length());
686 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1);
687
688 // Iterate over the spread if we need to.
689 if (MustIterate(isolate, spread)) {
690 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
691 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
692 isolate, spread,
693 Execution::Call(isolate, spread_iterable_function,
694 isolate->factory()->undefined_value(), 1, &spread));
695 }
696
697 if (args.length() == 1) return *spread;
698
699 JSArray* spread_array = JSArray::cast(*spread);
700 uint32_t spread_length;
701 CHECK(spread_array->length()->ToArrayIndex(&spread_length));
702
703 // Append each of the individual args to the result.
704 int result_length = args.length() - 1 + spread_length;
705 Handle<FixedArray> result = isolate->factory()->NewFixedArray(result_length);
706 for (int i = 0; i < args.length() - 1; i++) {
707 result->set(i, *args.at<Object>(i));
708 }
709
710 // Append element of the spread to the result.
711 for (uint32_t i = 0; i < spread_length; i++) {
712 LookupIterator it(isolate, spread, i);
713 Handle<Object> element = spread_array->GetDataProperty(&it);
714 result->set(args.length() - 1 + i, *element);
715 }
716
717 Handle<JSArray> r = isolate->factory()->NewJSArrayWithElements(
718 result, FAST_ELEMENTS, result_length);
719 return *r;
720 }
721
722 } // namespace internal 651 } // namespace internal
723 } // namespace v8 652 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-classes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698