OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/execution.h" | 8 #include "src/execution.h" |
9 #include "src/heap/spaces-inl.h" | 9 #include "src/heap/spaces-inl.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 if (script_obj->IsScript()) { | 168 if (script_obj->IsScript()) { |
169 Handle<Script> script = Handle<Script>::cast(script_obj); | 169 Handle<Script> script = Handle<Script>::cast(script_obj); |
170 Object* source_url = script->source_url(); | 170 Object* source_url = script->source_url(); |
171 if (source_url->IsString()) return Handle<Object>(source_url, isolate); | 171 if (source_url->IsString()) return Handle<Object>(source_url, isolate); |
172 return Handle<Object>(script->name(), isolate); | 172 return Handle<Object>(script->name(), isolate); |
173 } | 173 } |
174 return isolate->factory()->null_value(); | 174 return isolate->factory()->null_value(); |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 bool CheckMethodName(Handle<JSObject> obj, Handle<Name> name, | 178 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, |
179 Handle<JSFunction> fun, | 179 Handle<JSFunction> fun, |
180 LookupIterator::Configuration config) { | 180 LookupIterator::Configuration config) { |
181 LookupIterator iter(obj, name, config); | 181 LookupIterator iter = |
| 182 LookupIterator::PropertyOrElement(isolate, obj, name, config); |
182 if (iter.state() == LookupIterator::DATA) { | 183 if (iter.state() == LookupIterator::DATA) { |
183 return iter.GetDataValue().is_identical_to(fun); | 184 return iter.GetDataValue().is_identical_to(fun); |
184 } else if (iter.state() == LookupIterator::ACCESSOR) { | 185 } else if (iter.state() == LookupIterator::ACCESSOR) { |
185 Handle<Object> accessors = iter.GetAccessors(); | 186 Handle<Object> accessors = iter.GetAccessors(); |
186 if (accessors->IsAccessorPair()) { | 187 if (accessors->IsAccessorPair()) { |
187 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); | 188 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); |
188 return pair->getter() == *fun || pair->setter() == *fun; | 189 return pair->getter() == *fun || pair->setter() == *fun; |
189 } | 190 } |
190 } | 191 } |
191 return false; | 192 return false; |
192 } | 193 } |
193 | 194 |
194 | 195 |
195 Handle<Object> CallSite::GetMethodName(Isolate* isolate) { | 196 Handle<Object> CallSite::GetMethodName(Isolate* isolate) { |
196 MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate, receiver_); | 197 MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate, receiver_); |
197 Handle<JSReceiver> receiver; | 198 Handle<JSReceiver> receiver; |
198 if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) { | 199 if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) { |
199 return isolate->factory()->null_value(); | 200 return isolate->factory()->null_value(); |
200 } | 201 } |
201 | 202 |
202 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); | 203 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); |
203 Handle<Object> function_name(fun_->shared()->name(), isolate); | 204 Handle<Object> function_name(fun_->shared()->name(), isolate); |
204 if (function_name->IsName()) { | 205 if (function_name->IsName()) { |
205 Handle<Name> name = Handle<Name>::cast(function_name); | 206 Handle<Name> name = Handle<Name>::cast(function_name); |
206 if (CheckMethodName(obj, name, fun_, | 207 if (CheckMethodName(isolate, obj, name, fun_, |
207 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR)) | 208 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR)) |
208 return name; | 209 return name; |
209 } | 210 } |
210 | 211 |
211 HandleScope outer_scope(isolate); | 212 HandleScope outer_scope(isolate); |
212 Handle<Object> result; | 213 Handle<Object> result; |
213 for (PrototypeIterator iter(isolate, obj, | 214 for (PrototypeIterator iter(isolate, obj, |
214 PrototypeIterator::START_AT_RECEIVER); | 215 PrototypeIterator::START_AT_RECEIVER); |
215 !iter.IsAtEnd(); iter.Advance()) { | 216 !iter.IsAtEnd(); iter.Advance()) { |
216 Handle<Object> current = PrototypeIterator::GetCurrent(iter); | 217 Handle<Object> current = PrototypeIterator::GetCurrent(iter); |
217 if (!current->IsJSObject()) break; | 218 if (!current->IsJSObject()) break; |
218 Handle<JSObject> current_obj = Handle<JSObject>::cast(current); | 219 Handle<JSObject> current_obj = Handle<JSObject>::cast(current); |
219 if (current_obj->IsAccessCheckNeeded()) break; | 220 if (current_obj->IsAccessCheckNeeded()) break; |
220 Handle<FixedArray> keys = JSObject::GetEnumPropertyKeys(current_obj, false); | 221 Handle<FixedArray> keys = JSObject::GetEnumPropertyKeys(current_obj, false); |
221 for (int i = 0; i < keys->length(); i++) { | 222 for (int i = 0; i < keys->length(); i++) { |
222 HandleScope inner_scope(isolate); | 223 HandleScope inner_scope(isolate); |
223 if (!keys->get(i)->IsName()) continue; | 224 if (!keys->get(i)->IsName()) continue; |
224 Handle<Name> name_key(Name::cast(keys->get(i)), isolate); | 225 Handle<Name> name_key(Name::cast(keys->get(i)), isolate); |
225 if (!CheckMethodName(current_obj, name_key, fun_, | 226 if (!CheckMethodName(isolate, current_obj, name_key, fun_, |
226 LookupIterator::OWN_SKIP_INTERCEPTOR)) | 227 LookupIterator::OWN_SKIP_INTERCEPTOR)) |
227 continue; | 228 continue; |
228 // Return null in case of duplicates to avoid confusion. | 229 // Return null in case of duplicates to avoid confusion. |
229 if (!result.is_null()) return isolate->factory()->null_value(); | 230 if (!result.is_null()) return isolate->factory()->null_value(); |
230 result = inner_scope.CloseAndEscape(name_key); | 231 result = inner_scope.CloseAndEscape(name_key); |
231 } | 232 } |
232 } | 233 } |
233 | 234 |
234 if (!result.is_null()) return outer_scope.CloseAndEscape(result); | 235 if (!result.is_null()) return outer_scope.CloseAndEscape(result); |
235 return isolate->factory()->null_value(); | 236 return isolate->factory()->null_value(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 374 } |
374 } else { | 375 } else { |
375 builder.AppendCharacter(*c); | 376 builder.AppendCharacter(*c); |
376 } | 377 } |
377 } | 378 } |
378 | 379 |
379 return builder.Finish(); | 380 return builder.Finish(); |
380 } | 381 } |
381 } // namespace internal | 382 } // namespace internal |
382 } // namespace v8 | 383 } // namespace v8 |
OLD | NEW |