| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 4759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4770 } | 4770 } |
| 4771 return false; | 4771 return false; |
| 4772 } | 4772 } |
| 4773 | 4773 |
| 4774 | 4774 |
| 4775 bool HGraphBuilder::TryCallApply(Call* expr) { | 4775 bool HGraphBuilder::TryCallApply(Call* expr) { |
| 4776 Expression* callee = expr->expression(); | 4776 Expression* callee = expr->expression(); |
| 4777 Property* prop = callee->AsProperty(); | 4777 Property* prop = callee->AsProperty(); |
| 4778 ASSERT(prop != NULL); | 4778 ASSERT(prop != NULL); |
| 4779 | 4779 |
| 4780 if (!expr->IsMonomorphic() || expr->check_type() != RECEIVER_MAP_CHECK) { |
| 4781 return false; |
| 4782 } |
| 4783 Handle<Map> function_map = expr->GetReceiverTypes()->first(); |
| 4784 if (function_map->instance_type() != JS_FUNCTION_TYPE || |
| 4785 !expr->target()->shared()->HasBuiltinFunctionId() || |
| 4786 expr->target()->shared()->builtin_function_id() != kFunctionApply) { |
| 4787 return false; |
| 4788 } |
| 4789 |
| 4780 if (info()->scope()->arguments() == NULL) return false; | 4790 if (info()->scope()->arguments() == NULL) return false; |
| 4781 | 4791 |
| 4782 Handle<String> name = prop->key()->AsLiteral()->AsPropertyName(); | |
| 4783 if (!name->IsEqualTo(CStrVector("apply"))) return false; | |
| 4784 | |
| 4785 ZoneList<Expression*>* args = expr->arguments(); | 4792 ZoneList<Expression*>* args = expr->arguments(); |
| 4786 if (args->length() != 2) return false; | 4793 if (args->length() != 2) return false; |
| 4787 | 4794 |
| 4788 VariableProxy* arg_two = args->at(1)->AsVariableProxy(); | 4795 VariableProxy* arg_two = args->at(1)->AsVariableProxy(); |
| 4789 if (arg_two == NULL || !arg_two->var()->IsStackAllocated()) return false; | 4796 if (arg_two == NULL || !arg_two->var()->IsStackAllocated()) return false; |
| 4790 HValue* arg_two_value = environment()->Lookup(arg_two->var()); | 4797 HValue* arg_two_value = environment()->Lookup(arg_two->var()); |
| 4791 if (!arg_two_value->CheckFlag(HValue::kIsArguments)) return false; | 4798 if (!arg_two_value->CheckFlag(HValue::kIsArguments)) return false; |
| 4792 | 4799 |
| 4793 if (!expr->IsMonomorphic() || | |
| 4794 expr->check_type() != RECEIVER_MAP_CHECK) return false; | |
| 4795 | |
| 4796 // Our implementation of arguments (based on this stack frame or an | 4800 // Our implementation of arguments (based on this stack frame or an |
| 4797 // adapter below it) does not work for inlined functions. | 4801 // adapter below it) does not work for inlined functions. |
| 4798 if (function_state()->outer() != NULL) { | 4802 if (function_state()->outer() != NULL) { |
| 4799 Bailout("Function.prototype.apply optimization in inlined function"); | 4803 Bailout("Function.prototype.apply optimization in inlined function"); |
| 4800 return true; | 4804 return true; |
| 4801 } | 4805 } |
| 4802 | 4806 |
| 4803 // Found pattern f.apply(receiver, arguments). | 4807 // Found pattern f.apply(receiver, arguments). |
| 4804 VisitForValue(prop->obj()); | 4808 VisitForValue(prop->obj()); |
| 4805 if (HasStackOverflow() || current_block() == NULL) return true; | 4809 if (HasStackOverflow() || current_block() == NULL) return true; |
| 4806 HValue* function = Pop(); | 4810 HValue* function = Pop(); |
| 4807 VisitForValue(args->at(0)); | 4811 VisitForValue(args->at(0)); |
| 4808 if (HasStackOverflow() || current_block() == NULL) return true; | 4812 if (HasStackOverflow() || current_block() == NULL) return true; |
| 4809 HValue* receiver = Pop(); | 4813 HValue* receiver = Pop(); |
| 4810 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); | 4814 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); |
| 4811 HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements)); | 4815 HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements)); |
| 4812 AddCheckConstantFunction(expr, | 4816 AddCheckConstantFunction(expr, function, function_map, true); |
| 4813 function, | |
| 4814 expr->GetReceiverTypes()->first(), | |
| 4815 true); | |
| 4816 HInstruction* result = | 4817 HInstruction* result = |
| 4817 new(zone()) HApplyArguments(function, receiver, length, elements); | 4818 new(zone()) HApplyArguments(function, receiver, length, elements); |
| 4818 result->set_position(expr->position()); | 4819 result->set_position(expr->position()); |
| 4819 ast_context()->ReturnInstruction(result, expr->id()); | 4820 ast_context()->ReturnInstruction(result, expr->id()); |
| 4820 return true; | 4821 return true; |
| 4821 } | 4822 } |
| 4822 | 4823 |
| 4823 | 4824 |
| 4824 void HGraphBuilder::VisitCall(Call* expr) { | 4825 void HGraphBuilder::VisitCall(Call* expr) { |
| 4825 ASSERT(!HasStackOverflow()); | 4826 ASSERT(!HasStackOverflow()); |
| (...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6759 } | 6760 } |
| 6760 } | 6761 } |
| 6761 | 6762 |
| 6762 #ifdef DEBUG | 6763 #ifdef DEBUG |
| 6763 if (graph_ != NULL) graph_->Verify(); | 6764 if (graph_ != NULL) graph_->Verify(); |
| 6764 if (allocator_ != NULL) allocator_->Verify(); | 6765 if (allocator_ != NULL) allocator_->Verify(); |
| 6765 #endif | 6766 #endif |
| 6766 } | 6767 } |
| 6767 | 6768 |
| 6768 } } // namespace v8::internal | 6769 } } // namespace v8::internal |
| OLD | NEW |