| 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(isolate) || object->IsNull(isolate)) { | 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 Maybe<bool> result = | 189 Maybe<bool> result = |
| 190 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key); | 190 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key); |
| 191 if (!result.IsJust()) return isolate->heap()->exception(); | 191 if (!result.IsJust()) return isolate->heap()->exception(); |
| 192 return isolate->heap()->ToBoolean(result.FromJust()); | 192 return isolate->heap()->ToBoolean(result.FromJust()); |
| 193 | 193 |
| 194 } else if (object->IsString()) { | 194 } else if (object->IsString()) { |
| 195 return isolate->heap()->ToBoolean( | 195 return isolate->heap()->ToBoolean( |
| 196 key_is_array_index | 196 key_is_array_index |
| 197 ? index < static_cast<uint32_t>(String::cast(*object)->length()) | 197 ? index < static_cast<uint32_t>(String::cast(*object)->length()) |
| 198 : key->Equals(isolate->heap()->length_string())); | 198 : key->Equals(isolate->heap()->length_string())); |
| 199 } else if (object->IsNull(isolate) || object->IsUndefined(isolate)) { | 199 } else if (object->IsNull() || object->IsUndefined(isolate)) { |
| 200 THROW_NEW_ERROR_RETURN_FAILURE( | 200 THROW_NEW_ERROR_RETURN_FAILURE( |
| 201 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); | 201 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 return isolate->heap()->false_value(); | 204 return isolate->heap()->false_value(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, | 207 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, |
| 208 Handle<Object> object, | 208 Handle<Object> object, |
| 209 Handle<Object> key, | 209 Handle<Object> key, |
| 210 Handle<Object> value, | 210 Handle<Object> value, |
| 211 LanguageMode language_mode) { | 211 LanguageMode language_mode) { |
| 212 if (object->IsUndefined(isolate) || object->IsNull(isolate)) { | 212 if (object->IsUndefined(isolate) || object->IsNull()) { |
| 213 THROW_NEW_ERROR( | 213 THROW_NEW_ERROR( |
| 214 isolate, | 214 isolate, |
| 215 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), | 215 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), |
| 216 Object); | 216 Object); |
| 217 } | 217 } |
| 218 | 218 |
| 219 // Check if the given key is an array index. | 219 // Check if the given key is an array index. |
| 220 bool success = false; | 220 bool success = false; |
| 221 LookupIterator it = | 221 LookupIterator it = |
| 222 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... |
| 665 | 665 |
| 666 | 666 |
| 667 RUNTIME_FUNCTION(Runtime_IsJSGlobalProxy) { | 667 RUNTIME_FUNCTION(Runtime_IsJSGlobalProxy) { |
| 668 SealHandleScope shs(isolate); | 668 SealHandleScope shs(isolate); |
| 669 DCHECK(args.length() == 1); | 669 DCHECK(args.length() == 1); |
| 670 CONVERT_ARG_CHECKED(Object, obj, 0); | 670 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 671 return isolate->heap()->ToBoolean(obj->IsJSGlobalProxy()); | 671 return isolate->heap()->ToBoolean(obj->IsJSGlobalProxy()); |
| 672 } | 672 } |
| 673 | 673 |
| 674 static bool IsValidAccessor(Isolate* isolate, Handle<Object> obj) { | 674 static bool IsValidAccessor(Isolate* isolate, Handle<Object> obj) { |
| 675 return obj->IsUndefined(isolate) || obj->IsCallable() || obj->IsNull(isolate); | 675 return obj->IsUndefined(isolate) || obj->IsCallable() || obj->IsNull(); |
| 676 } | 676 } |
| 677 | 677 |
| 678 | 678 |
| 679 // Implements part of 8.12.9 DefineOwnProperty. | 679 // Implements part of 8.12.9 DefineOwnProperty. |
| 680 // There are 3 cases that lead here: | 680 // There are 3 cases that lead here: |
| 681 // Step 4b - define a new accessor property. | 681 // Step 4b - define a new accessor property. |
| 682 // Steps 9c & 12 - replace an existing data property with an accessor property. | 682 // 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 | 683 // Step 12 - update an existing accessor property with an accessor or generic |
| 684 // descriptor. | 684 // descriptor. |
| 685 RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) { | 685 RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) { |
| 686 HandleScope scope(isolate); | 686 HandleScope scope(isolate); |
| 687 DCHECK(args.length() == 5); | 687 DCHECK(args.length() == 5); |
| 688 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 688 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
| 689 CHECK(!obj->IsNull(isolate)); | 689 CHECK(!obj->IsNull()); |
| 690 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 690 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 691 CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2); | 691 CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2); |
| 692 CHECK(IsValidAccessor(isolate, getter)); | 692 CHECK(IsValidAccessor(isolate, getter)); |
| 693 CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3); | 693 CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3); |
| 694 CHECK(IsValidAccessor(isolate, setter)); | 694 CHECK(IsValidAccessor(isolate, setter)); |
| 695 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 4); | 695 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 4); |
| 696 | 696 |
| 697 RETURN_FAILURE_ON_EXCEPTION( | 697 RETURN_FAILURE_ON_EXCEPTION( |
| 698 isolate, JSObject::DefineAccessor(obj, name, getter, setter, attrs)); | 698 isolate, JSObject::DefineAccessor(obj, name, getter, setter, attrs)); |
| 699 return isolate->heap()->undefined_value(); | 699 return isolate->heap()->undefined_value(); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 isolate, o, key, &success, LookupIterator::OWN); | 974 isolate, o, key, &success, LookupIterator::OWN); |
| 975 if (!success) return isolate->heap()->exception(); | 975 if (!success) return isolate->heap()->exception(); |
| 976 MAYBE_RETURN( | 976 MAYBE_RETURN( |
| 977 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 977 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
| 978 isolate->heap()->exception()); | 978 isolate->heap()->exception()); |
| 979 return *value; | 979 return *value; |
| 980 } | 980 } |
| 981 | 981 |
| 982 } // namespace internal | 982 } // namespace internal |
| 983 } // namespace v8 | 983 } // namespace v8 |
| OLD | NEW |