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

Unified Diff: src/builtins.cc

Issue 1581033002: [es7] implement Object.values() / Object.entries() proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Execution::ToObject() -> Object::ToObject(), test fixups 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 35671d2c4c813c5adccd36ca989e9f101e6cb092..b7f30433d5f35a33128b1494639b82679c1174b9 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -1653,6 +1653,62 @@ BUILTIN(ObjectKeys) {
}
+BUILTIN(ObjectValues) {
+ HandleScope scope(isolate);
+ Handle<Object> object = args.atOrUndefined(isolate, 1);
+ 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, ENUMERABLE_STRINGS,
+ CONVERT_TO_STRING));
+
+ for (int i = 0; i < keys->length(); ++i) {
+ auto key = Handle<Name>::cast(FixedArray::get(keys, i));
+ Handle<Object> value;
+
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT));
+
+ keys->set(i, *value);
+ }
+
+ return *isolate->factory()->NewJSArrayWithElements(keys);
+}
+
+
+BUILTIN(ObjectEntries) {
+ HandleScope scope(isolate);
+ Handle<Object> object = args.atOrUndefined(isolate, 1);
+ 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, ENUMERABLE_STRINGS,
+ CONVERT_TO_STRING));
+
+ for (int i = 0; i < keys->length(); ++i) {
+ auto key = Handle<Name>::cast(FixedArray::get(keys, i));
+ Handle<Object> value;
+
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT));
+
+ auto entry_storage = isolate->factory()->NewUninitializedFixedArray(2);
+ entry_storage->set(0, *key);
+ entry_storage->set(1, *value);
+ auto entry = isolate->factory()->NewJSArrayWithElements(entry_storage);
+ keys->set(i, *entry);
+ }
+
+ return *isolate->factory()->NewJSArrayWithElements(keys);
+}
+
+
// ES6 section 19.1.2.15 Object.preventExtensions ( O )
BUILTIN(ObjectPreventExtensions) {
HandleScope scope(isolate);
« 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