| 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(Isolate* isolate, |
| 19 Handle<Object> object, | 19 Handle<Object> object, |
| 20 Handle<Object> key) { | 20 Handle<Object> key) { |
| 21 if (object->IsUndefined() || object->IsNull()) { | 21 if (object->IsUndefined(isolate) || object->IsNull()) { |
| 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>(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 55 Handle<Name> key = Handle<Name>::cast(key_obj); | 55 Handle<Name> key = Handle<Name>::cast(key_obj); |
| 56 if (receiver->IsJSGlobalObject()) { | 56 if (receiver->IsJSGlobalObject()) { |
| 57 // Attempt dictionary lookup. | 57 // Attempt dictionary lookup. |
| 58 GlobalDictionary* dictionary = receiver->global_dictionary(); | 58 GlobalDictionary* dictionary = receiver->global_dictionary(); |
| 59 int entry = dictionary->FindEntry(key); | 59 int entry = dictionary->FindEntry(key); |
| 60 if (entry != GlobalDictionary::kNotFound) { | 60 if (entry != GlobalDictionary::kNotFound) { |
| 61 DCHECK(dictionary->ValueAt(entry)->IsPropertyCell()); | 61 DCHECK(dictionary->ValueAt(entry)->IsPropertyCell()); |
| 62 PropertyCell* cell = PropertyCell::cast(dictionary->ValueAt(entry)); | 62 PropertyCell* cell = PropertyCell::cast(dictionary->ValueAt(entry)); |
| 63 if (cell->property_details().type() == DATA) { | 63 if (cell->property_details().type() == DATA) { |
| 64 Object* value = cell->value(); | 64 Object* value = cell->value(); |
| 65 if (!value->IsTheHole()) return Handle<Object>(value, isolate); | 65 if (!value->IsTheHole(isolate)) { |
| 66 return Handle<Object>(value, isolate); |
| 67 } |
| 66 // If value is the hole (meaning, absent) do the general lookup. | 68 // If value is the hole (meaning, absent) do the general lookup. |
| 67 } | 69 } |
| 68 } | 70 } |
| 69 } else if (!receiver->HasFastProperties()) { | 71 } else if (!receiver->HasFastProperties()) { |
| 70 // Attempt dictionary lookup. | 72 // Attempt dictionary lookup. |
| 71 NameDictionary* dictionary = receiver->property_dictionary(); | 73 NameDictionary* dictionary = receiver->property_dictionary(); |
| 72 int entry = dictionary->FindEntry(key); | 74 int entry = dictionary->FindEntry(key); |
| 73 if ((entry != NameDictionary::kNotFound) && | 75 if ((entry != NameDictionary::kNotFound) && |
| 74 (dictionary->DetailsAt(entry).type() == DATA)) { | 76 (dictionary->DetailsAt(entry).type() == DATA)) { |
| 75 Object* value = dictionary->ValueAt(entry); | 77 Object* value = dictionary->ValueAt(entry); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 Maybe<bool> result = | 189 Maybe<bool> result = |
| 188 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key); | 190 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key); |
| 189 if (!result.IsJust()) return isolate->heap()->exception(); | 191 if (!result.IsJust()) return isolate->heap()->exception(); |
| 190 return isolate->heap()->ToBoolean(result.FromJust()); | 192 return isolate->heap()->ToBoolean(result.FromJust()); |
| 191 | 193 |
| 192 } else if (object->IsString()) { | 194 } else if (object->IsString()) { |
| 193 return isolate->heap()->ToBoolean( | 195 return isolate->heap()->ToBoolean( |
| 194 key_is_array_index | 196 key_is_array_index |
| 195 ? index < static_cast<uint32_t>(String::cast(*object)->length()) | 197 ? index < static_cast<uint32_t>(String::cast(*object)->length()) |
| 196 : key->Equals(isolate->heap()->length_string())); | 198 : key->Equals(isolate->heap()->length_string())); |
| 197 } else if (object->IsNull() || object->IsUndefined()) { | 199 } else if (object->IsNull() || object->IsUndefined(isolate)) { |
| 198 THROW_NEW_ERROR_RETURN_FAILURE( | 200 THROW_NEW_ERROR_RETURN_FAILURE( |
| 199 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); | 201 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); |
| 200 } | 202 } |
| 201 | 203 |
| 202 return isolate->heap()->false_value(); | 204 return isolate->heap()->false_value(); |
| 203 } | 205 } |
| 204 | 206 |
| 205 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, | 207 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, |
| 206 Handle<Object> object, | 208 Handle<Object> object, |
| 207 Handle<Object> key, | 209 Handle<Object> key, |
| 208 Handle<Object> value, | 210 Handle<Object> value, |
| 209 LanguageMode language_mode) { | 211 LanguageMode language_mode) { |
| 210 if (object->IsUndefined() || object->IsNull()) { | 212 if (object->IsUndefined(isolate) || object->IsNull()) { |
| 211 THROW_NEW_ERROR( | 213 THROW_NEW_ERROR( |
| 212 isolate, | 214 isolate, |
| 213 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), | 215 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), |
| 214 Object); | 216 Object); |
| 215 } | 217 } |
| 216 | 218 |
| 217 // Check if the given key is an array index. | 219 // Check if the given key is an array index. |
| 218 bool success = false; | 220 bool success = false; |
| 219 LookupIterator it = | 221 LookupIterator it = |
| 220 LookupIterator::PropertyOrElement(isolate, object, key, &success); | 222 LookupIterator::PropertyOrElement(isolate, object, key, &success); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 } | 665 } |
| 664 | 666 |
| 665 | 667 |
| 666 RUNTIME_FUNCTION(Runtime_IsJSGlobalProxy) { | 668 RUNTIME_FUNCTION(Runtime_IsJSGlobalProxy) { |
| 667 SealHandleScope shs(isolate); | 669 SealHandleScope shs(isolate); |
| 668 DCHECK(args.length() == 1); | 670 DCHECK(args.length() == 1); |
| 669 CONVERT_ARG_CHECKED(Object, obj, 0); | 671 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 670 return isolate->heap()->ToBoolean(obj->IsJSGlobalProxy()); | 672 return isolate->heap()->ToBoolean(obj->IsJSGlobalProxy()); |
| 671 } | 673 } |
| 672 | 674 |
| 673 | 675 static bool IsValidAccessor(Isolate* isolate, Handle<Object> obj) { |
| 674 static bool IsValidAccessor(Handle<Object> obj) { | 676 return obj->IsUndefined(isolate) || obj->IsCallable() || obj->IsNull(); |
| 675 return obj->IsUndefined() || obj->IsCallable() || obj->IsNull(); | |
| 676 } | 677 } |
| 677 | 678 |
| 678 | 679 |
| 679 // Implements part of 8.12.9 DefineOwnProperty. | 680 // Implements part of 8.12.9 DefineOwnProperty. |
| 680 // There are 3 cases that lead here: | 681 // There are 3 cases that lead here: |
| 681 // Step 4b - define a new accessor property. | 682 // Step 4b - define a new accessor property. |
| 682 // Steps 9c & 12 - replace an existing data property with an accessor property. | 683 // Steps 9c & 12 - replace an existing data property with an accessor property. |
| 683 // Step 12 - update an existing accessor property with an accessor or generic | 684 // Step 12 - update an existing accessor property with an accessor or generic |
| 684 // descriptor. | 685 // descriptor. |
| 685 RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) { | 686 RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) { |
| 686 HandleScope scope(isolate); | 687 HandleScope scope(isolate); |
| 687 DCHECK(args.length() == 5); | 688 DCHECK(args.length() == 5); |
| 688 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 689 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
| 689 RUNTIME_ASSERT(!obj->IsNull()); | 690 RUNTIME_ASSERT(!obj->IsNull()); |
| 690 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 691 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 691 CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2); | 692 CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2); |
| 692 RUNTIME_ASSERT(IsValidAccessor(getter)); | 693 RUNTIME_ASSERT(IsValidAccessor(isolate, getter)); |
| 693 CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3); | 694 CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3); |
| 694 RUNTIME_ASSERT(IsValidAccessor(setter)); | 695 RUNTIME_ASSERT(IsValidAccessor(isolate, setter)); |
| 695 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 4); | 696 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 4); |
| 696 | 697 |
| 697 RETURN_FAILURE_ON_EXCEPTION( | 698 RETURN_FAILURE_ON_EXCEPTION( |
| 698 isolate, JSObject::DefineAccessor(obj, name, getter, setter, attrs)); | 699 isolate, JSObject::DefineAccessor(obj, name, getter, setter, attrs)); |
| 699 return isolate->heap()->undefined_value(); | 700 return isolate->heap()->undefined_value(); |
| 700 } | 701 } |
| 701 | 702 |
| 702 | 703 |
| 703 RUNTIME_FUNCTION(Runtime_DefineDataPropertyInLiteral) { | 704 RUNTIME_FUNCTION(Runtime_DefineDataPropertyInLiteral) { |
| 704 HandleScope scope(isolate); | 705 HandleScope scope(isolate); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 isolate, o, key, &success, LookupIterator::OWN); | 975 isolate, o, key, &success, LookupIterator::OWN); |
| 975 if (!success) return isolate->heap()->exception(); | 976 if (!success) return isolate->heap()->exception(); |
| 976 MAYBE_RETURN( | 977 MAYBE_RETURN( |
| 977 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 978 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
| 978 isolate->heap()->exception()); | 979 isolate->heap()->exception()); |
| 979 return *value; | 980 return *value; |
| 980 } | 981 } |
| 981 | 982 |
| 982 } // namespace internal | 983 } // namespace internal |
| 983 } // namespace v8 | 984 } // namespace v8 |
| OLD | NEW |