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/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" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); | 514 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); |
515 for (int i = 0; i < argument_count; i++) { | 515 for (int i = 0; i < argument_count; i++) { |
516 array->set(i, parameters[i], mode); | 516 array->set(i, parameters[i], mode); |
517 } | 517 } |
518 result->set_elements(*array); | 518 result->set_elements(*array); |
519 } | 519 } |
520 return result; | 520 return result; |
521 } | 521 } |
522 | 522 |
523 | 523 |
| 524 template <typename T> |
| 525 Handle<JSObject> NewRestArguments(Isolate* isolate, Handle<JSFunction> callee, |
| 526 T parameters, int argument_count, |
| 527 int start_index) { |
| 528 int num_elements = std::max(0, argument_count - start_index); |
| 529 Handle<JSObject> result = isolate->factory()->NewJSArray( |
| 530 FAST_ELEMENTS, num_elements, num_elements, Strength::WEAK, |
| 531 DONT_INITIALIZE_ARRAY_ELEMENTS); |
| 532 { |
| 533 DisallowHeapAllocation no_gc; |
| 534 FixedArray* elements = FixedArray::cast(result->elements()); |
| 535 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); |
| 536 for (int i = 0; i < num_elements; i++) { |
| 537 elements->set(i, parameters[i + start_index], mode); |
| 538 } |
| 539 } |
| 540 return result; |
| 541 } |
| 542 |
| 543 |
524 class HandleArguments BASE_EMBEDDED { | 544 class HandleArguments BASE_EMBEDDED { |
525 public: | 545 public: |
526 explicit HandleArguments(Handle<Object>* array) : array_(array) {} | 546 explicit HandleArguments(Handle<Object>* array) : array_(array) {} |
527 Object* operator[](int index) { return *array_[index]; } | 547 Object* operator[](int index) { return *array_[index]; } |
528 | 548 |
529 private: | 549 private: |
530 Handle<Object>* array_; | 550 Handle<Object>* array_; |
531 }; | 551 }; |
532 | 552 |
533 | 553 |
(...skipping 30 matching lines...) Expand all Loading... |
564 // This generic runtime function can also be used when the caller has been | 584 // This generic runtime function can also be used when the caller has been |
565 // inlined, we use the slow but accurate {Runtime::GetCallerArguments}. | 585 // inlined, we use the slow but accurate {Runtime::GetCallerArguments}. |
566 int argument_count = 0; | 586 int argument_count = 0; |
567 base::SmartArrayPointer<Handle<Object>> arguments = | 587 base::SmartArrayPointer<Handle<Object>> arguments = |
568 Runtime::GetCallerArguments(isolate, 0, &argument_count); | 588 Runtime::GetCallerArguments(isolate, 0, &argument_count); |
569 HandleArguments argument_getter(arguments.get()); | 589 HandleArguments argument_getter(arguments.get()); |
570 return *NewStrictArguments(isolate, callee, argument_getter, argument_count); | 590 return *NewStrictArguments(isolate, callee, argument_getter, argument_count); |
571 } | 591 } |
572 | 592 |
573 | 593 |
| 594 RUNTIME_FUNCTION(Runtime_NewRestArguments_Generic) { |
| 595 HandleScope scope(isolate); |
| 596 DCHECK(args.length() == 2); |
| 597 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0) |
| 598 CONVERT_SMI_ARG_CHECKED(start_index, 1); |
| 599 // This generic runtime function can also be used when the caller has been |
| 600 // inlined, we use the slow but accurate {Runtime::GetCallerArguments}. |
| 601 int argument_count = 0; |
| 602 base::SmartArrayPointer<Handle<Object>> arguments = |
| 603 Runtime::GetCallerArguments(isolate, 0, &argument_count); |
| 604 HandleArguments argument_getter(arguments.get()); |
| 605 return *NewRestArguments(isolate, callee, argument_getter, argument_count, |
| 606 start_index); |
| 607 } |
| 608 |
| 609 |
574 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) { | 610 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) { |
575 HandleScope scope(isolate); | 611 HandleScope scope(isolate); |
576 DCHECK(args.length() == 3); | 612 DCHECK(args.length() == 3); |
577 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); | 613 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); |
578 Object** parameters = reinterpret_cast<Object**>(args[1]); | 614 Object** parameters = reinterpret_cast<Object**>(args[1]); |
579 CONVERT_SMI_ARG_CHECKED(argument_count, 2); | 615 CONVERT_SMI_ARG_CHECKED(argument_count, 2); |
580 #ifdef DEBUG | 616 #ifdef DEBUG |
581 // This runtime function does not materialize the correct arguments when the | 617 // This runtime function does not materialize the correct arguments when the |
582 // caller has been inlined, better make sure we are not hitting that case. | 618 // caller has been inlined, better make sure we are not hitting that case. |
583 JavaScriptFrameIterator it(isolate); | 619 JavaScriptFrameIterator it(isolate); |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 | 1214 |
1179 // Lookup in the initial Object.prototype object. | 1215 // Lookup in the initial Object.prototype object. |
1180 Handle<Object> result; | 1216 Handle<Object> result; |
1181 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1217 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1182 isolate, result, | 1218 isolate, result, |
1183 Object::GetProperty(isolate->initial_object_prototype(), key)); | 1219 Object::GetProperty(isolate->initial_object_prototype(), key)); |
1184 return *result; | 1220 return *result; |
1185 } | 1221 } |
1186 } // namespace internal | 1222 } // namespace internal |
1187 } // namespace v8 | 1223 } // namespace v8 |
OLD | NEW |