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

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

Issue 1567393003: [runtime] Make Runtime::GetCallerArguments local to scopes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-runtime-rest
Patch Set: Created 4 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
« no previous file with comments | « src/runtime/runtime-function.cc ('k') | no next file » | 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/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/ast/scopeinfo.h" 9 #include "src/ast/scopeinfo.h"
10 #include "src/ast/scopes.h" 10 #include "src/ast/scopes.h"
11 #include "src/deoptimizer.h"
11 #include "src/frames-inl.h" 12 #include "src/frames-inl.h"
12 #include "src/isolate-inl.h" 13 #include "src/isolate-inl.h"
13 #include "src/messages.h" 14 #include "src/messages.h"
14 15
15 namespace v8 { 16 namespace v8 {
16 namespace internal { 17 namespace internal {
17 18
18 static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) { 19 static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) {
19 HandleScope scope(isolate); 20 HandleScope scope(isolate);
20 THROW_NEW_ERROR_RETURN_FAILURE( 21 THROW_NEW_ERROR_RETURN_FAILURE(
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 RETURN_FAILURE_ON_EXCEPTION( 406 RETURN_FAILURE_ON_EXCEPTION(
406 isolate, JSObject::SetOwnPropertyIgnoreAttributes( 407 isolate, JSObject::SetOwnPropertyIgnoreAttributes(
407 Handle<JSObject>::cast(holder), name, value, attr)); 408 Handle<JSObject>::cast(holder), name, value, attr));
408 409
409 return *value; 410 return *value;
410 } 411 }
411 412
412 413
413 namespace { 414 namespace {
414 415
416 // Find the arguments of the JavaScript function invocation that called
417 // into C++ code. Collect these in a newly allocated array of handles (possibly
418 // prefixed by a number of empty handles).
419 base::SmartArrayPointer<Handle<Object>> GetCallerArguments(Isolate* isolate,
420 int prefix_argc,
421 int* total_argc) {
422 // Find frame containing arguments passed to the caller.
423 JavaScriptFrameIterator it(isolate);
424 JavaScriptFrame* frame = it.frame();
425 List<JSFunction*> functions(2);
426 frame->GetFunctions(&functions);
427 if (functions.length() > 1) {
428 int inlined_jsframe_index = functions.length() - 1;
429 TranslatedState translated_values(frame);
430 translated_values.Prepare(false, frame->fp());
431
432 int argument_count = 0;
433 TranslatedFrame* translated_frame =
434 translated_values.GetArgumentsInfoFromJSFrameIndex(
435 inlined_jsframe_index, &argument_count);
436 TranslatedFrame::iterator iter = translated_frame->begin();
437
438 // Skip the function.
439 iter++;
440
441 // Skip the receiver.
442 iter++;
443 argument_count--;
444
445 *total_argc = prefix_argc + argument_count;
446 base::SmartArrayPointer<Handle<Object>> param_data(
447 NewArray<Handle<Object>>(*total_argc));
448 bool should_deoptimize = false;
449 for (int i = 0; i < argument_count; i++) {
450 should_deoptimize = should_deoptimize || iter->IsMaterializedObject();
451 Handle<Object> value = iter->GetValue();
452 param_data[prefix_argc + i] = value;
453 iter++;
454 }
455
456 if (should_deoptimize) {
457 translated_values.StoreMaterializedValuesAndDeopt();
458 }
459
460 return param_data;
461 } else {
462 it.AdvanceToArgumentsFrame();
463 frame = it.frame();
464 int args_count = frame->ComputeParametersCount();
465
466 *total_argc = prefix_argc + args_count;
467 base::SmartArrayPointer<Handle<Object>> param_data(
468 NewArray<Handle<Object>>(*total_argc));
469 for (int i = 0; i < args_count; i++) {
470 Handle<Object> val = Handle<Object>(frame->GetParameter(i), isolate);
471 param_data[prefix_argc + i] = val;
472 }
473 return param_data;
474 }
475 }
476
477
415 template <typename T> 478 template <typename T>
416 Handle<JSObject> NewSloppyArguments(Isolate* isolate, Handle<JSFunction> callee, 479 Handle<JSObject> NewSloppyArguments(Isolate* isolate, Handle<JSFunction> callee,
417 T parameters, int argument_count) { 480 T parameters, int argument_count) {
418 CHECK(!IsSubclassConstructor(callee->shared()->kind())); 481 CHECK(!IsSubclassConstructor(callee->shared()->kind()));
419 DCHECK(callee->shared()->has_simple_parameters()); 482 DCHECK(callee->shared()->has_simple_parameters());
420 Handle<JSObject> result = 483 Handle<JSObject> result =
421 isolate->factory()->NewArgumentsObject(callee, argument_count); 484 isolate->factory()->NewArgumentsObject(callee, argument_count);
422 485
423 // Allocate the elements if needed. 486 // Allocate the elements if needed.
424 int parameter_count = callee->shared()->internal_formal_parameter_count(); 487 int parameter_count = callee->shared()->internal_formal_parameter_count();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 }; 624 };
562 625
563 } // namespace 626 } // namespace
564 627
565 628
566 RUNTIME_FUNCTION(Runtime_NewSloppyArguments_Generic) { 629 RUNTIME_FUNCTION(Runtime_NewSloppyArguments_Generic) {
567 HandleScope scope(isolate); 630 HandleScope scope(isolate);
568 DCHECK(args.length() == 1); 631 DCHECK(args.length() == 1);
569 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); 632 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0);
570 // This generic runtime function can also be used when the caller has been 633 // This generic runtime function can also be used when the caller has been
571 // inlined, we use the slow but accurate {Runtime::GetCallerArguments}. 634 // inlined, we use the slow but accurate {GetCallerArguments}.
572 int argument_count = 0; 635 int argument_count = 0;
573 base::SmartArrayPointer<Handle<Object>> arguments = 636 base::SmartArrayPointer<Handle<Object>> arguments =
574 Runtime::GetCallerArguments(isolate, 0, &argument_count); 637 GetCallerArguments(isolate, 0, &argument_count);
575 HandleArguments argument_getter(arguments.get()); 638 HandleArguments argument_getter(arguments.get());
576 return *NewSloppyArguments(isolate, callee, argument_getter, argument_count); 639 return *NewSloppyArguments(isolate, callee, argument_getter, argument_count);
577 } 640 }
578 641
579 642
580 RUNTIME_FUNCTION(Runtime_NewStrictArguments_Generic) { 643 RUNTIME_FUNCTION(Runtime_NewStrictArguments_Generic) {
581 HandleScope scope(isolate); 644 HandleScope scope(isolate);
582 DCHECK(args.length() == 1); 645 DCHECK(args.length() == 1);
583 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); 646 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0);
584 // This generic runtime function can also be used when the caller has been 647 // This generic runtime function can also be used when the caller has been
585 // inlined, we use the slow but accurate {Runtime::GetCallerArguments}. 648 // inlined, we use the slow but accurate {GetCallerArguments}.
586 int argument_count = 0; 649 int argument_count = 0;
587 base::SmartArrayPointer<Handle<Object>> arguments = 650 base::SmartArrayPointer<Handle<Object>> arguments =
588 Runtime::GetCallerArguments(isolate, 0, &argument_count); 651 GetCallerArguments(isolate, 0, &argument_count);
589 HandleArguments argument_getter(arguments.get()); 652 HandleArguments argument_getter(arguments.get());
590 return *NewStrictArguments(isolate, callee, argument_getter, argument_count); 653 return *NewStrictArguments(isolate, callee, argument_getter, argument_count);
591 } 654 }
592 655
593 656
594 RUNTIME_FUNCTION(Runtime_NewRestArguments_Generic) { 657 RUNTIME_FUNCTION(Runtime_NewRestArguments_Generic) {
595 HandleScope scope(isolate); 658 HandleScope scope(isolate);
596 DCHECK(args.length() == 2); 659 DCHECK(args.length() == 2);
597 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0) 660 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0)
598 CONVERT_SMI_ARG_CHECKED(start_index, 1); 661 CONVERT_SMI_ARG_CHECKED(start_index, 1);
599 // This generic runtime function can also be used when the caller has been 662 // This generic runtime function can also be used when the caller has been
600 // inlined, we use the slow but accurate {Runtime::GetCallerArguments}. 663 // inlined, we use the slow but accurate {GetCallerArguments}.
601 int argument_count = 0; 664 int argument_count = 0;
602 base::SmartArrayPointer<Handle<Object>> arguments = 665 base::SmartArrayPointer<Handle<Object>> arguments =
603 Runtime::GetCallerArguments(isolate, 0, &argument_count); 666 GetCallerArguments(isolate, 0, &argument_count);
604 HandleArguments argument_getter(arguments.get()); 667 HandleArguments argument_getter(arguments.get());
605 return *NewRestArguments(isolate, callee, argument_getter, argument_count, 668 return *NewRestArguments(isolate, callee, argument_getter, argument_count,
606 start_index); 669 start_index);
607 } 670 }
608 671
609 672
610 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) { 673 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) {
611 HandleScope scope(isolate); 674 HandleScope scope(isolate);
612 DCHECK(args.length() == 3); 675 DCHECK(args.length() == 3);
613 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); 676 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0);
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 isolate, Object::SetProperty(object, name, value, language_mode)); 1168 isolate, Object::SetProperty(object, name, value, language_mode));
1106 1169
1107 return *value; 1170 return *value;
1108 } 1171 }
1109 1172
1110 1173
1111 RUNTIME_FUNCTION(Runtime_ArgumentsLength) { 1174 RUNTIME_FUNCTION(Runtime_ArgumentsLength) {
1112 HandleScope scope(isolate); 1175 HandleScope scope(isolate);
1113 DCHECK(args.length() == 0); 1176 DCHECK(args.length() == 0);
1114 int argument_count = 0; 1177 int argument_count = 0;
1115 Runtime::GetCallerArguments(isolate, 0, &argument_count); 1178 GetCallerArguments(isolate, 0, &argument_count);
1116 return Smi::FromInt(argument_count); 1179 return Smi::FromInt(argument_count);
1117 } 1180 }
1118 1181
1119 1182
1120 RUNTIME_FUNCTION(Runtime_Arguments) { 1183 RUNTIME_FUNCTION(Runtime_Arguments) {
1121 HandleScope scope(isolate); 1184 HandleScope scope(isolate);
1122 DCHECK(args.length() == 1); 1185 DCHECK(args.length() == 1);
1123 CONVERT_ARG_HANDLE_CHECKED(Object, raw_key, 0); 1186 CONVERT_ARG_HANDLE_CHECKED(Object, raw_key, 0);
1124 1187
1125 // Determine the actual arguments passed to the function. 1188 // Determine the actual arguments passed to the function.
1126 int argument_count_signed = 0; 1189 int argument_count_signed = 0;
1127 base::SmartArrayPointer<Handle<Object>> arguments = 1190 base::SmartArrayPointer<Handle<Object>> arguments =
1128 Runtime::GetCallerArguments(isolate, 0, &argument_count_signed); 1191 GetCallerArguments(isolate, 0, &argument_count_signed);
1129 const uint32_t argument_count = argument_count_signed; 1192 const uint32_t argument_count = argument_count_signed;
1130 1193
1131 // Try to convert the key to an index. If successful and within 1194 // Try to convert the key to an index. If successful and within
1132 // index return the the argument from the frame. 1195 // index return the the argument from the frame.
1133 uint32_t index = 0; 1196 uint32_t index = 0;
1134 if (raw_key->ToArrayIndex(&index) && index < argument_count) { 1197 if (raw_key->ToArrayIndex(&index) && index < argument_count) {
1135 return *arguments[index]; 1198 return *arguments[index];
1136 } 1199 }
1137 1200
1138 if (raw_key->IsSymbol()) { 1201 if (raw_key->IsSymbol()) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 1248
1186 // Lookup in the initial Object.prototype object. 1249 // Lookup in the initial Object.prototype object.
1187 Handle<Object> result; 1250 Handle<Object> result;
1188 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1251 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1189 isolate, result, 1252 isolate, result,
1190 Object::GetProperty(isolate->initial_object_prototype(), key)); 1253 Object::GetProperty(isolate->initial_object_prototype(), key));
1191 return *result; 1254 return *result;
1192 } 1255 }
1193 } // namespace internal 1256 } // namespace internal
1194 } // namespace v8 1257 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-function.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698