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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 defineProperty2: function(k, d) { key = k; desc = d; return true } | 282 defineProperty2: function(k, d) { key = k; desc = d; return true } |
283 }) | 283 }) |
284 TestDefine(Proxy.create({ | 284 TestDefine(Proxy.create({ |
285 get: function(pr, pk) { | 285 get: function(pr, pk) { |
286 return function(k, d) { key = k; desc = d; return true } | 286 return function(k, d) { key = k; desc = d; return true } |
287 } | 287 } |
288 })) | 288 })) |
289 | 289 |
290 | 290 |
291 | 291 |
| 292 // Property deletion (delete). |
| 293 |
| 294 var key |
| 295 function TestDelete(handler) { |
| 296 var o = Proxy.create(handler) |
| 297 assertEquals(true, delete o.a) |
| 298 assertEquals("a", key) |
| 299 assertEquals(true, delete o["b"]) |
| 300 assertEquals("b", key) |
| 301 |
| 302 assertEquals(false, delete o.z1) |
| 303 assertEquals("z1", key) |
| 304 assertEquals(false, delete o["z2"]) |
| 305 assertEquals("z2", key); |
| 306 |
| 307 (function() { |
| 308 "use strict" |
| 309 assertEquals(true, delete o.c) |
| 310 assertEquals("c", key) |
| 311 assertEquals(true, delete o["d"]) |
| 312 assertEquals("d", key) |
| 313 |
| 314 assertThrows(function() { delete o.z3 }, TypeError) |
| 315 assertEquals("z3", key) |
| 316 assertThrows(function() { delete o["z4"] }, TypeError) |
| 317 assertEquals("z4", key) |
| 318 })() |
| 319 } |
| 320 |
| 321 TestDelete({ |
| 322 'delete': function(k) { key = k; return k < "z" } |
| 323 }) |
| 324 TestDelete({ |
| 325 'delete': function(k) { return this.delete2(k) }, |
| 326 delete2: function(k) { key = k; return k < "z" } |
| 327 }) |
| 328 TestDelete(Proxy.create({ |
| 329 get: function(pr, pk) { |
| 330 return function(k) { key = k; return k < "z" } |
| 331 } |
| 332 })) |
| 333 |
| 334 |
| 335 |
292 // Property descriptors (Object.getOwnPropertyDescriptor). | 336 // Property descriptors (Object.getOwnPropertyDescriptor). |
293 | 337 |
294 function TestDescriptor(handler) { | 338 function TestDescriptor(handler) { |
295 var o = Proxy.create(handler) | 339 var o = Proxy.create(handler) |
296 var descs = [ | 340 var descs = [ |
297 {configurable: true}, | 341 {configurable: true}, |
298 {value: 34, enumerable: true, configurable: true}, | 342 {value: 34, enumerable: true, configurable: true}, |
299 {value: 3, writable: false, mine: "eyes", configurable: true}, | 343 {value: 3, writable: false, mine: "eyes", configurable: true}, |
300 {get value() { return 20 }, get configurable() { return true }}, | 344 {get value() { return 20 }, get configurable() { return true }}, |
301 {get: function() { "get" }, set: function() { "set" }, configurable: true} | 345 {get: function() { "get" }, set: function() { "set" }, configurable: true} |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 get getOwnPropertyDescriptor() { | 522 get getOwnPropertyDescriptor() { |
479 return function(k) { return {enumerable: k >= "44"} } | 523 return function(k) { return {enumerable: k >= "44"} } |
480 } | 524 } |
481 }) | 525 }) |
482 TestKeys([], { | 526 TestKeys([], { |
483 get getOwnPropertyNames() { | 527 get getOwnPropertyNames() { |
484 return function() { return ["a", "b", "c"] } | 528 return function() { return ["a", "b", "c"] } |
485 }, | 529 }, |
486 getOwnPropertyDescriptor: function(k) { return {} } | 530 getOwnPropertyDescriptor: function(k) { return {} } |
487 }) | 531 }) |
OLD | NEW |