OLD | NEW |
1 // Flags: --harmony-proxies | 1 // Flags: --harmony-proxies |
2 | 2 |
3 // Copyright 2008 the V8 project authors. All rights reserved. | 3 // Copyright 2008 the V8 project authors. All rights reserved. |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 assertSame(Object.getPrototypeOf(p1), null) | 302 assertSame(Object.getPrototypeOf(p1), null) |
303 assertSame(Object.getPrototypeOf(p2), o) | 303 assertSame(Object.getPrototypeOf(p2), o) |
304 assertSame(Object.getPrototypeOf(p3), p2) | 304 assertSame(Object.getPrototypeOf(p3), p2) |
305 assertSame(Object.getPrototypeOf(p4), null) | 305 assertSame(Object.getPrototypeOf(p4), null) |
306 } | 306 } |
307 | 307 |
308 TestPrototype() | 308 TestPrototype() |
309 | 309 |
310 | 310 |
311 | 311 |
312 // Property names (Object.getOwnPropertyNames). | 312 // Property names (Object.getOwnPropertyNames, Object.keys). |
313 | 313 |
314 function TestPropertyNames(names, handler) { | 314 function TestPropertyNames(names, handler) { |
315 var p = Proxy.create(handler) | 315 var p = Proxy.create(handler) |
316 assertArrayEquals(names, Object.getOwnPropertyNames(p)) | 316 assertArrayEquals(names, Object.getOwnPropertyNames(p)) |
317 } | 317 } |
318 | 318 |
319 TestPropertyNames([], { | 319 TestPropertyNames([], { |
320 getOwnPropertyNames: function() { return [] } | 320 getOwnPropertyNames: function() { return [] } |
321 }) | 321 }) |
322 TestPropertyNames(["a", "zz", " ", "0"], { | 322 TestPropertyNames(["a", "zz", " ", "0"], { |
323 getOwnPropertyNames: function() { return ["a", "zz", " ", 0] } | 323 getOwnPropertyNames: function() { return ["a", "zz", " ", 0] } |
324 }) | 324 }) |
325 TestPropertyNames(["throw", "function "], { | 325 TestPropertyNames(["throw", "function "], { |
326 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 326 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, |
327 getOwnPropertyNames2: function() { return ["throw", "function "] } | 327 getOwnPropertyNames2: function() { return ["throw", "function "] } |
328 }) | 328 }) |
329 TestPropertyNames(["[object Object]"], { | 329 TestPropertyNames(["[object Object]"], { |
330 get getOwnPropertyNames() { | 330 get getOwnPropertyNames() { |
331 return function() { return [{}] } | 331 return function() { return [{}] } |
332 } | 332 } |
333 }) | 333 }) |
| 334 |
| 335 |
| 336 function TestKeys(names, handler) { |
| 337 var p = Proxy.create(handler) |
| 338 assertArrayEquals(names, Object.keys(p)) |
| 339 } |
| 340 |
| 341 TestKeys([], { |
| 342 keys: function() { return [] } |
| 343 }) |
| 344 TestKeys(["a", "zz", " ", "0"], { |
| 345 keys: function() { return ["a", "zz", " ", 0] } |
| 346 }) |
| 347 TestKeys(["throw", "function "], { |
| 348 keys: function() { return this.keys2() }, |
| 349 keys2: function() { return ["throw", "function "] } |
| 350 }) |
| 351 TestKeys(["[object Object]"], { |
| 352 get keys() { |
| 353 return function() { return [{}] } |
| 354 } |
| 355 }) |
| 356 TestKeys(["a", "0"], { |
| 357 getOwnPropertyNames: function() { return ["a", 23, "zz", "", 0] }, |
| 358 getOwnPropertyDescriptor: function(k) { return {enumerable: k.length == 1} } |
| 359 }) |
| 360 TestKeys(["23", "zz", ""], { |
| 361 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, |
| 362 getOwnPropertyNames2: function() { return ["a", 23, "zz", "", 0] }, |
| 363 getOwnPropertyDescriptor: function(k) { |
| 364 return this.getOwnPropertyDescriptor2(k) |
| 365 }, |
| 366 getOwnPropertyDescriptor2: function(k) { return {enumerable: k.length != 1} } |
| 367 }) |
| 368 TestKeys(["a", "b", "c", "5"], { |
| 369 get getOwnPropertyNames() { |
| 370 return function() { return ["0", 4, "a", "b", "c", 5] } |
| 371 }, |
| 372 get getOwnPropertyDescriptor() { |
| 373 return function(k) { return {enumerable: k >= "44"} } |
| 374 } |
| 375 }) |
| 376 TestKeys([], { |
| 377 get getOwnPropertyNames() { |
| 378 return function() { return ["a", "b", "c"] } |
| 379 }, |
| 380 getOwnPropertyDescriptor: function(k) { return {} } |
| 381 }) |
OLD | NEW |