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-arguments.h" | 7 #include "src/api-arguments.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 if (fast_assign.FromJust()) continue; | 1621 if (fast_assign.FromJust()) continue; |
1622 // 4a. If nextSource is undefined or null, let keys be an empty List. | 1622 // 4a. If nextSource is undefined or null, let keys be an empty List. |
1623 // 4b. Else, | 1623 // 4b. Else, |
1624 // 4b i. Let from be ToObject(nextSource). | 1624 // 4b i. Let from be ToObject(nextSource). |
1625 // Only non-empty strings and JSReceivers have enumerable properties. | 1625 // Only non-empty strings and JSReceivers have enumerable properties. |
1626 Handle<JSReceiver> from = | 1626 Handle<JSReceiver> from = |
1627 Object::ToObject(isolate, next_source).ToHandleChecked(); | 1627 Object::ToObject(isolate, next_source).ToHandleChecked(); |
1628 // 4b ii. Let keys be ? from.[[OwnPropertyKeys]](). | 1628 // 4b ii. Let keys be ? from.[[OwnPropertyKeys]](). |
1629 Handle<FixedArray> keys; | 1629 Handle<FixedArray> keys; |
1630 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1630 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1631 isolate, keys, | 1631 isolate, keys, KeyAccumulator::GetKeys( |
1632 KeyAccumulator::GetKeys(from, OWN_ONLY, ALL_PROPERTIES, KEEP_NUMBERS)); | 1632 from, KeyCollectionMode::kOwnOnly, ALL_PROPERTIES, |
| 1633 GetKeysConversion::kKeepNumbers)); |
1633 // 4c. Repeat for each element nextKey of keys in List order, | 1634 // 4c. Repeat for each element nextKey of keys in List order, |
1634 for (int j = 0; j < keys->length(); ++j) { | 1635 for (int j = 0; j < keys->length(); ++j) { |
1635 Handle<Object> next_key(keys->get(j), isolate); | 1636 Handle<Object> next_key(keys->get(j), isolate); |
1636 // 4c i. Let desc be ? from.[[GetOwnProperty]](nextKey). | 1637 // 4c i. Let desc be ? from.[[GetOwnProperty]](nextKey). |
1637 PropertyDescriptor desc; | 1638 PropertyDescriptor desc; |
1638 Maybe<bool> found = | 1639 Maybe<bool> found = |
1639 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc); | 1640 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc); |
1640 if (found.IsNothing()) return isolate->heap()->exception(); | 1641 if (found.IsNothing()) return isolate->heap()->exception(); |
1641 // 4c ii. If desc is not undefined and desc.[[Enumerable]] is true, then | 1642 // 4c ii. If desc is not undefined and desc.[[Enumerable]] is true, then |
1642 if (found.FromJust() && desc.enumerable()) { | 1643 if (found.FromJust() && desc.enumerable()) { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1895 BuiltinArguments<BuiltinExtraArguments::kNone> args, | 1896 BuiltinArguments<BuiltinExtraArguments::kNone> args, |
1896 PropertyFilter filter) { | 1897 PropertyFilter filter) { |
1897 HandleScope scope(isolate); | 1898 HandleScope scope(isolate); |
1898 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1899 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1899 Handle<JSReceiver> receiver; | 1900 Handle<JSReceiver> receiver; |
1900 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1901 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
1901 Object::ToObject(isolate, object)); | 1902 Object::ToObject(isolate, object)); |
1902 Handle<FixedArray> keys; | 1903 Handle<FixedArray> keys; |
1903 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1904 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1904 isolate, keys, | 1905 isolate, keys, |
1905 KeyAccumulator::GetKeys(receiver, OWN_ONLY, filter, CONVERT_TO_STRING)); | 1906 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, filter, |
| 1907 GetKeysConversion::kConvertToString)); |
1906 return *isolate->factory()->NewJSArrayWithElements(keys); | 1908 return *isolate->factory()->NewJSArrayWithElements(keys); |
1907 } | 1909 } |
1908 | 1910 |
1909 } // namespace | 1911 } // namespace |
1910 | 1912 |
1911 | 1913 |
1912 // ES6 section 19.1.2.7 Object.getOwnPropertyNames ( O ) | 1914 // ES6 section 19.1.2.7 Object.getOwnPropertyNames ( O ) |
1913 BUILTIN(ObjectGetOwnPropertyNames) { | 1915 BUILTIN(ObjectGetOwnPropertyNames) { |
1914 return GetOwnPropertyKeys(isolate, args, SKIP_SYMBOLS); | 1916 return GetOwnPropertyKeys(isolate, args, SKIP_SYMBOLS); |
1915 } | 1917 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 if (enum_length == 0) { | 1993 if (enum_length == 0) { |
1992 keys = isolate->factory()->empty_fixed_array(); | 1994 keys = isolate->factory()->empty_fixed_array(); |
1993 } else { | 1995 } else { |
1994 Handle<FixedArray> cache( | 1996 Handle<FixedArray> cache( |
1995 receiver->map()->instance_descriptors()->GetEnumCache()); | 1997 receiver->map()->instance_descriptors()->GetEnumCache()); |
1996 keys = isolate->factory()->CopyFixedArrayUpTo(cache, enum_length); | 1998 keys = isolate->factory()->CopyFixedArrayUpTo(cache, enum_length); |
1997 } | 1999 } |
1998 } else { | 2000 } else { |
1999 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2001 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2000 isolate, keys, | 2002 isolate, keys, |
2001 KeyAccumulator::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS, | 2003 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, |
2002 CONVERT_TO_STRING)); | 2004 ENUMERABLE_STRINGS, |
| 2005 GetKeysConversion::kConvertToString)); |
2003 } | 2006 } |
2004 return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS); | 2007 return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS); |
2005 } | 2008 } |
2006 | 2009 |
2007 BUILTIN(ObjectValues) { | 2010 BUILTIN(ObjectValues) { |
2008 HandleScope scope(isolate); | 2011 HandleScope scope(isolate); |
2009 Handle<Object> object = args.atOrUndefined(isolate, 1); | 2012 Handle<Object> object = args.atOrUndefined(isolate, 1); |
2010 Handle<JSReceiver> receiver; | 2013 Handle<JSReceiver> receiver; |
2011 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 2014 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
2012 Object::ToObject(isolate, object)); | 2015 Object::ToObject(isolate, object)); |
(...skipping 21 matching lines...) Expand all Loading... |
2034 HandleScope scope(isolate); | 2037 HandleScope scope(isolate); |
2035 Handle<Object> object = args.atOrUndefined(isolate, 1); | 2038 Handle<Object> object = args.atOrUndefined(isolate, 1); |
2036 Handle<Object> undefined = isolate->factory()->undefined_value(); | 2039 Handle<Object> undefined = isolate->factory()->undefined_value(); |
2037 | 2040 |
2038 Handle<JSReceiver> receiver; | 2041 Handle<JSReceiver> receiver; |
2039 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 2042 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
2040 Object::ToObject(isolate, object)); | 2043 Object::ToObject(isolate, object)); |
2041 | 2044 |
2042 Handle<FixedArray> keys; | 2045 Handle<FixedArray> keys; |
2043 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2046 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2044 isolate, keys, KeyAccumulator::GetKeys(receiver, OWN_ONLY, ALL_PROPERTIES, | 2047 isolate, keys, KeyAccumulator::GetKeys( |
2045 CONVERT_TO_STRING)); | 2048 receiver, KeyCollectionMode::kOwnOnly, ALL_PROPERTIES, |
| 2049 GetKeysConversion::kConvertToString)); |
2046 | 2050 |
2047 Handle<JSObject> descriptors = | 2051 Handle<JSObject> descriptors = |
2048 isolate->factory()->NewJSObject(isolate->object_function()); | 2052 isolate->factory()->NewJSObject(isolate->object_function()); |
2049 | 2053 |
2050 for (int i = 0; i < keys->length(); ++i) { | 2054 for (int i = 0; i < keys->length(); ++i) { |
2051 Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate)); | 2055 Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate)); |
2052 PropertyDescriptor descriptor; | 2056 PropertyDescriptor descriptor; |
2053 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( | 2057 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( |
2054 isolate, receiver, key, &descriptor); | 2058 isolate, receiver, key, &descriptor); |
2055 MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception()); | 2059 MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception()); |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2712 if (!target->IsJSReceiver()) { | 2716 if (!target->IsJSReceiver()) { |
2713 THROW_NEW_ERROR_RETURN_FAILURE( | 2717 THROW_NEW_ERROR_RETURN_FAILURE( |
2714 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 2718 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
2715 isolate->factory()->NewStringFromAsciiChecked( | 2719 isolate->factory()->NewStringFromAsciiChecked( |
2716 "Reflect.ownKeys"))); | 2720 "Reflect.ownKeys"))); |
2717 } | 2721 } |
2718 | 2722 |
2719 Handle<FixedArray> keys; | 2723 Handle<FixedArray> keys; |
2720 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2724 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2721 isolate, keys, | 2725 isolate, keys, |
2722 KeyAccumulator::GetKeys(Handle<JSReceiver>::cast(target), OWN_ONLY, | 2726 KeyAccumulator::GetKeys(Handle<JSReceiver>::cast(target), |
2723 ALL_PROPERTIES, CONVERT_TO_STRING)); | 2727 KeyCollectionMode::kOwnOnly, ALL_PROPERTIES, |
| 2728 GetKeysConversion::kConvertToString)); |
2724 return *isolate->factory()->NewJSArrayWithElements(keys); | 2729 return *isolate->factory()->NewJSArrayWithElements(keys); |
2725 } | 2730 } |
2726 | 2731 |
2727 | 2732 |
2728 // ES6 section 26.1.12 Reflect.preventExtensions | 2733 // ES6 section 26.1.12 Reflect.preventExtensions |
2729 BUILTIN(ReflectPreventExtensions) { | 2734 BUILTIN(ReflectPreventExtensions) { |
2730 HandleScope scope(isolate); | 2735 HandleScope scope(isolate); |
2731 DCHECK_EQ(2, args.length()); | 2736 DCHECK_EQ(2, args.length()); |
2732 Handle<Object> target = args.at<Object>(1); | 2737 Handle<Object> target = args.at<Object>(1); |
2733 | 2738 |
(...skipping 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5543 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5548 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
5544 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5549 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
5545 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5550 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
5546 #undef DEFINE_BUILTIN_ACCESSOR_C | 5551 #undef DEFINE_BUILTIN_ACCESSOR_C |
5547 #undef DEFINE_BUILTIN_ACCESSOR_A | 5552 #undef DEFINE_BUILTIN_ACCESSOR_A |
5548 #undef DEFINE_BUILTIN_ACCESSOR_T | 5553 #undef DEFINE_BUILTIN_ACCESSOR_T |
5549 #undef DEFINE_BUILTIN_ACCESSOR_H | 5554 #undef DEFINE_BUILTIN_ACCESSOR_H |
5550 | 5555 |
5551 } // namespace internal | 5556 } // namespace internal |
5552 } // namespace v8 | 5557 } // namespace v8 |
OLD | NEW |