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

Side by Side Diff: test/mjsunit/harmony/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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 ownKeys: function() { return this.enumerate() }, 118 ownKeys: function() { return this.enumerate() },
119 enumerate: function() { throw "myexn" } 119 enumerate: function() { throw "myexn" }
120 }) 120 })
121 121
122 TestForInThrow(new Proxy({}, { 122 TestForInThrow(new Proxy({}, {
123 get: function(pr, pk) { 123 get: function(pr, pk) {
124 return function() { throw "myexn" } 124 return function() { throw "myexn" }
125 } 125 }
126 })); 126 }));
127 127
128 (function() { 128
129 var p = new Proxy({}, {ownKeys:function() { return ["0"]; }}); 129 function keys(object) {
130 var keys = [];
131 for (var k in object) {
132 keys.push(k);
133 }
134 return keys;
135 }
136
137 (function testKeysProxyOnProto() {
138 var p = new Proxy({}, {ownKeys() { return ["0"]; }});
130 var o = [0]; 139 var o = [0];
131 o.__proto__ = p; 140 o.__proto__ = p;
132 var keys = []; 141 assertEquals(["0"], keys(o));
neis 2016/03/01 13:40:31 Also do this test when o is empty, for instance.
Camillo Bruni 2016/03/01 19:04:57 done.
133 for (var k in o) { keys.push(k); };
134 assertEquals(["0"], keys);
135 })(); 142 })();
136 143
144 (function testKeysProxyProto() {
145 var target = {t1:true, t2:true};
146 var handler = {}
147 var proxy = new Proxy(target, handler);
148
149 assertEquals(["t1", "t2"], keys(proxy));
150
151 target.__proto__ = {p1:true, p2:true};
152 assertEquals(["t1", "t2", "p1", "p2"], keys(proxy));
153
154 handler.getPrototypeOf = function(target) {
155 return {p3:true, p4:true};
156 };
157 assertEquals(["t1", "t2"], keys(proxy));
158 handler.has = function() { return true };
159 assertEquals(["t1", "t2", "p3", "p4"], keys(proxy));
160
161 handler.getPrototypeOf = function() { throw "error" };
162 assertThrowsEquals(()=>{ keys(proxy) }, "error");
163 })();
164
165
137 (function () { 166 (function () {
138 var p = new Proxy({}, {ownKeys: function() { return ["1", Symbol(), "2"] }}); 167 var p = new Proxy({}, {ownKeys() { return ["1", Symbol(), "2"] }});
139 assertEquals(["1","2"], Object.getOwnPropertyNames(p)); 168 assertEquals(["1","2"], Object.getOwnPropertyNames(p));
neis 2016/03/01 13:40:31 Also call getOwnPropertySymbols here.
Camillo Bruni 2016/03/01 19:04:57 done.
140 })(); 169 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698