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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 isolate, o, key, &success, LookupIterator::OWN); | 976 isolate, o, key, &success, LookupIterator::OWN); |
975 if (!success) return isolate->heap()->exception(); | 977 if (!success) return isolate->heap()->exception(); |
976 MAYBE_RETURN( | 978 MAYBE_RETURN( |
977 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 979 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
978 isolate->heap()->exception()); | 980 isolate->heap()->exception()); |
979 return *value; | 981 return *value; |
980 } | 982 } |
981 | 983 |
982 } // namespace internal | 984 } // namespace internal |
983 } // namespace v8 | 985 } // namespace v8 |
OLD | NEW |