OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 Initialize(Handle<JSFunction>::null()); | 1987 Initialize(Handle<JSFunction>::null()); |
1988 } | 1988 } |
1989 } | 1989 } |
1990 | 1990 |
1991 | 1991 |
1992 CallOptimization::CallOptimization(Handle<JSFunction> function) { | 1992 CallOptimization::CallOptimization(Handle<JSFunction> function) { |
1993 Initialize(function); | 1993 Initialize(function); |
1994 } | 1994 } |
1995 | 1995 |
1996 | 1996 |
1997 int CallOptimization::GetPrototypeDepthOfExpectedType( | 1997 Handle<Map> CallOptimization::LookupHolderOfExpectedType( |
| 1998 Handle<JSObject> receiver, |
1998 Handle<JSObject> object, | 1999 Handle<JSObject> object, |
1999 Handle<JSObject> holder) const { | 2000 Handle<JSObject> holder, |
| 2001 HolderLookup* holder_lookup) const { |
2000 ASSERT(is_simple_api_call()); | 2002 ASSERT(is_simple_api_call()); |
2001 if (expected_receiver_type_.is_null()) return 0; | 2003 ASSERT_EQ(kHolderNotFound, *holder_lookup); |
2002 int depth = 0; | 2004 *holder_lookup = kHolderIsReceiver; |
| 2005 Handle<Map> map_to_holder; |
| 2006 if (expected_receiver_type_.is_null()) { |
| 2007 // no expected type, load from receiver. |
| 2008 return map_to_holder; |
| 2009 } |
| 2010 // walk down the prototype chain to the object |
| 2011 while (!receiver.is_identical_to(object)) { |
| 2012 *holder_lookup = kHolderIsPrototypeOfMap; |
| 2013 map_to_holder = Handle<Map>(receiver->map()); |
| 2014 receiver = Handle<JSObject>(JSObject::cast(map_to_holder->prototype())); |
| 2015 } |
| 2016 // start looking for the holder |
2003 while (!object.is_identical_to(holder)) { | 2017 while (!object.is_identical_to(holder)) { |
2004 if (expected_receiver_type_->IsTemplateFor(object->map())) return depth; | 2018 Handle<Map> object_map(object->map()); |
2005 object = Handle<JSObject>(JSObject::cast(object->GetPrototype())); | 2019 if (expected_receiver_type_->IsTemplateFor(*object_map)) { |
2006 if (!object->map()->is_hidden_prototype()) return kInvalidProtoDepth; | 2020 return map_to_holder; |
2007 ++depth; | 2021 } |
| 2022 if (!object_map->is_hidden_prototype()) { |
| 2023 *holder_lookup = kHolderNotFound; |
| 2024 return Handle<Map>::null(); |
| 2025 } |
| 2026 *holder_lookup = kHolderIsPrototypeOfMap; |
| 2027 map_to_holder = object_map; |
| 2028 object = Handle<JSObject>(JSObject::cast(object_map->prototype())); |
2008 } | 2029 } |
2009 if (expected_receiver_type_->IsTemplateFor(holder->map())) return depth; | 2030 if (expected_receiver_type_->IsTemplateFor(holder->map())) { |
2010 return kInvalidProtoDepth; | 2031 return map_to_holder; |
| 2032 } |
| 2033 *holder_lookup = kHolderNotFound; |
| 2034 return Handle<Map>::null(); |
2011 } | 2035 } |
2012 | 2036 |
2013 | 2037 |
2014 void CallOptimization::Initialize(Handle<JSFunction> function) { | 2038 void CallOptimization::Initialize(Handle<JSFunction> function) { |
2015 constant_function_ = Handle<JSFunction>::null(); | 2039 constant_function_ = Handle<JSFunction>::null(); |
2016 is_simple_api_call_ = false; | 2040 is_simple_api_call_ = false; |
2017 expected_receiver_type_ = Handle<FunctionTemplateInfo>::null(); | 2041 expected_receiver_type_ = Handle<FunctionTemplateInfo>::null(); |
2018 api_call_info_ = Handle<CallHandlerInfo>::null(); | 2042 api_call_info_ = Handle<CallHandlerInfo>::null(); |
2019 | 2043 |
2020 if (function.is_null() || !function->is_compiled()) return; | 2044 if (function.is_null() || !function->is_compiled()) return; |
(...skipping 23 matching lines...) Expand all Loading... |
2044 Handle<FunctionTemplateInfo>( | 2068 Handle<FunctionTemplateInfo>( |
2045 FunctionTemplateInfo::cast(signature->receiver())); | 2069 FunctionTemplateInfo::cast(signature->receiver())); |
2046 } | 2070 } |
2047 } | 2071 } |
2048 | 2072 |
2049 is_simple_api_call_ = true; | 2073 is_simple_api_call_ = true; |
2050 } | 2074 } |
2051 | 2075 |
2052 | 2076 |
2053 } } // namespace v8::internal | 2077 } } // namespace v8::internal |
OLD | NEW |