| 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 | |
| 19 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, | 18 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, |
| 20 Handle<Object> object, | 19 Handle<Object> object, |
| 21 Handle<Object> key, | 20 Handle<Object> key) { |
| 22 LanguageMode language_mode) { | |
| 23 if (object->IsUndefined() || object->IsNull()) { | 21 if (object->IsUndefined() || object->IsNull()) { |
| 24 THROW_NEW_ERROR( | 22 THROW_NEW_ERROR( |
| 25 isolate, | 23 isolate, |
| 26 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), | 24 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), |
| 27 Object); | 25 Object); |
| 28 } | 26 } |
| 29 | 27 |
| 30 bool success = false; | 28 bool success = false; |
| 31 LookupIterator it = | 29 LookupIterator it = |
| 32 LookupIterator::PropertyOrElement(isolate, object, key, &success); | 30 LookupIterator::PropertyOrElement(isolate, object, key, &success); |
| 33 if (!success) return MaybeHandle<Object>(); | 31 if (!success) return MaybeHandle<Object>(); |
| 34 | 32 |
| 35 return Object::GetProperty(&it, language_mode); | 33 return Object::GetProperty(&it); |
| 36 } | 34 } |
| 37 | 35 |
| 38 | |
| 39 static MaybeHandle<Object> KeyedGetObjectProperty(Isolate* isolate, | 36 static MaybeHandle<Object> KeyedGetObjectProperty(Isolate* isolate, |
| 40 Handle<Object> receiver_obj, | 37 Handle<Object> receiver_obj, |
| 41 Handle<Object> key_obj, | 38 Handle<Object> key_obj) { |
| 42 LanguageMode language_mode) { | |
| 43 // Fast cases for getting named properties of the receiver JSObject | 39 // Fast cases for getting named properties of the receiver JSObject |
| 44 // itself. | 40 // itself. |
| 45 // | 41 // |
| 46 // The global proxy objects has to be excluded since LookupOwn on | 42 // The global proxy objects has to be excluded since LookupOwn on |
| 47 // the global proxy object can return a valid result even though the | 43 // the global proxy object can return a valid result even though the |
| 48 // global proxy object never has properties. This is the case | 44 // global proxy object never has properties. This is the case |
| 49 // because the global proxy object forwards everything to its hidden | 45 // because the global proxy object forwards everything to its hidden |
| 50 // prototype including own lookups. | 46 // prototype including own lookups. |
| 51 // | 47 // |
| 52 // Additionally, we need to make sure that we do not cache results | 48 // Additionally, we need to make sure that we do not cache results |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 Handle<String> str = Handle<String>::cast(receiver_obj); | 102 Handle<String> str = Handle<String>::cast(receiver_obj); |
| 107 int index = Handle<Smi>::cast(key_obj)->value(); | 103 int index = Handle<Smi>::cast(key_obj)->value(); |
| 108 if (index >= 0 && index < str->length()) { | 104 if (index >= 0 && index < str->length()) { |
| 109 Factory* factory = isolate->factory(); | 105 Factory* factory = isolate->factory(); |
| 110 return factory->LookupSingleCharacterStringFromCode( | 106 return factory->LookupSingleCharacterStringFromCode( |
| 111 String::Flatten(str)->Get(index)); | 107 String::Flatten(str)->Get(index)); |
| 112 } | 108 } |
| 113 } | 109 } |
| 114 | 110 |
| 115 // Fall back to GetObjectProperty. | 111 // Fall back to GetObjectProperty. |
| 116 return Runtime::GetObjectProperty(isolate, receiver_obj, key_obj, | 112 return Runtime::GetObjectProperty(isolate, receiver_obj, key_obj); |
| 117 language_mode); | |
| 118 } | 113 } |
| 119 | 114 |
| 120 | 115 |
| 121 Maybe<bool> Runtime::DeleteObjectProperty(Isolate* isolate, | 116 Maybe<bool> Runtime::DeleteObjectProperty(Isolate* isolate, |
| 122 Handle<JSReceiver> receiver, | 117 Handle<JSReceiver> receiver, |
| 123 Handle<Object> key, | 118 Handle<Object> key, |
| 124 LanguageMode language_mode) { | 119 LanguageMode language_mode) { |
| 125 bool success = false; | 120 bool success = false; |
| 126 LookupIterator it = LookupIterator::PropertyOrElement( | 121 LookupIterator it = LookupIterator::PropertyOrElement( |
| 127 isolate, receiver, key, &success, LookupIterator::HIDDEN); | 122 isolate, receiver, key, &success, LookupIterator::HIDDEN); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 | 374 |
| 380 RUNTIME_FUNCTION(Runtime_GetProperty) { | 375 RUNTIME_FUNCTION(Runtime_GetProperty) { |
| 381 HandleScope scope(isolate); | 376 HandleScope scope(isolate); |
| 382 DCHECK(args.length() == 2); | 377 DCHECK(args.length() == 2); |
| 383 | 378 |
| 384 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 379 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 385 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 380 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 386 | 381 |
| 387 Handle<Object> result; | 382 Handle<Object> result; |
| 388 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 383 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 389 isolate, result, | 384 isolate, result, Runtime::GetObjectProperty(isolate, object, key)); |
| 390 Runtime::GetObjectProperty(isolate, object, key, SLOPPY)); | |
| 391 return *result; | 385 return *result; |
| 392 } | 386 } |
| 393 | 387 |
| 394 | |
| 395 RUNTIME_FUNCTION(Runtime_GetPropertyStrong) { | |
| 396 HandleScope scope(isolate); | |
| 397 DCHECK(args.length() == 2); | |
| 398 | |
| 399 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | |
| 400 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | |
| 401 | |
| 402 Handle<Object> result; | |
| 403 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 404 isolate, result, | |
| 405 Runtime::GetObjectProperty(isolate, object, key, STRONG)); | |
| 406 return *result; | |
| 407 } | |
| 408 | |
| 409 | 388 |
| 410 // KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric. | 389 // KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric. |
| 411 RUNTIME_FUNCTION(Runtime_KeyedGetProperty) { | 390 RUNTIME_FUNCTION(Runtime_KeyedGetProperty) { |
| 412 HandleScope scope(isolate); | 391 HandleScope scope(isolate); |
| 413 DCHECK(args.length() == 2); | 392 DCHECK(args.length() == 2); |
| 414 | 393 |
| 415 CONVERT_ARG_HANDLE_CHECKED(Object, receiver_obj, 0); | 394 CONVERT_ARG_HANDLE_CHECKED(Object, receiver_obj, 0); |
| 416 CONVERT_ARG_HANDLE_CHECKED(Object, key_obj, 1); | 395 CONVERT_ARG_HANDLE_CHECKED(Object, key_obj, 1); |
| 417 | 396 |
| 418 Handle<Object> result; | 397 Handle<Object> result; |
| 419 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 398 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 420 isolate, result, | 399 isolate, result, KeyedGetObjectProperty(isolate, receiver_obj, key_obj)); |
| 421 KeyedGetObjectProperty(isolate, receiver_obj, key_obj, SLOPPY)); | |
| 422 return *result; | 400 return *result; |
| 423 } | 401 } |
| 424 | 402 |
| 425 | |
| 426 RUNTIME_FUNCTION(Runtime_KeyedGetPropertyStrong) { | |
| 427 HandleScope scope(isolate); | |
| 428 DCHECK(args.length() == 2); | |
| 429 | |
| 430 CONVERT_ARG_HANDLE_CHECKED(Object, receiver_obj, 0); | |
| 431 CONVERT_ARG_HANDLE_CHECKED(Object, key_obj, 1); | |
| 432 | |
| 433 Handle<Object> result; | |
| 434 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 435 isolate, result, | |
| 436 KeyedGetObjectProperty(isolate, receiver_obj, key_obj, STRONG)); | |
| 437 return *result; | |
| 438 } | |
| 439 | |
| 440 | 403 |
| 441 RUNTIME_FUNCTION(Runtime_AddNamedProperty) { | 404 RUNTIME_FUNCTION(Runtime_AddNamedProperty) { |
| 442 HandleScope scope(isolate); | 405 HandleScope scope(isolate); |
| 443 RUNTIME_ASSERT(args.length() == 4); | 406 RUNTIME_ASSERT(args.length() == 4); |
| 444 | 407 |
| 445 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 408 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 446 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 409 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 447 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 410 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 448 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 411 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
| 449 | 412 |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 DCHECK(args.length() == 2); | 1233 DCHECK(args.length() == 2); |
| 1271 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); | 1234 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); |
| 1272 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); | 1235 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); |
| 1273 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1236 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1274 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); | 1237 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); |
| 1275 return *o; | 1238 return *o; |
| 1276 } | 1239 } |
| 1277 | 1240 |
| 1278 } // namespace internal | 1241 } // namespace internal |
| 1279 } // namespace v8 | 1242 } // namespace v8 |
| OLD | NEW |