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

Unified Diff: test/mjsunit/harmony/proxies-enumerate.js

Issue 1474083003: [proxies] Implement [[Enumerate]] and [[OwnPropertyKeys]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: gcmole fix Created 5 years, 1 month 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/objects.cc ('k') | test/mjsunit/harmony/proxies-ownkeys.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/proxies-enumerate.js
diff --git a/test/mjsunit/harmony/proxies-enumerate.js b/test/mjsunit/harmony/proxies-enumerate.js
new file mode 100644
index 0000000000000000000000000000000000000000..32d6bb5873283500ec98ac6ec2e769601fa33a3f
--- /dev/null
+++ b/test/mjsunit/harmony/proxies-enumerate.js
@@ -0,0 +1,64 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-proxies
+
+var target = {
+ "target_one": 1
+};
+target.__proto__ = {
+ "target_two": 2
+};
+var handler = {
+ enumerate: function(target) {
+ function* keys() {
+ yield "foo";
+ yield "bar";
+ }
+ return keys();
+ }
+}
+
+var proxy = new Proxy(target, handler);
+
+function TestForIn(receiver, expected) {
+ var result = [];
+ for (var k in receiver) {
+ result.push(k);
+ }
+ assertEquals(expected, result);
+}
+
+TestForIn(proxy, ["foo", "bar"]);
+
+// Properly call traps on proxies on the prototype chain.
+var receiver = {
+ "receiver_one": 1
+};
+receiver.__proto__ = proxy;
+// TODO(jkummerow): Needs proper 'has' trap; implement that and enable this!
+// TestForIn(receiver, ["receiver_one", "foo", "bar"]);
+
+// Fall through to default behavior when trap is undefined.
+handler.enumerate = undefined;
+TestForIn(proxy, ["target_one", "target_two"]);
+delete handler.enumerate;
+TestForIn(proxy, ["target_one", "target_two"]);
+
+// Non-string keys must be filtered.
+function TestNonStringKey(key) {
+ handler.enumerate = function(target) {
+ function* keys() { yield key; }
+ return keys();
+ }
+ assertThrows("for (var k in proxy) {}", TypeError);
+}
+
+TestNonStringKey(1);
+TestNonStringKey(3.14);
+TestNonStringKey(Symbol("foo"));
+TestNonStringKey({bad: "value"});
+TestNonStringKey(null);
+TestNonStringKey(undefined);
+TestNonStringKey(true);
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/harmony/proxies-ownkeys.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698