| 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( | 18 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, |
| 19 Isolate* isolate, Handle<Object> object, Handle<Object> key, | 19 Handle<Object> object, |
| 20 bool should_throw_reference_error) { | 20 Handle<Object> key, |
| 21 bool* is_found_out) { |
| 21 if (object->IsUndefined(isolate) || object->IsNull(isolate)) { | 22 if (object->IsUndefined(isolate) || object->IsNull(isolate)) { |
| 22 THROW_NEW_ERROR( | 23 THROW_NEW_ERROR( |
| 23 isolate, | 24 isolate, |
| 24 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), | 25 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), |
| 25 Object); | 26 Object); |
| 26 } | 27 } |
| 27 | 28 |
| 28 bool success = false; | 29 bool success = false; |
| 29 LookupIterator it = | 30 LookupIterator it = |
| 30 LookupIterator::PropertyOrElement(isolate, object, key, &success); | 31 LookupIterator::PropertyOrElement(isolate, object, key, &success); |
| 31 if (!success) return MaybeHandle<Object>(); | 32 if (!success) return MaybeHandle<Object>(); |
| 32 | 33 |
| 33 MaybeHandle<Object> result = Object::GetProperty(&it); | 34 MaybeHandle<Object> result = Object::GetProperty(&it); |
| 34 if (!result.is_null() && should_throw_reference_error && !it.IsFound()) { | 35 if (is_found_out) *is_found_out = it.IsFound(); |
| 35 THROW_NEW_ERROR( | |
| 36 isolate, NewReferenceError(MessageTemplate::kNotDefined, key), Object); | |
| 37 } | |
| 38 return result; | 36 return result; |
| 39 } | 37 } |
| 40 | 38 |
| 41 static MaybeHandle<Object> KeyedGetObjectProperty(Isolate* isolate, | 39 static MaybeHandle<Object> KeyedGetObjectProperty(Isolate* isolate, |
| 42 Handle<Object> receiver_obj, | 40 Handle<Object> receiver_obj, |
| 43 Handle<Object> key_obj) { | 41 Handle<Object> key_obj) { |
| 44 // Fast cases for getting named properties of the receiver JSObject | 42 // Fast cases for getting named properties of the receiver JSObject |
| 45 // itself. | 43 // itself. |
| 46 // | 44 // |
| 47 // The global proxy objects has to be excluded since LookupOwn on | 45 // The global proxy objects has to be excluded since LookupOwn on |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 HandleScope scope(isolate); | 339 HandleScope scope(isolate); |
| 342 DCHECK(args.length() == 2); | 340 DCHECK(args.length() == 2); |
| 343 | 341 |
| 344 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 342 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 345 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 343 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 346 | 344 |
| 347 RETURN_RESULT_OR_FAILURE(isolate, | 345 RETURN_RESULT_OR_FAILURE(isolate, |
| 348 Runtime::GetObjectProperty(isolate, object, key)); | 346 Runtime::GetObjectProperty(isolate, object, key)); |
| 349 } | 347 } |
| 350 | 348 |
| 351 RUNTIME_FUNCTION(Runtime_GetGlobal) { | |
| 352 HandleScope scope(isolate); | |
| 353 DCHECK_EQ(3, args.length()); | |
| 354 CONVERT_SMI_ARG_CHECKED(slot, 0); | |
| 355 CONVERT_ARG_HANDLE_CHECKED(TypeFeedbackVector, vector, 1); | |
| 356 CONVERT_SMI_ARG_CHECKED(typeof_mode_value, 2); | |
| 357 TypeofMode typeof_mode = static_cast<TypeofMode>(typeof_mode_value); | |
| 358 bool should_throw_reference_error = typeof_mode == NOT_INSIDE_TYPEOF; | |
| 359 | |
| 360 FeedbackVectorSlot vector_slot = vector->ToSlot(slot); | |
| 361 DCHECK_EQ(FeedbackVectorSlotKind::LOAD_GLOBAL_IC, | |
| 362 vector->GetKind(vector_slot)); | |
| 363 Handle<String> name(vector->GetName(vector_slot), isolate); | |
| 364 DCHECK_NE(*name, *isolate->factory()->empty_string()); | |
| 365 | |
| 366 Handle<JSGlobalObject> global = isolate->global_object(); | |
| 367 | |
| 368 Handle<ScriptContextTable> script_contexts( | |
| 369 global->native_context()->script_context_table()); | |
| 370 | |
| 371 ScriptContextTable::LookupResult lookup_result; | |
| 372 if (ScriptContextTable::Lookup(script_contexts, name, &lookup_result)) { | |
| 373 Handle<Context> script_context = ScriptContextTable::GetContext( | |
| 374 script_contexts, lookup_result.context_index); | |
| 375 Handle<Object> result = | |
| 376 FixedArray::get(*script_context, lookup_result.slot_index, isolate); | |
| 377 if (*result == *isolate->factory()->the_hole_value()) { | |
| 378 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 379 isolate, NewReferenceError(MessageTemplate::kNotDefined, name)); | |
| 380 } | |
| 381 return *result; | |
| 382 } | |
| 383 | |
| 384 Handle<Object> result; | |
| 385 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 386 isolate, result, | |
| 387 Runtime::GetObjectProperty(isolate, global, name, | |
| 388 should_throw_reference_error)); | |
| 389 return *result; | |
| 390 } | |
| 391 | |
| 392 // KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric. | 349 // KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric. |
| 393 RUNTIME_FUNCTION(Runtime_KeyedGetProperty) { | 350 RUNTIME_FUNCTION(Runtime_KeyedGetProperty) { |
| 394 HandleScope scope(isolate); | 351 HandleScope scope(isolate); |
| 395 DCHECK(args.length() == 2); | 352 DCHECK(args.length() == 2); |
| 396 | 353 |
| 397 CONVERT_ARG_HANDLE_CHECKED(Object, receiver_obj, 0); | 354 CONVERT_ARG_HANDLE_CHECKED(Object, receiver_obj, 0); |
| 398 CONVERT_ARG_HANDLE_CHECKED(Object, key_obj, 1); | 355 CONVERT_ARG_HANDLE_CHECKED(Object, key_obj, 1); |
| 399 | 356 |
| 400 RETURN_RESULT_OR_FAILURE( | 357 RETURN_RESULT_OR_FAILURE( |
| 401 isolate, KeyedGetObjectProperty(isolate, receiver_obj, key_obj)); | 358 isolate, KeyedGetObjectProperty(isolate, receiver_obj, key_obj)); |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 isolate, o, key, &success, LookupIterator::OWN); | 922 isolate, o, key, &success, LookupIterator::OWN); |
| 966 if (!success) return isolate->heap()->exception(); | 923 if (!success) return isolate->heap()->exception(); |
| 967 MAYBE_RETURN( | 924 MAYBE_RETURN( |
| 968 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 925 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
| 969 isolate->heap()->exception()); | 926 isolate->heap()->exception()); |
| 970 return *value; | 927 return *value; |
| 971 } | 928 } |
| 972 | 929 |
| 973 } // namespace internal | 930 } // namespace internal |
| 974 } // namespace v8 | 931 } // namespace v8 |
| OLD | NEW |