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 bool* is_found_out) { | 21 bool* is_found_out) { |
22 if (object->IsUndefined(isolate) || object->IsNull(isolate)) { | 22 if (object->IsNullOrUndefined(isolate)) { |
23 THROW_NEW_ERROR( | 23 THROW_NEW_ERROR( |
24 isolate, | 24 isolate, |
25 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), | 25 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), |
26 Object); | 26 Object); |
27 } | 27 } |
28 | 28 |
29 bool success = false; | 29 bool success = false; |
30 LookupIterator it = | 30 LookupIterator it = |
31 LookupIterator::PropertyOrElement(isolate, object, key, &success); | 31 LookupIterator::PropertyOrElement(isolate, object, key, &success); |
32 if (!success) return MaybeHandle<Object>(); | 32 if (!success) return MaybeHandle<Object>(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 Maybe<bool> result = | 192 Maybe<bool> result = |
193 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key); | 193 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key); |
194 if (!result.IsJust()) return isolate->heap()->exception(); | 194 if (!result.IsJust()) return isolate->heap()->exception(); |
195 return isolate->heap()->ToBoolean(result.FromJust()); | 195 return isolate->heap()->ToBoolean(result.FromJust()); |
196 | 196 |
197 } else if (object->IsString()) { | 197 } else if (object->IsString()) { |
198 return isolate->heap()->ToBoolean( | 198 return isolate->heap()->ToBoolean( |
199 key_is_array_index | 199 key_is_array_index |
200 ? index < static_cast<uint32_t>(String::cast(*object)->length()) | 200 ? index < static_cast<uint32_t>(String::cast(*object)->length()) |
201 : key->Equals(isolate->heap()->length_string())); | 201 : key->Equals(isolate->heap()->length_string())); |
202 } else if (object->IsNull(isolate) || object->IsUndefined(isolate)) { | 202 } else if (object->IsNullOrUndefined(isolate)) { |
203 THROW_NEW_ERROR_RETURN_FAILURE( | 203 THROW_NEW_ERROR_RETURN_FAILURE( |
204 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); | 204 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); |
205 } | 205 } |
206 | 206 |
207 return isolate->heap()->false_value(); | 207 return isolate->heap()->false_value(); |
208 } | 208 } |
209 | 209 |
210 // ES6 section 19.1.2.2 Object.create ( O [ , Properties ] ) | 210 // ES6 section 19.1.2.2 Object.create ( O [ , Properties ] ) |
211 // TODO(verwaest): Support the common cases with precached map directly in | 211 // TODO(verwaest): Support the common cases with precached map directly in |
212 // an Object.create stub. | 212 // an Object.create stub. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 269 } |
270 | 270 |
271 return *object; | 271 return *object; |
272 } | 272 } |
273 | 273 |
274 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, | 274 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, |
275 Handle<Object> object, | 275 Handle<Object> object, |
276 Handle<Object> key, | 276 Handle<Object> key, |
277 Handle<Object> value, | 277 Handle<Object> value, |
278 LanguageMode language_mode) { | 278 LanguageMode language_mode) { |
279 if (object->IsUndefined(isolate) || object->IsNull(isolate)) { | 279 if (object->IsNullOrUndefined(isolate)) { |
280 THROW_NEW_ERROR( | 280 THROW_NEW_ERROR( |
281 isolate, | 281 isolate, |
282 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), | 282 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), |
283 Object); | 283 Object); |
284 } | 284 } |
285 | 285 |
286 // Check if the given key is an array index. | 286 // Check if the given key is an array index. |
287 bool success = false; | 287 bool success = false; |
288 LookupIterator it = | 288 LookupIterator it = |
289 LookupIterator::PropertyOrElement(isolate, object, key, &success); | 289 LookupIterator::PropertyOrElement(isolate, object, key, &success); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 | 611 |
612 | 612 |
613 RUNTIME_FUNCTION(Runtime_IsJSGlobalProxy) { | 613 RUNTIME_FUNCTION(Runtime_IsJSGlobalProxy) { |
614 SealHandleScope shs(isolate); | 614 SealHandleScope shs(isolate); |
615 DCHECK_EQ(1, args.length()); | 615 DCHECK_EQ(1, args.length()); |
616 CONVERT_ARG_CHECKED(Object, obj, 0); | 616 CONVERT_ARG_CHECKED(Object, obj, 0); |
617 return isolate->heap()->ToBoolean(obj->IsJSGlobalProxy()); | 617 return isolate->heap()->ToBoolean(obj->IsJSGlobalProxy()); |
618 } | 618 } |
619 | 619 |
620 static bool IsValidAccessor(Isolate* isolate, Handle<Object> obj) { | 620 static bool IsValidAccessor(Isolate* isolate, Handle<Object> obj) { |
621 return obj->IsUndefined(isolate) || obj->IsCallable() || obj->IsNull(isolate); | 621 return obj->IsNullOrUndefined(isolate) || obj->IsCallable(); |
622 } | 622 } |
623 | 623 |
624 | 624 |
625 // Implements part of 8.12.9 DefineOwnProperty. | 625 // Implements part of 8.12.9 DefineOwnProperty. |
626 // There are 3 cases that lead here: | 626 // There are 3 cases that lead here: |
627 // Step 4b - define a new accessor property. | 627 // Step 4b - define a new accessor property. |
628 // Steps 9c & 12 - replace an existing data property with an accessor property. | 628 // Steps 9c & 12 - replace an existing data property with an accessor property. |
629 // Step 12 - update an existing accessor property with an accessor or generic | 629 // Step 12 - update an existing accessor property with an accessor or generic |
630 // descriptor. | 630 // descriptor. |
631 RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) { | 631 RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); | 700 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); |
701 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 701 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
702 return *JSReceiver::GetDataProperty(object, name); | 702 return *JSReceiver::GetDataProperty(object, name); |
703 } | 703 } |
704 | 704 |
705 RUNTIME_FUNCTION(Runtime_GetConstructorName) { | 705 RUNTIME_FUNCTION(Runtime_GetConstructorName) { |
706 HandleScope scope(isolate); | 706 HandleScope scope(isolate); |
707 DCHECK_EQ(1, args.length()); | 707 DCHECK_EQ(1, args.length()); |
708 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 708 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
709 | 709 |
710 CHECK(!object->IsUndefined(isolate) && !object->IsNull(isolate)); | 710 CHECK(!object->IsNullOrUndefined(isolate)); |
711 Handle<JSReceiver> recv = Object::ToObject(isolate, object).ToHandleChecked(); | 711 Handle<JSReceiver> recv = Object::ToObject(isolate, object).ToHandleChecked(); |
712 return *JSReceiver::GetConstructorName(recv); | 712 return *JSReceiver::GetConstructorName(recv); |
713 } | 713 } |
714 | 714 |
715 RUNTIME_FUNCTION(Runtime_HasFastPackedElements) { | 715 RUNTIME_FUNCTION(Runtime_HasFastPackedElements) { |
716 SealHandleScope shs(isolate); | 716 SealHandleScope shs(isolate); |
717 DCHECK_EQ(1, args.length()); | 717 DCHECK_EQ(1, args.length()); |
718 CONVERT_ARG_CHECKED(HeapObject, obj, 0); | 718 CONVERT_ARG_CHECKED(HeapObject, obj, 0); |
719 return isolate->heap()->ToBoolean( | 719 return isolate->heap()->ToBoolean( |
720 IsFastPackedElementsKind(obj->map()->elements_kind())); | 720 IsFastPackedElementsKind(obj->map()->elements_kind())); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 if (!success) return isolate->heap()->exception(); | 963 if (!success) return isolate->heap()->exception(); |
964 MAYBE_RETURN( | 964 MAYBE_RETURN( |
965 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 965 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
966 isolate->heap()->exception()); | 966 isolate->heap()->exception()); |
967 return *value; | 967 return *value; |
968 } | 968 } |
969 | 969 |
970 | 970 |
971 } // namespace internal | 971 } // namespace internal |
972 } // namespace v8 | 972 } // namespace v8 |
OLD | NEW |