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

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

Issue 816913003: Implement ES6 rest parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix typo in ARM port Created 5 years, 10 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
« no previous file with comments | « src/runtime/runtime.h ('k') | src/scopeinfo.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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/frames-inl.h" 9 #include "src/frames-inl.h"
10 #include "src/runtime/runtime-utils.h" 10 #include "src/runtime/runtime-utils.h"
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 350
351 return *value; 351 return *value;
352 } 352 }
353 353
354 354
355 static Handle<JSObject> NewSloppyArguments(Isolate* isolate, 355 static Handle<JSObject> NewSloppyArguments(Isolate* isolate,
356 Handle<JSFunction> callee, 356 Handle<JSFunction> callee,
357 Object** parameters, 357 Object** parameters,
358 int argument_count) { 358 int argument_count) {
359 CHECK(!IsSubclassConstructor(callee->shared()->kind())); 359 CHECK(!IsSubclassConstructor(callee->shared()->kind()));
360 DCHECK(callee->is_simple_parameter_list());
360 Handle<JSObject> result = 361 Handle<JSObject> result =
361 isolate->factory()->NewArgumentsObject(callee, argument_count); 362 isolate->factory()->NewArgumentsObject(callee, argument_count);
362 363
363 // Allocate the elements if needed. 364 // Allocate the elements if needed.
364 int parameter_count = callee->shared()->internal_formal_parameter_count(); 365 int parameter_count = callee->shared()->internal_formal_parameter_count();
365 if (argument_count > 0) { 366 if (argument_count > 0) {
366 if (parameter_count > 0) { 367 if (parameter_count > 0) {
367 int mapped_count = Min(argument_count, parameter_count); 368 int mapped_count = Min(argument_count, parameter_count);
368 Handle<FixedArray> parameter_map = 369 Handle<FixedArray> parameter_map =
369 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED); 370 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } else { 414 } else {
414 // The context index goes in the parameter map with a hole in the 415 // The context index goes in the parameter map with a hole in the
415 // arguments array. 416 // arguments array.
416 int context_index = -1; 417 int context_index = -1;
417 for (int j = 0; j < context_local_count; ++j) { 418 for (int j = 0; j < context_local_count; ++j) {
418 if (scope_info->ContextLocalName(j) == *name) { 419 if (scope_info->ContextLocalName(j) == *name) {
419 context_index = j; 420 context_index = j;
420 break; 421 break;
421 } 422 }
422 } 423 }
424
423 DCHECK(context_index >= 0); 425 DCHECK(context_index >= 0);
424 arguments->set_the_hole(index); 426 arguments->set_the_hole(index);
425 parameter_map->set( 427 parameter_map->set(
426 index + 2, 428 index + 2,
427 Smi::FromInt(Context::MIN_CONTEXT_SLOTS + context_index)); 429 Smi::FromInt(Context::MIN_CONTEXT_SLOTS + context_index));
428 } 430 }
429 431
430 --index; 432 --index;
431 } 433 }
432 } else { 434 } else {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); 473 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0);
472 JavaScriptFrameIterator it(isolate); 474 JavaScriptFrameIterator it(isolate);
473 475
474 // Find the frame that holds the actual arguments passed to the function. 476 // Find the frame that holds the actual arguments passed to the function.
475 it.AdvanceToArgumentsFrame(); 477 it.AdvanceToArgumentsFrame();
476 JavaScriptFrame* frame = it.frame(); 478 JavaScriptFrame* frame = it.frame();
477 479
478 // Determine parameter location on the stack and dispatch on language mode. 480 // Determine parameter location on the stack and dispatch on language mode.
479 int argument_count = frame->GetArgumentsLength(); 481 int argument_count = frame->GetArgumentsLength();
480 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1)); 482 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1));
481 return is_strict(callee->shared()->language_mode()) 483
484 return (is_strict(callee->shared()->language_mode()) ||
485 !callee->is_simple_parameter_list())
482 ? *NewStrictArguments(isolate, callee, parameters, argument_count) 486 ? *NewStrictArguments(isolate, callee, parameters, argument_count)
483 : *NewSloppyArguments(isolate, callee, parameters, argument_count); 487 : *NewSloppyArguments(isolate, callee, parameters, argument_count);
484 } 488 }
485 489
486 490
487 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) { 491 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) {
488 HandleScope scope(isolate); 492 HandleScope scope(isolate);
489 DCHECK(args.length() == 3); 493 DCHECK(args.length() == 3);
490 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); 494 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0);
491 Object** parameters = reinterpret_cast<Object**>(args[1]); 495 Object** parameters = reinterpret_cast<Object**>(args[1]);
492 CONVERT_SMI_ARG_CHECKED(argument_count, 2); 496 CONVERT_SMI_ARG_CHECKED(argument_count, 2);
493 return *NewSloppyArguments(isolate, callee, parameters, argument_count); 497 return *NewSloppyArguments(isolate, callee, parameters, argument_count);
494 } 498 }
495 499
496 500
497 RUNTIME_FUNCTION(Runtime_NewStrictArguments) { 501 RUNTIME_FUNCTION(Runtime_NewStrictArguments) {
498 HandleScope scope(isolate); 502 HandleScope scope(isolate);
499 DCHECK(args.length() == 3); 503 DCHECK(args.length() == 3);
500 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0) 504 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0)
501 Object** parameters = reinterpret_cast<Object**>(args[1]); 505 Object** parameters = reinterpret_cast<Object**>(args[1]);
502 CONVERT_SMI_ARG_CHECKED(argument_count, 2); 506 CONVERT_SMI_ARG_CHECKED(argument_count, 2);
503 return *NewStrictArguments(isolate, callee, parameters, argument_count); 507 return *NewStrictArguments(isolate, callee, parameters, argument_count);
504 } 508 }
505 509
506 510
511 static Handle<JSArray> NewRestParam(Isolate* isolate,
512 Object** parameters,
513 int num_params,
514 int rest_index) {
515 parameters -= rest_index;
516 int num_elements = std::max(0, num_params - rest_index);
517 Handle<FixedArray> elements =
518 isolate->factory()->NewUninitializedFixedArray(num_elements);
519 for (int i = 0; i < num_elements; ++i) {
520 elements->set(i, *--parameters);
521 }
522 return isolate->factory()->NewJSArrayWithElements(elements, FAST_ELEMENTS,
523 num_elements);
524 }
525
526
527 RUNTIME_FUNCTION(Runtime_NewRestParam) {
528 HandleScope scope(isolate);
529 DCHECK(args.length() == 3);
530 Object** parameters = reinterpret_cast<Object**>(args[0]);
531 CONVERT_SMI_ARG_CHECKED(num_params, 1);
532 CONVERT_SMI_ARG_CHECKED(rest_index, 2);
533
534 return *NewRestParam(isolate, parameters, num_params, rest_index);
535 }
536
537
538 RUNTIME_FUNCTION(Runtime_NewRestParamSlow) {
539 HandleScope scope(isolate);
540 DCHECK(args.length() == 1);
541 CONVERT_SMI_ARG_CHECKED(rest_index, 0);
542
543 JavaScriptFrameIterator it(isolate);
544
545 // Find the frame that holds the actual arguments passed to the function.
546 it.AdvanceToArgumentsFrame();
547 JavaScriptFrame* frame = it.frame();
548
549 int argument_count = frame->GetArgumentsLength();
550 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1));
551
552 return *NewRestParam(isolate, parameters, argument_count, rest_index);
553 }
554
555
507 RUNTIME_FUNCTION(Runtime_NewClosureFromStubFailure) { 556 RUNTIME_FUNCTION(Runtime_NewClosureFromStubFailure) {
508 HandleScope scope(isolate); 557 HandleScope scope(isolate);
509 DCHECK(args.length() == 1); 558 DCHECK(args.length() == 1);
510 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); 559 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0);
511 Handle<Context> context(isolate->context()); 560 Handle<Context> context(isolate->context());
512 PretenureFlag pretenure_flag = NOT_TENURED; 561 PretenureFlag pretenure_flag = NOT_TENURED;
513 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, 562 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context,
514 pretenure_flag); 563 pretenure_flag);
515 } 564 }
516 565
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 return Smi::FromInt(frame->GetArgumentsLength()); 1132 return Smi::FromInt(frame->GetArgumentsLength());
1084 } 1133 }
1085 1134
1086 1135
1087 RUNTIME_FUNCTION(RuntimeReference_Arguments) { 1136 RUNTIME_FUNCTION(RuntimeReference_Arguments) {
1088 SealHandleScope shs(isolate); 1137 SealHandleScope shs(isolate);
1089 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); 1138 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate);
1090 } 1139 }
1091 } 1140 }
1092 } // namespace v8::internal 1141 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698