OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
11 #include "src/messages.h" | 11 #include "src/messages.h" |
12 #include "src/property-descriptor.h" | 12 #include "src/property-descriptor.h" |
13 #include "src/runtime/runtime.h" | 13 #include "src/runtime/runtime.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, | 18 MaybeHandle<Object> Runtime::GetObjectProperty( |
19 Handle<Object> object, | 19 Isolate* isolate, Handle<Object> object, Handle<Object> key, |
20 Handle<Object> key) { | 20 bool should_throw_reference_error) { |
21 if (object->IsUndefined(isolate) || object->IsNull(isolate)) { | 21 if (object->IsUndefined(isolate) || object->IsNull(isolate)) { |
22 THROW_NEW_ERROR( | 22 THROW_NEW_ERROR( |
23 isolate, | 23 isolate, |
24 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), | 24 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), |
25 Object); | 25 Object); |
26 } | 26 } |
27 | 27 |
28 bool success = false; | 28 bool success = false; |
29 LookupIterator it = | 29 LookupIterator it = |
30 LookupIterator::PropertyOrElement(isolate, object, key, &success); | 30 LookupIterator::PropertyOrElement(isolate, object, key, &success); |
31 if (!success) return MaybeHandle<Object>(); | 31 if (!success) return MaybeHandle<Object>(); |
32 | 32 |
33 return Object::GetProperty(&it); | 33 MaybeHandle<Object> result = Object::GetProperty(&it); |
| 34 if (!result.is_null() && should_throw_reference_error && !it.IsFound()) { |
| 35 THROW_NEW_ERROR( |
| 36 isolate, NewReferenceError(MessageTemplate::kNotDefined, key), Object); |
| 37 } |
| 38 return result; |
34 } | 39 } |
35 | 40 |
36 static MaybeHandle<Object> KeyedGetObjectProperty(Isolate* isolate, | 41 static MaybeHandle<Object> KeyedGetObjectProperty(Isolate* isolate, |
37 Handle<Object> receiver_obj, | 42 Handle<Object> receiver_obj, |
38 Handle<Object> key_obj) { | 43 Handle<Object> key_obj) { |
39 // Fast cases for getting named properties of the receiver JSObject | 44 // Fast cases for getting named properties of the receiver JSObject |
40 // itself. | 45 // itself. |
41 // | 46 // |
42 // The global proxy objects has to be excluded since LookupOwn on | 47 // The global proxy objects has to be excluded since LookupOwn on |
43 // the global proxy object can return a valid result even though the | 48 // the global proxy object can return a valid result even though the |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 HandleScope scope(isolate); | 341 HandleScope scope(isolate); |
337 DCHECK(args.length() == 2); | 342 DCHECK(args.length() == 2); |
338 | 343 |
339 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 344 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
340 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 345 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
341 | 346 |
342 RETURN_RESULT_OR_FAILURE(isolate, | 347 RETURN_RESULT_OR_FAILURE(isolate, |
343 Runtime::GetObjectProperty(isolate, object, key)); | 348 Runtime::GetObjectProperty(isolate, object, key)); |
344 } | 349 } |
345 | 350 |
346 RUNTIME_FUNCTION(Runtime_GetGlobal) { | 351 namespace { |
347 HandleScope scope(isolate); | |
348 DCHECK(args.length() == 1); | |
349 | 352 |
350 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 353 Object* GetGlobal(Isolate* isolate, Handle<String> name, |
351 | 354 bool should_throw_reference_error) { |
352 Handle<JSGlobalObject> global = isolate->global_object(); | 355 Handle<JSGlobalObject> global = isolate->global_object(); |
353 | 356 |
354 Handle<ScriptContextTable> script_contexts( | 357 Handle<ScriptContextTable> script_contexts( |
355 global->native_context()->script_context_table()); | 358 global->native_context()->script_context_table()); |
356 | 359 |
357 ScriptContextTable::LookupResult lookup_result; | 360 ScriptContextTable::LookupResult lookup_result; |
358 if (ScriptContextTable::Lookup(script_contexts, name, &lookup_result)) { | 361 if (ScriptContextTable::Lookup(script_contexts, name, &lookup_result)) { |
359 Handle<Context> script_context = ScriptContextTable::GetContext( | 362 Handle<Context> script_context = ScriptContextTable::GetContext( |
360 script_contexts, lookup_result.context_index); | 363 script_contexts, lookup_result.context_index); |
361 Handle<Object> result = | 364 Handle<Object> result = |
362 FixedArray::get(*script_context, lookup_result.slot_index, isolate); | 365 FixedArray::get(*script_context, lookup_result.slot_index, isolate); |
363 if (*result == *isolate->factory()->the_hole_value()) { | 366 if (*result == *isolate->factory()->the_hole_value()) { |
364 THROW_NEW_ERROR_RETURN_FAILURE( | 367 THROW_NEW_ERROR_RETURN_FAILURE( |
365 isolate, NewReferenceError(MessageTemplate::kNotDefined, name)); | 368 isolate, NewReferenceError(MessageTemplate::kNotDefined, name)); |
366 } | 369 } |
367 | |
368 return *result; | 370 return *result; |
369 } | 371 } |
370 | 372 |
371 Handle<Object> result; | 373 Handle<Object> result; |
372 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 374 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
373 isolate, result, Runtime::GetObjectProperty(isolate, global, name)); | 375 isolate, result, |
| 376 Runtime::GetObjectProperty(isolate, global, name, |
| 377 should_throw_reference_error)); |
374 return *result; | 378 return *result; |
375 } | 379 } |
376 | 380 |
| 381 } // namespace |
| 382 |
| 383 RUNTIME_FUNCTION(Runtime_GetGlobalInsideTypeof) { |
| 384 HandleScope scope(isolate); |
| 385 DCHECK_EQ(1, args.length()); |
| 386 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 387 return GetGlobal(isolate, name, false); |
| 388 } |
| 389 |
| 390 RUNTIME_FUNCTION(Runtime_GetGlobalNotInsideTypeof) { |
| 391 HandleScope scope(isolate); |
| 392 DCHECK_EQ(1, args.length()); |
| 393 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 394 return GetGlobal(isolate, name, true); |
| 395 } |
| 396 |
377 // KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric. | 397 // KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric. |
378 RUNTIME_FUNCTION(Runtime_KeyedGetProperty) { | 398 RUNTIME_FUNCTION(Runtime_KeyedGetProperty) { |
379 HandleScope scope(isolate); | 399 HandleScope scope(isolate); |
380 DCHECK(args.length() == 2); | 400 DCHECK(args.length() == 2); |
381 | 401 |
382 CONVERT_ARG_HANDLE_CHECKED(Object, receiver_obj, 0); | 402 CONVERT_ARG_HANDLE_CHECKED(Object, receiver_obj, 0); |
383 CONVERT_ARG_HANDLE_CHECKED(Object, key_obj, 1); | 403 CONVERT_ARG_HANDLE_CHECKED(Object, key_obj, 1); |
384 | 404 |
385 RETURN_RESULT_OR_FAILURE( | 405 RETURN_RESULT_OR_FAILURE( |
386 isolate, KeyedGetObjectProperty(isolate, receiver_obj, key_obj)); | 406 isolate, KeyedGetObjectProperty(isolate, receiver_obj, key_obj)); |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 isolate, o, key, &success, LookupIterator::OWN); | 990 isolate, o, key, &success, LookupIterator::OWN); |
971 if (!success) return isolate->heap()->exception(); | 991 if (!success) return isolate->heap()->exception(); |
972 MAYBE_RETURN( | 992 MAYBE_RETURN( |
973 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 993 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
974 isolate->heap()->exception()); | 994 isolate->heap()->exception()); |
975 return *value; | 995 return *value; |
976 } | 996 } |
977 | 997 |
978 } // namespace internal | 998 } // namespace internal |
979 } // namespace v8 | 999 } // namespace v8 |
OLD | NEW |