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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index e05a4dd45a98a38c8fc11e8f95f4ca1685a769cd..3e2df52841ed35af8b5f2015eab79a753f0cd38e 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -1806,6 +1806,43 @@ BUILTIN(ObjectEntries) {
return *isolate->factory()->NewJSArrayWithElements(keys);
}
+BUILTIN(ObjectGetOwnPropertyDescriptors) {
+ HandleScope scope(isolate);
+ Handle<Object> object = args.atOrUndefined(isolate, 1);
+ Handle<Object> undefined = isolate->factory()->undefined_value();
+
+ Handle<JSReceiver> receiver;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
+ Object::ToObject(isolate, object));
+
+ Handle<FixedArray> keys;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, keys, JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY,
+ ALL_PROPERTIES, CONVERT_TO_STRING));
+
+ Handle<Object> descriptors =
+ isolate->factory()->NewJSObject(isolate->object_function());
+
+ for (int i = 0; i < keys->length(); ++i) {
+ auto key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate));
+ PropertyDescriptor descriptor;
+ auto did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor(
+ isolate, receiver, key, &descriptor);
+ MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception());
+ Handle<Object> from_descriptor = did_get_descriptor.FromJust()
+ ? descriptor.ToObject(isolate)
+ : undefined;
+
+ auto it = LookupIterator::PropertyOrElement(isolate, descriptors, key,
+ LookupIterator::OWN);
+
+ CHECK(
+ JSReceiver::CreateDataProperty(&it, from_descriptor, Object::DONT_THROW)
+ .FromJust());
+ }
+
+ return *descriptors;
+}
// ES6 section 19.1.2.15 Object.preventExtensions ( O )
BUILTIN(ObjectPreventExtensions) {
« 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