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

Unified Diff: src/runtime/runtime-array.cc

Issue 2540593003: Move desugaring of super calls with trailing spread to one runtime call. (Closed)
Patch Set: Address comments Created 4 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 side-by-side diff with in-line comments
Download patch
« src/interpreter/bytecode-generator.cc ('K') | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-array.cc
diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc
index 51b8cb956b171519d16c3d96b941782b9c4a3cd2..9197d2dc833354f92e1939c1426ab7a3d97d4434 100644
--- a/src/runtime/runtime-array.cc
+++ b/src/runtime/runtime-array.cc
@@ -635,11 +635,9 @@ RUNTIME_FUNCTION(Runtime_ArrayIndexOf) {
return Smi::FromInt(-1);
}
-RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) {
- HandleScope scope(isolate);
- DCHECK_EQ(1, args.length());
- CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0);
+namespace {
+bool MustIterate(Isolate* isolate, Handle<Object> spread) {
if (spread->IsJSArray()) {
// Check that the spread arg has fast elements
Handle<JSArray> spread_array = Handle<JSArray>::cast(spread);
@@ -653,19 +651,31 @@ RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) {
// If IsArrayIteratorLookupChainIntact(), then we know that the initial
// ArrayIterator is being used. If the map of the prototype has changed,
// then take the slow path.
-
if (isolate->is_initial_array_prototype(array_proto) &&
isolate->IsArrayIteratorLookupChainIntact() &&
isolate->is_initial_array_iterator_prototype_map(iterator_map)) {
if (IsFastPackedElementsKind(array_kind)) {
- return *spread;
+ return false;
}
if (IsFastHoleyElementsKind(array_kind) &&
isolate->IsFastArrayConstructorPrototypeChainIntact()) {
- return *spread;
+ return false;
}
}
}
+ return true;
+}
+
+} // namespace
+
+RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) {
+ HandleScope scope(isolate);
+ DCHECK_EQ(1, args.length());
+ CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0);
+
+ if (!MustIterate(isolate, spread)) {
+ return *spread;
+ }
Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
@@ -678,5 +688,36 @@ RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) {
return *spreaded;
}
+RUNTIME_FUNCTION(Runtime_SpreadIterablePrepareVarargs) {
+ HandleScope scope(isolate);
+ DCHECK_LE(2, args.length());
+ CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1);
+
+ Handle<FixedArray> result = isolate->factory()->NewFixedArray(args.length());
+ for (int i = 0; i < args.length() - 1; i++) {
+ result->set(i, *args.at<Object>(i));
+ }
+ // Iterate over the spread if we need to.
+ if (MustIterate(isolate, spread)) {
+ Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, spread,
+ Execution::Call(isolate, spread_iterable_function,
+ isolate->factory()->undefined_value(), 1, &spread));
+ }
+ JSArray* spread_array = JSArray::cast(*spread);
+ uint32_t length;
+ CHECK(spread_array->length()->ToArrayIndex(&length));
+ for (uint32_t i = 0; i < length; i++) {
+ LookupIterator it(isolate, spread, i);
+ result = FixedArray::SetAndGrow(result, args.length() - 1 + i,
+ spread_array->GetDataProperty(&it));
+ }
+
+ Handle<JSArray> r = isolate->factory()->NewJSArrayWithElements(
+ result, FAST_ELEMENTS, args.length() - 1 + length);
+ return *r;
+}
+
} // namespace internal
} // namespace v8
« src/interpreter/bytecode-generator.cc ('K') | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698