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 1941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 Initialize(Handle<JSFunction>::null()); | 1952 Initialize(Handle<JSFunction>::null()); |
1953 } | 1953 } |
1954 } | 1954 } |
1955 | 1955 |
1956 | 1956 |
1957 CallOptimization::CallOptimization(Handle<JSFunction> function) { | 1957 CallOptimization::CallOptimization(Handle<JSFunction> function) { |
1958 Initialize(function); | 1958 Initialize(function); |
1959 } | 1959 } |
1960 | 1960 |
1961 | 1961 |
1962 int CallOptimization::GetPrototypeDepthOfExpectedType( | 1962 Handle<Map> CallOptimization::LookupHolderOfExpectedType( |
| 1963 Handle<JSObject> receiver, |
1963 Handle<JSObject> object, | 1964 Handle<JSObject> object, |
1964 Handle<JSObject> holder) const { | 1965 Handle<JSObject> holder, |
| 1966 HolderLookup* holder_lookup) const { |
1965 ASSERT(is_simple_api_call()); | 1967 ASSERT(is_simple_api_call()); |
1966 if (expected_receiver_type_.is_null()) return 0; | 1968 ASSERT_EQ(kHolderNotFound, *holder_lookup); |
1967 int depth = 0; | 1969 *holder_lookup = kHolderIsReceiver; |
| 1970 Handle<Map> map_to_holder; |
| 1971 if (expected_receiver_type_.is_null()) { |
| 1972 // no expected type, load from receiver. |
| 1973 return map_to_holder; |
| 1974 } |
| 1975 // walk down the prototype chain to the object |
| 1976 while (!receiver.is_identical_to(object)) { |
| 1977 *holder_lookup = kHolderIsPrototypeOfMap; |
| 1978 map_to_holder = Handle<Map>(receiver->map()); |
| 1979 receiver = Handle<JSObject>(JSObject::cast(map_to_holder->prototype())); |
| 1980 ASSERT(!expected_receiver_type_->IsTemplateFor(*map_to_holder)); |
| 1981 } |
| 1982 // start looking for the holder |
1968 while (!object.is_identical_to(holder)) { | 1983 while (!object.is_identical_to(holder)) { |
1969 if (expected_receiver_type_->IsTemplateFor(object->map())) return depth; | 1984 Handle<Map> object_map(object->map()); |
1970 object = Handle<JSObject>(JSObject::cast(object->GetPrototype())); | 1985 if (expected_receiver_type_->IsTemplateFor(*object_map)) { |
1971 if (!object->map()->is_hidden_prototype()) return kInvalidProtoDepth; | 1986 return map_to_holder; |
1972 ++depth; | 1987 } |
| 1988 if (!object_map->is_hidden_prototype()) { |
| 1989 *holder_lookup = kHolderNotFound; |
| 1990 return Handle<Map>::null(); |
| 1991 } |
| 1992 *holder_lookup = kHolderIsPrototypeOfMap; |
| 1993 map_to_holder = object_map; |
| 1994 object = Handle<JSObject>(JSObject::cast(object_map->prototype())); |
1973 } | 1995 } |
1974 if (expected_receiver_type_->IsTemplateFor(holder->map())) return depth; | 1996 if (expected_receiver_type_->IsTemplateFor(holder->map())) { |
1975 return kInvalidProtoDepth; | 1997 return map_to_holder; |
| 1998 } |
| 1999 *holder_lookup = kHolderNotFound; |
| 2000 return Handle<Map>::null(); |
1976 } | 2001 } |
1977 | 2002 |
1978 | 2003 |
1979 void CallOptimization::Initialize(Handle<JSFunction> function) { | 2004 void CallOptimization::Initialize(Handle<JSFunction> function) { |
1980 constant_function_ = Handle<JSFunction>::null(); | 2005 constant_function_ = Handle<JSFunction>::null(); |
1981 is_simple_api_call_ = false; | 2006 is_simple_api_call_ = false; |
1982 expected_receiver_type_ = Handle<FunctionTemplateInfo>::null(); | 2007 expected_receiver_type_ = Handle<FunctionTemplateInfo>::null(); |
1983 api_call_info_ = Handle<CallHandlerInfo>::null(); | 2008 api_call_info_ = Handle<CallHandlerInfo>::null(); |
1984 | 2009 |
1985 if (function.is_null() || !function->is_compiled()) return; | 2010 if (function.is_null() || !function->is_compiled()) return; |
(...skipping 23 matching lines...) Expand all Loading... |
2009 Handle<FunctionTemplateInfo>( | 2034 Handle<FunctionTemplateInfo>( |
2010 FunctionTemplateInfo::cast(signature->receiver())); | 2035 FunctionTemplateInfo::cast(signature->receiver())); |
2011 } | 2036 } |
2012 } | 2037 } |
2013 | 2038 |
2014 is_simple_api_call_ = true; | 2039 is_simple_api_call_ = true; |
2015 } | 2040 } |
2016 | 2041 |
2017 | 2042 |
2018 } } // namespace v8::internal | 2043 } } // namespace v8::internal |
OLD | NEW |