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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 if (script_obj->IsScript()) { | 190 if (script_obj->IsScript()) { |
191 Handle<Script> script = Handle<Script>::cast(script_obj); | 191 Handle<Script> script = Handle<Script>::cast(script_obj); |
192 Object* source_url = script->source_url(); | 192 Object* source_url = script->source_url(); |
193 if (source_url->IsString()) return Handle<Object>(source_url, isolate); | 193 if (source_url->IsString()) return Handle<Object>(source_url, isolate); |
194 return Handle<Object>(script->name(), isolate); | 194 return Handle<Object>(script->name(), isolate); |
195 } | 195 } |
196 return isolate->factory()->null_value(); | 196 return isolate->factory()->null_value(); |
197 } | 197 } |
198 | 198 |
199 | 199 |
200 bool CheckMethodName(Handle<JSObject> obj, Handle<Name> name, | |
201 Handle<JSFunction> fun) { | |
Igor Sheludko
2015/05/05 10:30:49
Maybe it's better to use LookupIterator here.
| |
202 if (obj->IsAccessCheckNeeded()) return false; | |
203 if (JSObject::GetDataProperty(obj, name).is_identical_to(fun)) return true; | |
204 Handle<Object> getter = | |
205 JSObject::GetAccessor(obj, name, ACCESSOR_GETTER).ToHandleChecked(); | |
206 if (getter.is_identical_to(fun)) return true; | |
207 Handle<Object> setter = | |
208 JSObject::GetAccessor(obj, name, ACCESSOR_SETTER).ToHandleChecked(); | |
209 return setter.is_identical_to(fun); | |
210 } | |
211 | |
212 | |
213 Handle<Object> CallSite::GetMethodName(Isolate* isolate) { | |
214 MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate, receiver_); | |
215 Handle<JSReceiver> receiver; | |
216 if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) { | |
217 return isolate->factory()->null_value(); | |
218 } | |
219 | |
220 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); | |
221 Handle<Object> function_name(fun_->shared()->name(), isolate); | |
222 if (function_name->IsName()) { | |
223 Handle<Name> name = Handle<Name>::cast(function_name); | |
224 if (CheckMethodName(obj, name, fun_)) return function_name; | |
225 } | |
226 | |
227 HandleScope scope(isolate); | |
228 Handle<Object> name; | |
229 for (PrototypeIterator iter(isolate, obj, | |
230 PrototypeIterator::START_AT_RECEIVER); | |
231 !iter.IsAtEnd(); iter.Advance()) { | |
232 Handle<JSObject> current = | |
233 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)); | |
234 if (current->IsAccessCheckNeeded()) break; | |
235 Handle<Object> lookup(current->SlowReverseLookup(*fun_), isolate); | |
Igor Sheludko
2015/05/05 10:30:49
SlowReverseLookup() does not look into accessor pa
| |
236 if (lookup->IsName()) { | |
237 if (!name.is_null()) break; | |
Igor Sheludko
2015/05/05 10:30:49
You probably wanted to return null at this point t
| |
238 name = lookup; | |
239 } | |
240 } | |
241 | |
242 if (!name.is_null()) return scope.CloseAndEscape(name); | |
243 return isolate->factory()->null_value(); | |
244 } | |
245 | |
246 | |
200 int CallSite::GetLineNumber(Isolate* isolate) { | 247 int CallSite::GetLineNumber(Isolate* isolate) { |
201 if (pos_ >= 0) { | 248 if (pos_ >= 0) { |
202 Handle<Object> script_obj(fun_->shared()->script(), isolate); | 249 Handle<Object> script_obj(fun_->shared()->script(), isolate); |
203 if (script_obj->IsScript()) { | 250 if (script_obj->IsScript()) { |
204 Handle<Script> script = Handle<Script>::cast(script_obj); | 251 Handle<Script> script = Handle<Script>::cast(script_obj); |
205 return Script::GetLineNumber(script, pos_) + 1; | 252 return Script::GetLineNumber(script, pos_) + 1; |
206 } | 253 } |
207 } | 254 } |
208 return -1; | 255 return -1; |
209 } | 256 } |
(...skipping 25 matching lines...) Expand all Loading... | |
235 | 282 |
236 | 283 |
237 bool CallSite::IsEval(Isolate* isolate) { | 284 bool CallSite::IsEval(Isolate* isolate) { |
238 Handle<Object> script(fun_->shared()->script(), isolate); | 285 Handle<Object> script(fun_->shared()->script(), isolate); |
239 return script->IsScript() && | 286 return script->IsScript() && |
240 Handle<Script>::cast(script)->compilation_type() == | 287 Handle<Script>::cast(script)->compilation_type() == |
241 Script::COMPILATION_TYPE_EVAL; | 288 Script::COMPILATION_TYPE_EVAL; |
242 } | 289 } |
243 | 290 |
244 | 291 |
292 bool CallSite::IsConstructor(Isolate* isolate) { | |
293 if (!receiver_->IsJSObject()) return false; | |
294 Handle<Object> constructor = | |
295 JSObject::GetDataProperty(Handle<JSObject>::cast(receiver_), | |
296 isolate->factory()->constructor_string()); | |
297 return constructor.is_identical_to(fun_); | |
298 } | |
299 | |
300 | |
245 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, | 301 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, |
246 Handle<String> arg0, | 302 Handle<String> arg0, |
247 Handle<String> arg1, | 303 Handle<String> arg1, |
248 Handle<String> arg2) { | 304 Handle<String> arg2) { |
249 const char* template_string; | 305 const char* template_string; |
250 switch (template_index) { | 306 switch (template_index) { |
251 #define CASE(NAME, STRING) \ | 307 #define CASE(NAME, STRING) \ |
252 case k##NAME: \ | 308 case k##NAME: \ |
253 template_string = STRING; \ | 309 template_string = STRING; \ |
254 break; | 310 break; |
(...skipping 16 matching lines...) Expand all Loading... | |
271 DCHECK(i < arraysize(args)); | 327 DCHECK(i < arraysize(args)); |
272 builder.AppendString(args[i++]); | 328 builder.AppendString(args[i++]); |
273 } else { | 329 } else { |
274 builder.AppendCharacter(*c); | 330 builder.AppendCharacter(*c); |
275 } | 331 } |
276 } | 332 } |
277 | 333 |
278 return builder.Finish(); | 334 return builder.Finish(); |
279 } | 335 } |
280 } } // namespace v8::internal | 336 } } // namespace v8::internal |
OLD | NEW |