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

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: fix rebase + re-enable test 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 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 9cc26db23b622e67c63ea7f144ea109f93a495de..3b22fbd31c150fead2ae773d72dc228a90cd543f 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -1800,6 +1800,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, OWN_ONLY, ALL_PROPERTIES,
+ CONVERT_TO_STRING));
+
+ Handle<Object> descriptors =
+ isolate->factory()->NewJSObject(isolate->object_function());
+
+ for (int i = 0; i < keys->length(); ++i) {
+ Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate));
+ PropertyDescriptor descriptor;
+ Maybe<bool> 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()
adamk 2016/02/04 20:13:48 Isn't this guaranteed to return true since we MAYB
caitp (gmail) 2016/02/04 20:14:49 nope, it can return false if the property doesn't
+ ? descriptor.ToObject(isolate)
+ : undefined;
+
+ LookupIterator it = LookupIterator::PropertyOrElement(
+ isolate, descriptors, key, LookupIterator::OWN);
+ Maybe<bool> success = JSReceiver::CreateDataProperty(&it, from_descriptor,
+ Object::DONT_THROW);
+ CHECK(success.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