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

Unified Diff: test/mjsunit/es6/proxies-for.js

Issue 1748923003: [proxies] use [[GetPrototypeOf]] trap in for-in (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge with master Created 4 years, 9 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/runtime/runtime-forin.cc ('k') | test/mjsunit/for-in-opt.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/es6/proxies-for.js
diff --git a/test/mjsunit/es6/proxies-for.js b/test/mjsunit/es6/proxies-for.js
index f31ee2ad5c93ca0b6245c37261109edbd864e8a7..5b818453a9ce1726b7f685dc6159a393b007870b 100644
--- a/test/mjsunit/es6/proxies-for.js
+++ b/test/mjsunit/es6/proxies-for.js
@@ -123,16 +123,96 @@ TestForInThrow(new Proxy({}, {
}
}));
-(function() {
- var p = new Proxy({}, {ownKeys:function() { return ["0"]; }});
+
+function keys(object) {
+ var keys = [];
+ for (var k in object) {
+ keys.push(k);
+ }
+ return keys;
+}
+
+(function testKeysProxyOnProtoEmpty() {
+ var p = new Proxy({}, {
+ ownKeys() { return []; },
+ });
var o = [0];
o.__proto__ = p;
- var keys = [];
- for (var k in o) { keys.push(k); };
- assertEquals(["0"], keys);
+ assertEquals(["0"], keys(o));
+
+ delete o[0];
+ assertEquals([], keys(o));
})();
+(function testKeysProxyOnProto() {
+ var handler = {ownKeys() { return ["0"]; }};
+ var proxy = new Proxy({}, handler);
+ var object = [0];
+ object.__proto__ = proxy;
+ assertEquals(["0"], keys(object));
+
+ // The Proxy doesn't set his ownKeys enumerable.
+ delete object[0];
+ assertEquals([], keys(object));
+
+ // The [[Has]] trap has no influence on which are enumerable properties are
+ // shown in for-in.
+ handler.has = function() { return true };
+ assertEquals([], keys(object));
+
+ handler.getOwnPropertyDescriptor = function() {
+ return {enumerable: true, configurable: true}
+ }
+ assertEquals(["0"], keys(object));
+})();
+
+(function testKeysProxyProto() {
+ var target = {t1:true, t2:true};
+ var handler = {};
+ var proxy = new Proxy(target, handler);
+
+ assertEquals(["t1", "t2"], keys(proxy));
+
+ target.__proto__ = {p1:true, p2:true};
+ assertEquals(["t1", "t2", "p1", "p2"], keys(proxy));
+
+ handler.getPrototypeOf = function(target) {
+ return {p3:true, p4:true};
+ };
+ // for-in walks the prototype chain for the [[Has]] / Enumerable check.
+ assertEquals(["t1", "t2", "p3", "p4"], keys(proxy));
+
+ // [[Has]] is not used in for-in.
+ handler.has = function() { return false };
+ assertEquals(["t1", "t2", "p3", "p4"], keys(proxy));
+
+ // Proxy intercepts enumerability check.
+ handler.getOwnPropertyDescriptor = function() {
+ return {enumerable: false, configurable: true}
+ }
+ assertEquals([], keys(proxy));
+
+ handler.getOwnPropertyDescriptor = function() {
+ return {enumerable: true, configurable: true}
+ }
+ assertEquals(["t1", "t2", "p3", "p4"], keys(proxy));
+
+ handler.getOwnPropertyDescriptor = function(target, key) {
+ return {
+ enumerable: key in target,
+ configurable: true
+ }
+ }
+ assertEquals(["t1", "t2"], keys(proxy));
+
+ handler.getPrototypeOf = function() { throw "error" };
+ assertThrowsEquals(() => {keys(proxy)}, "error");
+})();
+
+
(function () {
- var p = new Proxy({}, {ownKeys: function() { return ["1", Symbol(), "2"] }});
+ var symbol = Symbol();
+ var p = new Proxy({}, {ownKeys() { return ["1", symbol, "2"] }});
assertEquals(["1","2"], Object.getOwnPropertyNames(p));
+ assertEquals([symbol], Object.getOwnPropertySymbols(p));
})();
« no previous file with comments | « src/runtime/runtime-forin.cc ('k') | test/mjsunit/for-in-opt.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698