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

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

Issue 2629363002: [Ignition/turbo] Add a CallWithSpread bytecode. (Closed)
Patch Set: Remove case for 1 arg only from PrepareSpreadArguments 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 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 <stdlib.h> 7 #include <stdlib.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 HandleScope scope(isolate); 455 HandleScope scope(isolate);
456 return ThrowNotSuperConstructor(isolate, handle(prototype, isolate), 456 return ThrowNotSuperConstructor(isolate, handle(prototype, isolate),
457 handle(active_function, isolate)); 457 handle(active_function, isolate));
458 } 458 }
459 return prototype; 459 return prototype;
460 } 460 }
461 461
462 RUNTIME_FUNCTION(Runtime_NewWithSpread) { 462 RUNTIME_FUNCTION(Runtime_NewWithSpread) {
463 HandleScope scope(isolate); 463 HandleScope scope(isolate);
464 DCHECK_LE(3, args.length()); 464 DCHECK_LE(3, args.length());
465 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0); 465 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 0);
466 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1); 466 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1);
467 467
468 int constructor_argc = args.length() - 2; 468 int constructor_argc = args.length() - 2;
469 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); 469 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1);
470 470
471 // Iterate over the spread if we need to. 471 // Iterate over the spread if we need to.
472 if (spread->IterationHasObservableEffects()) { 472 if (spread->IterationHasObservableEffects()) {
473 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); 473 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
474 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 474 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
475 isolate, spread, 475 isolate, spread,
(...skipping 19 matching lines...) Expand all
495 Handle<Object> element = accessor->Get(spread_array, i); 495 Handle<Object> element = accessor->Get(spread_array, i);
496 construct_args[constructor_argc - 1 + i] = element; 496 construct_args[constructor_argc - 1 + i] = element;
497 } 497 }
498 498
499 // Call the constructor. 499 // Call the constructor.
500 RETURN_RESULT_OR_FAILURE( 500 RETURN_RESULT_OR_FAILURE(
501 isolate, Execution::New(isolate, constructor, new_target, result_length, 501 isolate, Execution::New(isolate, constructor, new_target, result_length,
502 construct_args.start())); 502 construct_args.start()));
503 } 503 }
504 504
505 RUNTIME_FUNCTION(Runtime_CallWithSpread) {
506 HandleScope scope(isolate);
507 DCHECK_LE(3, args.length());
508 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0);
509 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
510
511 int function_argc = args.length() - 2;
512 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1);
513
514 // Iterate over the spread if we need to.
515 if (spread->IterationHasObservableEffects()) {
516 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
517 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
518 isolate, spread,
519 Execution::Call(isolate, spread_iterable_function,
520 isolate->factory()->undefined_value(), 1, &spread));
521 }
522
523 uint32_t spread_length;
524 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread);
525 CHECK(spread_array->length()->ToArrayIndex(&spread_length));
526 int result_length = function_argc - 1 + spread_length;
527 ScopedVector<Handle<Object>> function_args(result_length);
528
529 // Append each of the individual args to the result.
530 for (int i = 0; i < function_argc - 1; i++) {
531 function_args[i] = args.at<Object>(2 + i);
532 }
533
534 // Append element of the spread to the result.
535 ElementsAccessor* accessor = spread_array->GetElementsAccessor();
536 for (uint32_t i = 0; i < spread_length; i++) {
537 DCHECK(accessor->HasElement(spread_array, i));
538 Handle<Object> element = accessor->Get(spread_array, i);
539 function_args[function_argc - 1 + i] = element;
540 }
541
542 // Call the function.
543 RETURN_RESULT_OR_FAILURE(
544 isolate, Execution::Call(isolate, callable, receiver, result_length,
545 function_args.start()));
546 }
547
505 } // namespace internal 548 } // namespace internal
506 } // namespace v8 549 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698