| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/builtins.h" | 5 #include "src/builtins.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 346 |
| 347 if (object->IsJSObject()) { | 347 if (object->IsJSObject()) { |
| 348 Handle<JSObject> js_obj = Handle<JSObject>::cast(object); | 348 Handle<JSObject> js_obj = Handle<JSObject>::cast(object); |
| 349 // Fast case: either the key is a real named property or it is not | 349 // Fast case: either the key is a real named property or it is not |
| 350 // an array index and there are no interceptors or hidden | 350 // an array index and there are no interceptors or hidden |
| 351 // prototypes. | 351 // prototypes. |
| 352 // TODO(jkummerow): Make JSReceiver::HasOwnProperty fast enough to | 352 // TODO(jkummerow): Make JSReceiver::HasOwnProperty fast enough to |
| 353 // handle all cases directly (without this custom fast path). | 353 // handle all cases directly (without this custom fast path). |
| 354 { | 354 { |
| 355 LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR; | 355 LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR; |
| 356 LookupIterator it = key_is_array_index | 356 LookupIterator it = |
| 357 ? LookupIterator(isolate, js_obj, index, c) | 357 key_is_array_index ? LookupIterator(isolate, js_obj, index, js_obj, c) |
| 358 : LookupIterator(js_obj, key, c); | 358 : LookupIterator(js_obj, key, js_obj, c); |
| 359 Maybe<bool> maybe = JSReceiver::HasProperty(&it); | 359 Maybe<bool> maybe = JSReceiver::HasProperty(&it); |
| 360 if (maybe.IsNothing()) return isolate->heap()->exception(); | 360 if (maybe.IsNothing()) return isolate->heap()->exception(); |
| 361 DCHECK(!isolate->has_pending_exception()); | 361 DCHECK(!isolate->has_pending_exception()); |
| 362 if (maybe.FromJust()) return isolate->heap()->true_value(); | 362 if (maybe.FromJust()) return isolate->heap()->true_value(); |
| 363 } | 363 } |
| 364 | 364 |
| 365 Map* map = js_obj->map(); | 365 Map* map = js_obj->map(); |
| 366 if (!map->has_hidden_prototype() && | 366 if (!map->has_hidden_prototype() && |
| 367 (key_is_array_index ? !map->has_indexed_interceptor() | 367 (key_is_array_index ? !map->has_indexed_interceptor() |
| 368 : !map->has_named_interceptor())) { | 368 : !map->has_named_interceptor())) { |
| 369 return isolate->heap()->false_value(); | 369 return isolate->heap()->false_value(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 // Slow case. | 372 // Slow case. |
| 373 LookupIterator::Configuration c = LookupIterator::HIDDEN; | 373 LookupIterator::Configuration c = LookupIterator::HIDDEN; |
| 374 LookupIterator it = key_is_array_index | 374 LookupIterator it = key_is_array_index |
| 375 ? LookupIterator(isolate, js_obj, index, c) | 375 ? LookupIterator(isolate, js_obj, index, js_obj, c) |
| 376 : LookupIterator(js_obj, key, c); | 376 : LookupIterator(js_obj, key, js_obj, c); |
| 377 | 377 |
| 378 Maybe<bool> maybe = JSReceiver::HasProperty(&it); | 378 Maybe<bool> maybe = JSReceiver::HasProperty(&it); |
| 379 if (maybe.IsNothing()) return isolate->heap()->exception(); | 379 if (maybe.IsNothing()) return isolate->heap()->exception(); |
| 380 DCHECK(!isolate->has_pending_exception()); | 380 DCHECK(!isolate->has_pending_exception()); |
| 381 return isolate->heap()->ToBoolean(maybe.FromJust()); | 381 return isolate->heap()->ToBoolean(maybe.FromJust()); |
| 382 | 382 |
| 383 } else if (object->IsJSProxy()) { | 383 } else if (object->IsJSProxy()) { |
| 384 if (key.is_null()) { | 384 if (key.is_null()) { |
| 385 DCHECK(key_is_array_index); | 385 DCHECK(key_is_array_index); |
| 386 key = isolate->factory()->Uint32ToString(index); | 386 key = isolate->factory()->Uint32ToString(index); |
| (...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 } | 1535 } |
| 1536 } else { | 1536 } else { |
| 1537 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, prop_value, | 1537 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, prop_value, |
| 1538 Object::GetProperty(from, next_key), | 1538 Object::GetProperty(from, next_key), |
| 1539 Nothing<bool>()); | 1539 Nothing<bool>()); |
| 1540 stable = from->map() == *map; | 1540 stable = from->map() == *map; |
| 1541 } | 1541 } |
| 1542 } else { | 1542 } else { |
| 1543 // If the map did change, do a slower lookup. We are still guaranteed that | 1543 // If the map did change, do a slower lookup. We are still guaranteed that |
| 1544 // the object has a simple shape, and that the key is a name. | 1544 // the object has a simple shape, and that the key is a name. |
| 1545 LookupIterator it(from, next_key, LookupIterator::OWN_SKIP_INTERCEPTOR); | 1545 LookupIterator it(from, next_key, from, |
| 1546 LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 1546 if (!it.IsFound()) continue; | 1547 if (!it.IsFound()) continue; |
| 1547 DCHECK(it.state() == LookupIterator::DATA || | 1548 DCHECK(it.state() == LookupIterator::DATA || |
| 1548 it.state() == LookupIterator::ACCESSOR); | 1549 it.state() == LookupIterator::ACCESSOR); |
| 1549 if (!it.IsEnumerable()) continue; | 1550 if (!it.IsEnumerable()) continue; |
| 1550 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 1551 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 1551 isolate, prop_value, Object::GetProperty(&it), Nothing<bool>()); | 1552 isolate, prop_value, Object::GetProperty(&it), Nothing<bool>()); |
| 1552 } | 1553 } |
| 1553 LookupIterator it(to, next_key); | 1554 LookupIterator it(to, next_key, to); |
| 1554 bool call_to_js = it.IsFound() && it.state() != LookupIterator::DATA; | 1555 bool call_to_js = it.IsFound() && it.state() != LookupIterator::DATA; |
| 1555 Maybe<bool> result = Object::SetProperty( | 1556 Maybe<bool> result = Object::SetProperty( |
| 1556 &it, prop_value, STRICT, Object::CERTAINLY_NOT_STORE_FROM_KEYED); | 1557 &it, prop_value, STRICT, Object::CERTAINLY_NOT_STORE_FROM_KEYED); |
| 1557 if (result.IsNothing()) return result; | 1558 if (result.IsNothing()) return result; |
| 1558 if (stable && call_to_js) stable = from->map() == *map; | 1559 if (stable && call_to_js) stable = from->map() == *map; |
| 1559 } | 1560 } |
| 1560 | 1561 |
| 1561 return Just(true); | 1562 return Just(true); |
| 1562 } | 1563 } |
| 1563 | 1564 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 | 1840 |
| 1840 Handle<JSReceiver> receiver; | 1841 Handle<JSReceiver> receiver; |
| 1841 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1842 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 1842 Object::ToObject(isolate, object)); | 1843 Object::ToObject(isolate, object)); |
| 1843 | 1844 |
| 1844 Handle<FixedArray> keys; | 1845 Handle<FixedArray> keys; |
| 1845 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1846 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1846 isolate, keys, JSReceiver::GetKeys(receiver, OWN_ONLY, ALL_PROPERTIES, | 1847 isolate, keys, JSReceiver::GetKeys(receiver, OWN_ONLY, ALL_PROPERTIES, |
| 1847 CONVERT_TO_STRING)); | 1848 CONVERT_TO_STRING)); |
| 1848 | 1849 |
| 1849 Handle<Object> descriptors = | 1850 Handle<JSObject> descriptors = |
| 1850 isolate->factory()->NewJSObject(isolate->object_function()); | 1851 isolate->factory()->NewJSObject(isolate->object_function()); |
| 1851 | 1852 |
| 1852 for (int i = 0; i < keys->length(); ++i) { | 1853 for (int i = 0; i < keys->length(); ++i) { |
| 1853 Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate)); | 1854 Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate)); |
| 1854 PropertyDescriptor descriptor; | 1855 PropertyDescriptor descriptor; |
| 1855 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( | 1856 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( |
| 1856 isolate, receiver, key, &descriptor); | 1857 isolate, receiver, key, &descriptor); |
| 1857 MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception()); | 1858 MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception()); |
| 1858 | 1859 |
| 1859 Handle<Object> from_descriptor = did_get_descriptor.FromJust() | 1860 Handle<Object> from_descriptor = did_get_descriptor.FromJust() |
| 1860 ? descriptor.ToObject(isolate) | 1861 ? descriptor.ToObject(isolate) |
| 1861 : undefined; | 1862 : undefined; |
| 1862 | 1863 |
| 1863 LookupIterator it = LookupIterator::PropertyOrElement( | 1864 LookupIterator it = LookupIterator::PropertyOrElement( |
| 1864 isolate, descriptors, key, LookupIterator::OWN); | 1865 isolate, descriptors, key, descriptors, LookupIterator::OWN); |
| 1865 Maybe<bool> success = JSReceiver::CreateDataProperty(&it, from_descriptor, | 1866 Maybe<bool> success = JSReceiver::CreateDataProperty(&it, from_descriptor, |
| 1866 Object::DONT_THROW); | 1867 Object::DONT_THROW); |
| 1867 CHECK(success.FromJust()); | 1868 CHECK(success.FromJust()); |
| 1868 } | 1869 } |
| 1869 | 1870 |
| 1870 return *descriptors; | 1871 return *descriptors; |
| 1871 } | 1872 } |
| 1872 | 1873 |
| 1873 // ES6 section 19.1.2.15 Object.preventExtensions ( O ) | 1874 // ES6 section 19.1.2.15 Object.preventExtensions ( O ) |
| 1874 BUILTIN(ObjectPreventExtensions) { | 1875 BUILTIN(ObjectPreventExtensions) { |
| (...skipping 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4532 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4533 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 4533 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4534 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4534 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4535 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 4535 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4536 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4536 #undef DEFINE_BUILTIN_ACCESSOR_C | 4537 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 4537 #undef DEFINE_BUILTIN_ACCESSOR_A | 4538 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 4538 | 4539 |
| 4539 | 4540 |
| 4540 } // namespace internal | 4541 } // namespace internal |
| 4541 } // namespace v8 | 4542 } // namespace v8 |
| OLD | NEW |