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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 return *isolate->factory()->NewJSArrayWithElements(keys); | 1714 return *isolate->factory()->NewJSArrayWithElements(keys); |
1715 } | 1715 } |
1716 | 1716 |
1717 | 1717 |
1718 BUILTIN(ObjectValues) { | 1718 BUILTIN(ObjectValues) { |
1719 HandleScope scope(isolate); | 1719 HandleScope scope(isolate); |
1720 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1720 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1721 Handle<JSReceiver> receiver; | 1721 Handle<JSReceiver> receiver; |
1722 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1722 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
1723 Object::ToObject(isolate, object)); | 1723 Object::ToObject(isolate, object)); |
1724 Handle<FixedArray> keys; | 1724 Handle<FixedArray> values; |
1725 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1725 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1726 isolate, keys, | 1726 isolate, values, |
1727 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS, | 1727 JSReceiver::GetOwnValues(receiver, SKIP_SYMBOLS, CONVERT_TO_STRING)); |
1728 CONVERT_TO_STRING)); | 1728 return *isolate->factory()->NewJSArrayWithElements(values); |
1729 | |
1730 for (int i = 0; i < keys->length(); ++i) { | |
1731 auto key = Handle<Name>::cast(FixedArray::get(keys, i)); | |
1732 Handle<Object> value; | |
1733 | |
1734 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1735 isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT)); | |
1736 | |
1737 keys->set(i, *value); | |
1738 } | |
1739 | |
1740 return *isolate->factory()->NewJSArrayWithElements(keys); | |
1741 } | 1729 } |
1742 | 1730 |
1743 | 1731 |
1744 BUILTIN(ObjectEntries) { | 1732 BUILTIN(ObjectEntries) { |
1745 HandleScope scope(isolate); | 1733 HandleScope scope(isolate); |
1746 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1734 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1747 Handle<JSReceiver> receiver; | 1735 Handle<JSReceiver> receiver; |
1748 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1736 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
1749 Object::ToObject(isolate, object)); | 1737 Object::ToObject(isolate, object)); |
1750 Handle<FixedArray> keys; | 1738 Handle<FixedArray> entries; |
1751 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1739 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1752 isolate, keys, | 1740 isolate, entries, |
1753 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS, | 1741 JSReceiver::GetOwnEntries(receiver, SKIP_SYMBOLS, CONVERT_TO_STRING)); |
1754 CONVERT_TO_STRING)); | 1742 return *isolate->factory()->NewJSArrayWithElements(entries); |
1755 | |
1756 for (int i = 0; i < keys->length(); ++i) { | |
1757 auto key = Handle<Name>::cast(FixedArray::get(keys, i)); | |
1758 Handle<Object> value; | |
1759 | |
1760 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1761 isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT)); | |
1762 | |
1763 auto entry_storage = isolate->factory()->NewUninitializedFixedArray(2); | |
1764 entry_storage->set(0, *key); | |
1765 entry_storage->set(1, *value); | |
1766 auto entry = isolate->factory()->NewJSArrayWithElements(entry_storage); | |
1767 keys->set(i, *entry); | |
1768 } | |
1769 | |
1770 return *isolate->factory()->NewJSArrayWithElements(keys); | |
1771 } | 1743 } |
1772 | 1744 |
1773 | 1745 |
1774 // ES6 section 19.1.2.15 Object.preventExtensions ( O ) | 1746 // ES6 section 19.1.2.15 Object.preventExtensions ( O ) |
1775 BUILTIN(ObjectPreventExtensions) { | 1747 BUILTIN(ObjectPreventExtensions) { |
1776 HandleScope scope(isolate); | 1748 HandleScope scope(isolate); |
1777 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1749 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1778 if (object->IsJSReceiver()) { | 1750 if (object->IsJSReceiver()) { |
1779 MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object), | 1751 MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object), |
1780 Object::THROW_ON_ERROR), | 1752 Object::THROW_ON_ERROR), |
(...skipping 2374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4155 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4127 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4156 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4128 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4157 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4129 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4158 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4130 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4159 #undef DEFINE_BUILTIN_ACCESSOR_C | 4131 #undef DEFINE_BUILTIN_ACCESSOR_C |
4160 #undef DEFINE_BUILTIN_ACCESSOR_A | 4132 #undef DEFINE_BUILTIN_ACCESSOR_A |
4161 | 4133 |
4162 | 4134 |
4163 } // namespace internal | 4135 } // namespace internal |
4164 } // namespace v8 | 4136 } // namespace v8 |
OLD | NEW |