| 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/messages.h" | 10 #include "src/messages.h" |
| 11 #include "src/runtime/runtime.h" | 11 #include "src/runtime/runtime.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 | 16 |
| 17 MaybeHandle<Name> Runtime::ToName(Isolate* isolate, Handle<Object> key) { | |
| 18 if (key->IsName()) { | |
| 19 return Handle<Name>::cast(key); | |
| 20 } else { | |
| 21 Handle<Object> converted; | |
| 22 ASSIGN_RETURN_ON_EXCEPTION(isolate, converted, | |
| 23 Execution::ToString(isolate, key), Name); | |
| 24 return Handle<Name>::cast(converted); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 | |
| 29 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, | 17 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate, |
| 30 Handle<Object> object, | 18 Handle<Object> object, |
| 31 Handle<Object> key, | 19 Handle<Object> key, |
| 32 LanguageMode language_mode) { | 20 LanguageMode language_mode) { |
| 33 if (object->IsUndefined() || object->IsNull()) { | 21 if (object->IsUndefined() || object->IsNull()) { |
| 34 THROW_NEW_ERROR( | 22 THROW_NEW_ERROR( |
| 35 isolate, | 23 isolate, |
| 36 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), | 24 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), |
| 37 Object); | 25 Object); |
| 38 } | 26 } |
| 39 | 27 |
| 40 // Check if the given key is an array index. | 28 // Check if the given key is an array index. |
| 41 uint32_t index = 0; | 29 uint32_t index = 0; |
| 42 if (key->ToArrayIndex(&index)) { | 30 if (key->ToArrayIndex(&index)) { |
| 43 return Object::GetElement(isolate, object, index, language_mode); | 31 return Object::GetElement(isolate, object, index, language_mode); |
| 44 } | 32 } |
| 45 | 33 |
| 46 // Convert the key to a name - possibly by calling back into JavaScript. | 34 // Convert the key to a name - possibly by calling back into JavaScript. |
| 47 Handle<Name> name; | 35 Handle<Name> name; |
| 48 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object); | 36 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key), |
| 37 Object); |
| 49 | 38 |
| 50 // Check if the name is trivially convertible to an index and get | 39 // Check if the name is trivially convertible to an index and get |
| 51 // the element if so. | 40 // the element if so. |
| 52 // TODO(verwaest): Make sure GetProperty(LookupIterator*) can handle this, and | 41 // TODO(verwaest): Make sure GetProperty(LookupIterator*) can handle this, and |
| 53 // remove the special casing here. | 42 // remove the special casing here. |
| 54 if (name->AsArrayIndex(&index)) { | 43 if (name->AsArrayIndex(&index)) { |
| 55 return Object::GetElement(isolate, object, index); | 44 return Object::GetElement(isolate, object, index); |
| 56 } else { | 45 } else { |
| 57 return Object::GetProperty(object, name, language_mode); | 46 return Object::GetProperty(object, name, language_mode); |
| 58 } | 47 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 Handle<JSReceiver> receiver, | 132 Handle<JSReceiver> receiver, |
| 144 Handle<Object> key, | 133 Handle<Object> key, |
| 145 LanguageMode language_mode) { | 134 LanguageMode language_mode) { |
| 146 // Check if the given key is an array index. | 135 // Check if the given key is an array index. |
| 147 uint32_t index = 0; | 136 uint32_t index = 0; |
| 148 if (key->ToArrayIndex(&index)) { | 137 if (key->ToArrayIndex(&index)) { |
| 149 return JSReceiver::DeleteElement(receiver, index, language_mode); | 138 return JSReceiver::DeleteElement(receiver, index, language_mode); |
| 150 } | 139 } |
| 151 | 140 |
| 152 Handle<Name> name; | 141 Handle<Name> name; |
| 153 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object); | 142 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key), |
| 143 Object); |
| 154 | 144 |
| 155 return JSReceiver::DeletePropertyOrElement(receiver, name, language_mode); | 145 return JSReceiver::DeletePropertyOrElement(receiver, name, language_mode); |
| 156 } | 146 } |
| 157 | 147 |
| 158 | 148 |
| 159 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, | 149 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, |
| 160 Handle<Object> object, | 150 Handle<Object> object, |
| 161 Handle<Object> key, | 151 Handle<Object> key, |
| 162 Handle<Object> value, | 152 Handle<Object> value, |
| 163 LanguageMode language_mode) { | 153 LanguageMode language_mode) { |
| 164 if (object->IsUndefined() || object->IsNull()) { | 154 if (object->IsUndefined() || object->IsNull()) { |
| 165 THROW_NEW_ERROR( | 155 THROW_NEW_ERROR( |
| 166 isolate, | 156 isolate, |
| 167 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), | 157 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), |
| 168 Object); | 158 Object); |
| 169 } | 159 } |
| 170 | 160 |
| 171 // Check if the given key is an array index. | 161 // Check if the given key is an array index. |
| 172 uint32_t index = 0; | 162 uint32_t index = 0; |
| 173 if (key->ToArrayIndex(&index)) { | 163 if (key->ToArrayIndex(&index)) { |
| 174 return Object::SetElement(isolate, object, index, value, language_mode); | 164 return Object::SetElement(isolate, object, index, value, language_mode); |
| 175 } | 165 } |
| 176 | 166 |
| 177 Handle<Name> name; | 167 Handle<Name> name; |
| 178 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object); | 168 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key), |
| 169 Object); |
| 179 | 170 |
| 180 LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name); | 171 LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name); |
| 181 return Object::SetProperty(&it, value, language_mode, | 172 return Object::SetProperty(&it, value, language_mode, |
| 182 Object::MAY_BE_STORE_FROM_KEYED); | 173 Object::MAY_BE_STORE_FROM_KEYED); |
| 183 } | 174 } |
| 184 | 175 |
| 185 | 176 |
| 186 MaybeHandle<Object> Runtime::GetPrototype(Isolate* isolate, | 177 MaybeHandle<Object> Runtime::GetPrototype(Isolate* isolate, |
| 187 Handle<Object> obj) { | 178 Handle<Object> obj) { |
| 188 // We don't expect access checks to be needed on JSProxy objects. | 179 // We don't expect access checks to be needed on JSProxy objects. |
| (...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1492 SealHandleScope scope(isolate); | 1483 SealHandleScope scope(isolate); |
| 1493 DCHECK_EQ(2, args.length()); | 1484 DCHECK_EQ(2, args.length()); |
| 1494 CONVERT_ARG_CHECKED(Object, object, 0); | 1485 CONVERT_ARG_CHECKED(Object, object, 0); |
| 1495 CONVERT_ARG_CHECKED(Object, prototype, 1); | 1486 CONVERT_ARG_CHECKED(Object, prototype, 1); |
| 1496 return isolate->heap()->ToBoolean( | 1487 return isolate->heap()->ToBoolean( |
| 1497 object->HasInPrototypeChain(isolate, prototype)); | 1488 object->HasInPrototypeChain(isolate, prototype)); |
| 1498 } | 1489 } |
| 1499 | 1490 |
| 1500 } // namespace internal | 1491 } // namespace internal |
| 1501 } // namespace v8 | 1492 } // namespace v8 |
| OLD | NEW |