| OLD | NEW |
| 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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 Handle<JSObject>::cast(holder), name, value, attr)); | 349 Handle<JSObject>::cast(holder), name, value, attr)); |
| 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 DCHECK(callee->is_simple_parameter_list()); |
| 359 Handle<JSObject> result = | 360 Handle<JSObject> result = |
| 360 isolate->factory()->NewArgumentsObject(callee, argument_count); | 361 isolate->factory()->NewArgumentsObject(callee, argument_count); |
| 361 | 362 |
| 362 // Allocate the elements if needed. | 363 // Allocate the elements if needed. |
| 363 int parameter_count = callee->shared()->formal_parameter_count(); | 364 int parameter_count = callee->shared()->formal_parameter_count(); |
| 364 if (argument_count > 0) { | 365 if (argument_count > 0) { |
| 365 if (parameter_count > 0) { | 366 if (parameter_count > 0) { |
| 366 int mapped_count = Min(argument_count, parameter_count); | 367 int mapped_count = Min(argument_count, parameter_count); |
| 367 Handle<FixedArray> parameter_map = | 368 Handle<FixedArray> parameter_map = |
| 368 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED); | 369 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } else { | 413 } else { |
| 413 // The context index goes in the parameter map with a hole in the | 414 // The context index goes in the parameter map with a hole in the |
| 414 // arguments array. | 415 // arguments array. |
| 415 int context_index = -1; | 416 int context_index = -1; |
| 416 for (int j = 0; j < context_local_count; ++j) { | 417 for (int j = 0; j < context_local_count; ++j) { |
| 417 if (scope_info->ContextLocalName(j) == *name) { | 418 if (scope_info->ContextLocalName(j) == *name) { |
| 418 context_index = j; | 419 context_index = j; |
| 419 break; | 420 break; |
| 420 } | 421 } |
| 421 } | 422 } |
| 423 |
| 422 DCHECK(context_index >= 0); | 424 DCHECK(context_index >= 0); |
| 423 arguments->set_the_hole(index); | 425 arguments->set_the_hole(index); |
| 424 parameter_map->set( | 426 parameter_map->set( |
| 425 index + 2, | 427 index + 2, |
| 426 Smi::FromInt(Context::MIN_CONTEXT_SLOTS + context_index)); | 428 Smi::FromInt(Context::MIN_CONTEXT_SLOTS + context_index)); |
| 427 } | 429 } |
| 428 | 430 |
| 429 --index; | 431 --index; |
| 430 } | 432 } |
| 431 } else { | 433 } else { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); | 472 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); |
| 471 JavaScriptFrameIterator it(isolate); | 473 JavaScriptFrameIterator it(isolate); |
| 472 | 474 |
| 473 // Find the frame that holds the actual arguments passed to the function. | 475 // Find the frame that holds the actual arguments passed to the function. |
| 474 it.AdvanceToArgumentsFrame(); | 476 it.AdvanceToArgumentsFrame(); |
| 475 JavaScriptFrame* frame = it.frame(); | 477 JavaScriptFrame* frame = it.frame(); |
| 476 | 478 |
| 477 // Determine parameter location on the stack and dispatch on language mode. | 479 // Determine parameter location on the stack and dispatch on language mode. |
| 478 int argument_count = frame->GetArgumentsLength(); | 480 int argument_count = frame->GetArgumentsLength(); |
| 479 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1)); | 481 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1)); |
| 480 return is_strict(callee->shared()->language_mode()) | 482 |
| 483 return (is_strict(callee->shared()->language_mode()) || |
| 484 !callee->is_simple_parameter_list()) |
| 481 ? *NewStrictArguments(isolate, callee, parameters, argument_count) | 485 ? *NewStrictArguments(isolate, callee, parameters, argument_count) |
| 482 : *NewSloppyArguments(isolate, callee, parameters, argument_count); | 486 : *NewSloppyArguments(isolate, callee, parameters, argument_count); |
| 483 } | 487 } |
| 484 | 488 |
| 485 | 489 |
| 486 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) { | 490 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) { |
| 487 HandleScope scope(isolate); | 491 HandleScope scope(isolate); |
| 488 DCHECK(args.length() == 3); | 492 DCHECK(args.length() == 3); |
| 489 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); | 493 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); |
| 490 Object** parameters = reinterpret_cast<Object**>(args[1]); | 494 Object** parameters = reinterpret_cast<Object**>(args[1]); |
| 491 CONVERT_SMI_ARG_CHECKED(argument_count, 2); | 495 CONVERT_SMI_ARG_CHECKED(argument_count, 2); |
| 492 return *NewSloppyArguments(isolate, callee, parameters, argument_count); | 496 return *NewSloppyArguments(isolate, callee, parameters, argument_count); |
| 493 } | 497 } |
| 494 | 498 |
| 495 | 499 |
| 496 RUNTIME_FUNCTION(Runtime_NewStrictArguments) { | 500 RUNTIME_FUNCTION(Runtime_NewStrictArguments) { |
| 497 HandleScope scope(isolate); | 501 HandleScope scope(isolate); |
| 498 DCHECK(args.length() == 3); | 502 DCHECK(args.length() == 3); |
| 499 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0) | 503 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0) |
| 500 Object** parameters = reinterpret_cast<Object**>(args[1]); | 504 Object** parameters = reinterpret_cast<Object**>(args[1]); |
| 501 CONVERT_SMI_ARG_CHECKED(argument_count, 2); | 505 CONVERT_SMI_ARG_CHECKED(argument_count, 2); |
| 502 return *NewStrictArguments(isolate, callee, parameters, argument_count); | 506 return *NewStrictArguments(isolate, callee, parameters, argument_count); |
| 503 } | 507 } |
| 504 | 508 |
| 505 | 509 |
| 510 static Handle<JSArray> NewRestParam(Isolate* isolate, |
| 511 Object** parameters, |
| 512 int num_params, |
| 513 int rest_index) { |
| 514 parameters -= rest_index; |
| 515 int num_elements = std::max(0, num_params - rest_index); |
| 516 Handle<FixedArray> elements = |
| 517 isolate->factory()->NewUninitializedFixedArray(num_elements); |
| 518 for (int i = 0; i < num_elements; ++i) { |
| 519 elements->set(i, *--parameters); |
| 520 } |
| 521 return isolate->factory()->NewJSArrayWithElements(elements, FAST_ELEMENTS, |
| 522 num_elements); |
| 523 } |
| 524 |
| 525 |
| 526 RUNTIME_FUNCTION(Runtime_NewRestParam) { |
| 527 HandleScope scope(isolate); |
| 528 DCHECK(args.length() == 3); |
| 529 Object** parameters = reinterpret_cast<Object**>(args[0]); |
| 530 CONVERT_SMI_ARG_CHECKED(num_params, 1); |
| 531 CONVERT_SMI_ARG_CHECKED(rest_index, 2); |
| 532 |
| 533 return *NewRestParam(isolate, parameters, num_params, rest_index); |
| 534 } |
| 535 |
| 536 |
| 537 RUNTIME_FUNCTION(Runtime_NewRestParamSlow) { |
| 538 HandleScope scope(isolate); |
| 539 DCHECK(args.length() == 1); |
| 540 CONVERT_SMI_ARG_CHECKED(rest_index, 0); |
| 541 |
| 542 JavaScriptFrameIterator it(isolate); |
| 543 |
| 544 // Find the frame that holds the actual arguments passed to the function. |
| 545 it.AdvanceToArgumentsFrame(); |
| 546 JavaScriptFrame* frame = it.frame(); |
| 547 |
| 548 int argument_count = frame->GetArgumentsLength(); |
| 549 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1)); |
| 550 |
| 551 return *NewRestParam(isolate, parameters, argument_count, rest_index); |
| 552 } |
| 553 |
| 554 |
| 506 RUNTIME_FUNCTION(Runtime_NewClosureFromStubFailure) { | 555 RUNTIME_FUNCTION(Runtime_NewClosureFromStubFailure) { |
| 507 HandleScope scope(isolate); | 556 HandleScope scope(isolate); |
| 508 DCHECK(args.length() == 1); | 557 DCHECK(args.length() == 1); |
| 509 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); | 558 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); |
| 510 Handle<Context> context(isolate->context()); | 559 Handle<Context> context(isolate->context()); |
| 511 PretenureFlag pretenure_flag = NOT_TENURED; | 560 PretenureFlag pretenure_flag = NOT_TENURED; |
| 512 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, | 561 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, |
| 513 pretenure_flag); | 562 pretenure_flag); |
| 514 } | 563 } |
| 515 | 564 |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 return Smi::FromInt(frame->GetArgumentsLength()); | 1131 return Smi::FromInt(frame->GetArgumentsLength()); |
| 1083 } | 1132 } |
| 1084 | 1133 |
| 1085 | 1134 |
| 1086 RUNTIME_FUNCTION(RuntimeReference_Arguments) { | 1135 RUNTIME_FUNCTION(RuntimeReference_Arguments) { |
| 1087 SealHandleScope shs(isolate); | 1136 SealHandleScope shs(isolate); |
| 1088 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); | 1137 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); |
| 1089 } | 1138 } |
| 1090 } | 1139 } |
| 1091 } // namespace v8::internal | 1140 } // namespace v8::internal |
| OLD | NEW |