Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: src/builtins.cc

Issue 1658773003: [esnext] implement Object.getOwnPropertyDescriptors() proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 auto entry_storage = isolate->factory()->NewUninitializedFixedArray(2); 1799 auto entry_storage = isolate->factory()->NewUninitializedFixedArray(2);
1800 entry_storage->set(0, *key); 1800 entry_storage->set(0, *key);
1801 entry_storage->set(1, *value); 1801 entry_storage->set(1, *value);
1802 auto entry = isolate->factory()->NewJSArrayWithElements(entry_storage); 1802 auto entry = isolate->factory()->NewJSArrayWithElements(entry_storage);
1803 keys->set(i, *entry); 1803 keys->set(i, *entry);
1804 } 1804 }
1805 1805
1806 return *isolate->factory()->NewJSArrayWithElements(keys); 1806 return *isolate->factory()->NewJSArrayWithElements(keys);
1807 } 1807 }
1808 1808
1809 BUILTIN(ObjectGetOwnPropertyDescriptors) {
1810 HandleScope scope(isolate);
1811 Handle<Object> object = args.atOrUndefined(isolate, 1);
1812 Handle<Object> undefined = isolate->factory()->undefined_value();
1813
1814 Handle<JSReceiver> receiver;
1815 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1816 Object::ToObject(isolate, object));
1817
1818 Handle<FixedArray> keys;
1819 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1820 isolate, keys, JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY,
1821 ALL_PROPERTIES, CONVERT_TO_STRING));
1822
1823 Handle<Object> descriptors =
1824 isolate->factory()->NewJSObject(isolate->object_function());
1825
1826 for (int i = 0; i < keys->length(); ++i) {
1827 auto key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate));
1828 PropertyDescriptor descriptor;
1829 auto did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor(
1830 isolate, receiver, key, &descriptor);
1831 MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception());
1832 Handle<Object> from_descriptor = did_get_descriptor.FromJust()
1833 ? descriptor.ToObject(isolate)
1834 : undefined;
1835
1836 auto it = LookupIterator::PropertyOrElement(isolate, descriptors, key,
1837 LookupIterator::OWN);
1838
1839 CHECK(
1840 JSReceiver::CreateDataProperty(&it, from_descriptor, Object::DONT_THROW)
1841 .FromJust());
1842 }
1843
1844 return *descriptors;
1845 }
1809 1846
1810 // ES6 section 19.1.2.15 Object.preventExtensions ( O ) 1847 // ES6 section 19.1.2.15 Object.preventExtensions ( O )
1811 BUILTIN(ObjectPreventExtensions) { 1848 BUILTIN(ObjectPreventExtensions) {
1812 HandleScope scope(isolate); 1849 HandleScope scope(isolate);
1813 Handle<Object> object = args.atOrUndefined(isolate, 1); 1850 Handle<Object> object = args.atOrUndefined(isolate, 1);
1814 if (object->IsJSReceiver()) { 1851 if (object->IsJSReceiver()) {
1815 MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object), 1852 MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object),
1816 Object::THROW_ON_ERROR), 1853 Object::THROW_ON_ERROR),
1817 isolate->heap()->exception()); 1854 isolate->heap()->exception());
1818 } 1855 }
(...skipping 2372 matching lines...) Expand 10 before | Expand all | Expand 10 after
4191 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4228 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
4192 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4229 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
4193 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4230 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4194 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4231 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4195 #undef DEFINE_BUILTIN_ACCESSOR_C 4232 #undef DEFINE_BUILTIN_ACCESSOR_C
4196 #undef DEFINE_BUILTIN_ACCESSOR_A 4233 #undef DEFINE_BUILTIN_ACCESSOR_A
4197 4234
4198 4235
4199 } // namespace internal 4236 } // namespace internal
4200 } // namespace v8 4237 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698