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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ownKeys: function() { return this.enumerate() }, 116 ownKeys: function() { return this.enumerate() },
117 enumerate: function() { throw "myexn" } 117 enumerate: function() { throw "myexn" }
118 }) 118 })
119 119
120 TestForInThrow(new Proxy({}, { 120 TestForInThrow(new Proxy({}, {
121 get: function(pr, pk) { 121 get: function(pr, pk) {
122 return function() { throw "myexn" } 122 return function() { throw "myexn" }
123 } 123 }
124 })); 124 }));
125 125
126 (function() { 126
127 var p = new Proxy({}, {ownKeys:function() { return ["0"]; }}); 127 function keys(object) {
128 var keys = [];
129 for (var k in object) {
130 keys.push(k);
131 }
132 return keys;
133 }
134
135 (function testKeysProxyOnProtoEmpty() {
136 var p = new Proxy({}, {
137 ownKeys() { return []; },
138 });
128 var o = [0]; 139 var o = [0];
129 o.__proto__ = p; 140 o.__proto__ = p;
130 var keys = []; 141 assertEquals(["0"], keys(o));
131 for (var k in o) { keys.push(k); }; 142
132 assertEquals(["0"], keys); 143 delete o[0];
144 assertEquals([], keys(o));
133 })(); 145 })();
134 146
147 (function testKeysProxyOnProto() {
148 var handler = {ownKeys() { return ["0"]; }};
149 var proxy = new Proxy({}, handler);
150 var object = [0];
151 object.__proto__ = proxy;
152 assertEquals(["0"], keys(object));
153
154 // The Proxy doesn't set his ownKeys enumerable.
155 delete object[0];
156 assertEquals([], keys(object));
157
158 // The [[Has]] trap has no influence on which are enumerable properties are
159 // shown in for-in.
160 handler.has = function() { return true };
161 assertEquals([], keys(object));
162
163 handler.getOwnPropertyDescriptor = function() {
164 return {enumerable: true, configurable: true}
165 }
166 assertEquals(["0"], keys(object));
167 })();
168
169 (function testKeysProxyProto() {
170 var target = {t1:true, t2:true};
171 var handler = {};
172 var proxy = new Proxy(target, handler);
173
174 assertEquals(["t1", "t2"], keys(proxy));
175
176 target.__proto__ = {p1:true, p2:true};
177 assertEquals(["t1", "t2", "p1", "p2"], keys(proxy));
178
179 handler.getPrototypeOf = function(target) {
180 return {p3:true, p4:true};
181 };
182 // for-in walks the prototype chain for the [[Has]] / Enumerable check.
183 assertEquals(["t1", "t2", "p3", "p4"], keys(proxy));
184
185 // [[Has]] is not used in for-in.
186 handler.has = function() { return false };
187 assertEquals(["t1", "t2", "p3", "p4"], keys(proxy));
188
189 // Proxy intercepts enumerability check.
190 handler.getOwnPropertyDescriptor = function() {
191 return {enumerable: false, configurable: true}
192 }
193 assertEquals([], keys(proxy));
194
195 handler.getOwnPropertyDescriptor = function() {
196 return {enumerable: true, configurable: true}
197 }
198 assertEquals(["t1", "t2", "p3", "p4"], keys(proxy));
199
200 handler.getOwnPropertyDescriptor = function(target, key) {
201 return {
202 enumerable: key in target,
203 configurable: true
204 }
205 }
206 assertEquals(["t1", "t2"], keys(proxy));
207
208 handler.getPrototypeOf = function() { throw "error" };
209 assertThrowsEquals(() => {keys(proxy)}, "error");
210 })();
211
212
135 (function () { 213 (function () {
136 var p = new Proxy({}, {ownKeys: function() { return ["1", Symbol(), "2"] }}); 214 var symbol = Symbol();
215 var p = new Proxy({}, {ownKeys() { return ["1", symbol, "2"] }});
137 assertEquals(["1","2"], Object.getOwnPropertyNames(p)); 216 assertEquals(["1","2"], Object.getOwnPropertyNames(p));
217 assertEquals([symbol], Object.getOwnPropertySymbols(p));
138 })(); 218 })();
OLDNEW
« 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