| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 __ Push(expr->flags()); | 656 __ Push(expr->flags()); |
| 657 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); | 657 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
| 658 // Label done: | 658 // Label done: |
| 659 __ bind(&done); | 659 __ bind(&done); |
| 660 Move(expr->context(), rax); | 660 Move(expr->context(), rax); |
| 661 } | 661 } |
| 662 | 662 |
| 663 | 663 |
| 664 void FastCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | 664 void FastCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 665 Comment cmnt(masm_, "[ ObjectLiteral"); | 665 Comment cmnt(masm_, "[ ObjectLiteral"); |
| 666 Label boilerplate_exists; | |
| 667 | |
| 668 __ movq(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 666 __ movq(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 669 __ movq(rbx, FieldOperand(rdi, JSFunction::kLiteralsOffset)); | 667 __ push(FieldOperand(rdi, JSFunction::kLiteralsOffset)); |
| 670 int literal_offset = | |
| 671 FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; | |
| 672 __ movq(rax, FieldOperand(rbx, literal_offset)); | |
| 673 __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); | |
| 674 __ j(not_equal, &boilerplate_exists); | |
| 675 // Create boilerplate if it does not exist. | |
| 676 // Literal array (0). | |
| 677 __ push(rbx); | |
| 678 // Literal index (1). | |
| 679 __ Push(Smi::FromInt(expr->literal_index())); | 668 __ Push(Smi::FromInt(expr->literal_index())); |
| 680 // Constant properties (2). | |
| 681 __ Push(expr->constant_properties()); | 669 __ Push(expr->constant_properties()); |
| 682 __ CallRuntime(Runtime::kCreateObjectLiteralBoilerplate, 3); | 670 if (expr->depth() > 1) { |
| 683 __ bind(&boilerplate_exists); | 671 __ CallRuntime(Runtime::kCreateObjectLiteral, 3); |
| 684 // rax contains boilerplate. | |
| 685 // Clone boilerplate. | |
| 686 __ push(rax); | |
| 687 if (expr->depth() == 1) { | |
| 688 __ CallRuntime(Runtime::kCloneShallowLiteralBoilerplate, 1); | |
| 689 } else { | 672 } else { |
| 690 __ CallRuntime(Runtime::kCloneLiteralBoilerplate, 1); | 673 __ CallRuntime(Runtime::kCreateObjectLiteralShallow, 3); |
| 691 } | 674 } |
| 692 | 675 |
| 693 // If result_saved == true: The result is saved on top of the | 676 // If result_saved == true: The result is saved on top of the |
| 694 // stack and in rax. | 677 // stack and in rax. |
| 695 // If result_saved == false: The result not on the stack, just in rax. | 678 // If result_saved == false: The result not on the stack, just in rax. |
| 696 bool result_saved = false; | 679 bool result_saved = false; |
| 697 | 680 |
| 698 for (int i = 0; i < expr->properties()->length(); i++) { | 681 for (int i = 0; i < expr->properties()->length(); i++) { |
| 699 ObjectLiteral::Property* property = expr->properties()->at(i); | 682 ObjectLiteral::Property* property = expr->properties()->at(i); |
| 700 if (property->IsCompileTimeValue()) continue; | 683 if (property->IsCompileTimeValue()) continue; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 __ addq(rsp, Immediate(kPointerSize)); | 759 __ addq(rsp, Immediate(kPointerSize)); |
| 777 __ jmp(true_label_); | 760 __ jmp(true_label_); |
| 778 break; | 761 break; |
| 779 } | 762 } |
| 780 } | 763 } |
| 781 } | 764 } |
| 782 | 765 |
| 783 | 766 |
| 784 void FastCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 767 void FastCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 785 Comment cmnt(masm_, "[ ArrayLiteral"); | 768 Comment cmnt(masm_, "[ ArrayLiteral"); |
| 786 Label make_clone; | |
| 787 | |
| 788 // Fetch the function's literals array. | |
| 789 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 769 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 790 __ movq(rbx, FieldOperand(rbx, JSFunction::kLiteralsOffset)); | 770 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
| 791 // Check if the literal's boilerplate has been instantiated. | |
| 792 int offset = | |
| 793 FixedArray::kHeaderSize + (expr->literal_index() * kPointerSize); | |
| 794 __ movq(rax, FieldOperand(rbx, offset)); | |
| 795 __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); | |
| 796 __ j(not_equal, &make_clone); | |
| 797 | |
| 798 // Instantiate the boilerplate. | |
| 799 __ push(rbx); | |
| 800 __ Push(Smi::FromInt(expr->literal_index())); | 771 __ Push(Smi::FromInt(expr->literal_index())); |
| 801 __ Push(expr->literals()); | 772 __ Push(expr->literals()); |
| 802 __ CallRuntime(Runtime::kCreateArrayLiteralBoilerplate, 3); | |
| 803 | |
| 804 __ bind(&make_clone); | |
| 805 // Clone the boilerplate. | |
| 806 __ push(rax); | |
| 807 if (expr->depth() > 1) { | 773 if (expr->depth() > 1) { |
| 808 __ CallRuntime(Runtime::kCloneLiteralBoilerplate, 1); | 774 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
| 809 } else { | 775 } else { |
| 810 __ CallRuntime(Runtime::kCloneShallowLiteralBoilerplate, 1); | 776 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
| 811 } | 777 } |
| 812 | 778 |
| 813 bool result_saved = false; // Is the result saved to the stack? | 779 bool result_saved = false; // Is the result saved to the stack? |
| 814 | 780 |
| 815 // Emit code to evaluate all the non-constant subexpressions and to store | 781 // Emit code to evaluate all the non-constant subexpressions and to store |
| 816 // them into the newly cloned array. | 782 // them into the newly cloned array. |
| 817 ZoneList<Expression*>* subexprs = expr->values(); | 783 ZoneList<Expression*>* subexprs = expr->values(); |
| 818 for (int i = 0, len = subexprs->length(); i < len; i++) { | 784 for (int i = 0, len = subexprs->length(); i < len; i++) { |
| 819 Expression* subexpr = subexprs->at(i); | 785 Expression* subexpr = subexprs->at(i); |
| 820 // If the subexpression is a literal or a simple materialized literal it | 786 // If the subexpression is a literal or a simple materialized literal it |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) { | 1647 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 1682 __ movq(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1648 __ movq(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1683 Move(expr->context(), rax); | 1649 Move(expr->context(), rax); |
| 1684 } | 1650 } |
| 1685 | 1651 |
| 1686 | 1652 |
| 1687 #undef __ | 1653 #undef __ |
| 1688 | 1654 |
| 1689 | 1655 |
| 1690 } } // namespace v8::internal | 1656 } } // namespace v8::internal |
| OLD | NEW |