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 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1845 // ES6 section 19.1.2.14 Object.keys ( O ) | 1845 // ES6 section 19.1.2.14 Object.keys ( O ) |
1846 BUILTIN(ObjectKeys) { | 1846 BUILTIN(ObjectKeys) { |
1847 HandleScope scope(isolate); | 1847 HandleScope scope(isolate); |
1848 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1848 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1849 Handle<JSReceiver> receiver; | 1849 Handle<JSReceiver> receiver; |
1850 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1850 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
1851 Object::ToObject(isolate, object)); | 1851 Object::ToObject(isolate, object)); |
1852 | 1852 |
1853 Handle<FixedArray> keys; | 1853 Handle<FixedArray> keys; |
1854 int enum_length = receiver->map()->EnumLength(); | 1854 int enum_length = receiver->map()->EnumLength(); |
1855 if (enum_length != kInvalidEnumCacheSentinel) { | 1855 if (enum_length != kInvalidEnumCacheSentinel && |
1856 JSObject::cast(*receiver)->elements() == | |
1857 isolate->heap()->empty_fixed_array()) { | |
Camillo Bruni
2016/02/12 13:04:21
Maybe add a HasNoElements helper at some point?
| |
1856 DCHECK(receiver->IsJSObject()); | 1858 DCHECK(receiver->IsJSObject()); |
1857 Handle<JSObject> js_object = Handle<JSObject>::cast(receiver); | 1859 DCHECK(!JSObject::cast(*receiver)->HasNamedInterceptor()); |
1858 DCHECK(!js_object->HasNamedInterceptor()); | 1860 DCHECK(!JSObject::cast(*receiver)->IsAccessCheckNeeded()); |
1859 DCHECK(!js_object->IsAccessCheckNeeded()); | 1861 DCHECK(!receiver->map()->has_hidden_prototype()); |
1860 DCHECK(!js_object->map()->has_hidden_prototype()); | 1862 DCHECK(JSObject::cast(*receiver)->HasFastProperties()); |
1861 DCHECK(js_object->HasFastProperties()); | 1863 if (enum_length == 0) { |
1862 if (js_object->elements() == isolate->heap()->empty_fixed_array()) { | 1864 keys = isolate->factory()->empty_fixed_array(); |
1863 keys = isolate->factory()->NewFixedArray(enum_length); | 1865 } else { |
1864 if (enum_length != 0) { | 1866 Handle<FixedArray> cache( |
1865 Handle<FixedArray> cache( | 1867 receiver->map()->instance_descriptors()->GetEnumCache()); |
1866 js_object->map()->instance_descriptors()->GetEnumCache()); | 1868 keys = isolate->factory()->CopyFixedArrayUpTo(cache, enum_length); |
Camillo Bruni
2016/02/12 13:04:21
This pattern probably as well... GetEnumCacheCopy
| |
1867 keys = isolate->factory()->CopyFixedArrayUpTo(cache, enum_length); | |
1868 } | |
1869 } | 1869 } |
1870 } | 1870 } else { |
1871 | |
1872 if (keys.is_null()) { | |
1873 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1871 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1874 isolate, keys, | 1872 isolate, keys, |
1875 JSReceiver::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS, | 1873 JSReceiver::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS, |
1876 CONVERT_TO_STRING)); | 1874 CONVERT_TO_STRING)); |
1877 } | 1875 } |
1878 return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS); | 1876 return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS); |
1879 } | 1877 } |
1880 | 1878 |
1881 BUILTIN(ObjectValues) { | 1879 BUILTIN(ObjectValues) { |
1882 HandleScope scope(isolate); | 1880 HandleScope scope(isolate); |
(...skipping 2496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4379 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4377 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4380 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4378 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4381 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4379 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4382 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4380 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4383 #undef DEFINE_BUILTIN_ACCESSOR_C | 4381 #undef DEFINE_BUILTIN_ACCESSOR_C |
4384 #undef DEFINE_BUILTIN_ACCESSOR_A | 4382 #undef DEFINE_BUILTIN_ACCESSOR_A |
4385 | 4383 |
4386 | 4384 |
4387 } // namespace internal | 4385 } // namespace internal |
4388 } // namespace v8 | 4386 } // namespace v8 |
OLD | NEW |