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

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

Issue 2629363002: [Ignition/turbo] Add a CallWithSpread bytecode. (Closed)
Patch Set: reparent on the bytecode CL Created 3 years, 11 months 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
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/interpreter/bytecode_expectations/CallAndSpread.golden » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-classes.cc
diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc
index 9398586de5fed40711c5be4e2d8a090564ed0da9..a0fb019e83b0dc2cd98db81ffda47661363e9fc1 100644
--- a/src/runtime/runtime-classes.cc
+++ b/src/runtime/runtime-classes.cc
@@ -459,5 +459,48 @@ RUNTIME_FUNCTION(Runtime_GetSuperConstructor) {
return prototype;
}
+RUNTIME_FUNCTION(Runtime_CallWithSpread) {
+ HandleScope scope(isolate);
+ DCHECK_LE(3, args.length());
+ CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
+
+ int function_argc = args.length() - 2;
+ CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1);
+
+ // Iterate over the spread if we need to.
+ if (spread->IterationHasObservableEffects()) {
+ 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));
+ }
+
+ uint32_t spread_length;
+ Handle<JSArray> spread_array = Handle<JSArray>::cast(spread);
+ CHECK(spread_array->length()->ToArrayIndex(&spread_length));
+ int result_length = function_argc - 1 + spread_length;
+ ScopedVector<Handle<Object>> function_args(result_length);
+
+ // Append each of the individual args to the result.
+ for (int i = 0; i < function_argc - 1; i++) {
+ function_args[i] = args.at<Object>(2 + i);
+ }
+
+ // Append element of the spread to the result.
+ ElementsAccessor* accessor = spread_array->GetElementsAccessor();
+ for (uint32_t i = 0; i < spread_length; i++) {
+ DCHECK(accessor->HasElement(spread_array, i));
+ Handle<Object> element = accessor->Get(spread_array, i);
+ function_args[function_argc - 1 + i] = element;
+ }
+
+ // Call the function.
+ RETURN_RESULT_OR_FAILURE(
+ isolate, Execution::Call(isolate, callable, receiver, result_length,
+ function_args.start()));
+}
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/interpreter/bytecode_expectations/CallAndSpread.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698