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

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

Issue 1272673003: [es6] Re-implement rest parameters via desugaring. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tiny bit more cleanup Created 5 years, 3 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 "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/messages.h" 10 #include "src/messages.h"
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 RUNTIME_FUNCTION(Runtime_NewStrictArguments) { 548 RUNTIME_FUNCTION(Runtime_NewStrictArguments) {
549 HandleScope scope(isolate); 549 HandleScope scope(isolate);
550 DCHECK(args.length() == 3); 550 DCHECK(args.length() == 3);
551 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0) 551 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0)
552 Object** parameters = reinterpret_cast<Object**>(args[1]); 552 Object** parameters = reinterpret_cast<Object**>(args[1]);
553 CONVERT_SMI_ARG_CHECKED(argument_count, 2); 553 CONVERT_SMI_ARG_CHECKED(argument_count, 2);
554 return *NewStrictArguments(isolate, callee, parameters, argument_count); 554 return *NewStrictArguments(isolate, callee, parameters, argument_count);
555 } 555 }
556 556
557 557
558 static Handle<JSArray> NewRestParam(Isolate* isolate, Object** parameters,
559 int num_params, int rest_index,
560 LanguageMode language_mode) {
561 parameters -= rest_index;
562 int num_elements = std::max(0, num_params - rest_index);
563 Handle<FixedArray> elements =
564 isolate->factory()->NewUninitializedFixedArray(num_elements);
565 for (int i = 0; i < num_elements; ++i) {
566 elements->set(i, *--parameters);
567 }
568 return isolate->factory()->NewJSArrayWithElements(
569 elements, FAST_ELEMENTS, num_elements, strength(language_mode));
570 }
571
572
573 RUNTIME_FUNCTION(Runtime_NewRestParam) {
574 HandleScope scope(isolate);
575 DCHECK(args.length() == 4);
576 Object** parameters = reinterpret_cast<Object**>(args[0]);
577 CONVERT_SMI_ARG_CHECKED(num_params, 1);
578 CONVERT_SMI_ARG_CHECKED(rest_index, 2);
579 CONVERT_SMI_ARG_CHECKED(language_mode, 3);
580
581 return *NewRestParam(isolate, parameters, num_params, rest_index,
582 static_cast<LanguageMode>(language_mode));
583 }
584
585
586 RUNTIME_FUNCTION(Runtime_NewRestParamSlow) {
587 HandleScope scope(isolate);
588 DCHECK(args.length() == 2);
589 CONVERT_SMI_ARG_CHECKED(rest_index, 0);
590 CONVERT_SMI_ARG_CHECKED(language_mode, 1);
591
592 JavaScriptFrameIterator it(isolate);
593
594 // Find the frame that holds the actual arguments passed to the function.
595 it.AdvanceToArgumentsFrame();
596 JavaScriptFrame* frame = it.frame();
597
598 int argument_count = frame->GetArgumentsLength();
599 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1));
600
601 return *NewRestParam(isolate, parameters, argument_count, rest_index,
602 static_cast<LanguageMode>(language_mode));
603 }
604
605
606 RUNTIME_FUNCTION(Runtime_NewClosureFromStubFailure) { 558 RUNTIME_FUNCTION(Runtime_NewClosureFromStubFailure) {
607 HandleScope scope(isolate); 559 HandleScope scope(isolate);
608 DCHECK(args.length() == 1); 560 DCHECK(args.length() == 1);
609 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); 561 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0);
610 Handle<Context> context(isolate->context()); 562 Handle<Context> context(isolate->context());
611 PretenureFlag pretenure_flag = NOT_TENURED; 563 PretenureFlag pretenure_flag = NOT_TENURED;
612 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, 564 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context,
613 pretenure_flag); 565 pretenure_flag);
614 } 566 }
615 567
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 1123
1172 // Lookup in the initial Object.prototype object. 1124 // Lookup in the initial Object.prototype object.
1173 Handle<Object> result; 1125 Handle<Object> result;
1174 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1126 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1175 isolate, result, 1127 isolate, result,
1176 Object::GetProperty(isolate->initial_object_prototype(), key)); 1128 Object::GetProperty(isolate->initial_object_prototype(), key));
1177 return *result; 1129 return *result;
1178 } 1130 }
1179 } // namespace internal 1131 } // namespace internal
1180 } // namespace v8 1132 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698