Chromium Code Reviews| Index: test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js |
| diff --git a/test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js b/test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d68afecc6bcb2e497bfacdbeddc6dc2287a3980d |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js |
| @@ -0,0 +1,100 @@ |
| +// Copyright 2015 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --harmony-proxies |
| + |
| +var target = {}; |
| +var configurable_desc = { |
| + value: 123, |
| + configurable: true, |
| + writable: true, |
| + enumerable: false, |
| +}; |
| +Object.defineProperty(target, "configurable", configurable_desc); |
| +var nonconfigurable_desc = { |
| + value: 234, |
| + configurable: false, |
| + writable: false, |
| + enumerable: true |
| +} |
| +Object.defineProperty(target, "nonconfigurable", nonconfigurable_desc); |
|
Camillo Bruni
2015/11/16 16:15:40
I'd repeat this exact test with an empty proxy: ne
Jakob Kummerow
2015/11/17 12:42:51
This isn't a test... I guess you mean lines 44/46.
|
| + |
| +var proxied_desc = { |
| + value: 345, |
| + configurable: true |
| +}; |
| + |
| +var handler = { |
| + "getOwnPropertyDescriptor": function(target, name) { |
| + if (name === "proxied") { |
| + return proxied_desc; |
| + } |
| + if (name === "return_null") { |
| + return null; |
| + } |
| + return Object.getOwnPropertyDescriptor(target, name); |
| + } |
| +}; |
| + |
| +var proxy = new Proxy(target, handler); |
| + |
| +// Checking basic functionality: |
|
Camillo Bruni
2015/11/16 16:15:40
Maybe this is too much work... I tried to order th
Jakob Kummerow
2015/11/17 12:42:51
Done, added a third section that specifically trig
|
| + |
| +assertEquals(configurable_desc, |
| + Object.getOwnPropertyDescriptor(proxy, "configurable")); |
| +assertEquals(nonconfigurable_desc, |
| + Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")); |
| +assertEquals({ value: proxied_desc.value, |
| + configurable: proxied_desc.configurable, |
| + enumerable: false, |
| + writable: false }, |
| + Object.getOwnPropertyDescriptor(proxy, "proxied")); |
| + |
| +assertThrows('Object.getOwnPropertyDescriptor(proxy, "return_null")'); |
| + |
| +handler.getOwnPropertyDescriptor = undefined; |
| +assertEquals(configurable_desc, |
| + Object.getOwnPropertyDescriptor(proxy, "configurable")); |
| + |
| +handler.getOwnPropertyDescriptor = function(target, name) { |
| + return {value: 456, configurable: true, writable: true} |
| +}; |
| +assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")'); |
|
Camillo Bruni
2015/11/16 16:15:40
please add a comment why this should throw, I end
Jakob Kummerow
2015/11/17 12:42:51
Done. (It throws because nonconfigurable propertie
|
| + |
| +// Checking invariants mentioned explicitly by the ES spec: |
| + |
| +// "A property cannot be reported as non-existent, if it exists as a |
| +// non-configurable own property of the target object." |
| +handler.getOwnPropertyDescriptor = function(target, name) { return undefined; }; |
| +assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")'); |
| +assertEquals(undefined, Object.getOwnPropertyDescriptor(proxy, "configurable")); |
| + |
| +// "A property cannot be reported as non-configurable, if it does not exist |
| +// as an own property of the target object or if it exists as a configurable |
| +// own property of the target object." |
| +handler.getOwnPropertyDescriptor = function(target, name) { |
| + return {value: 234, configurable: false, enumerable: true}; |
| +}; |
| +assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonexistent")'); |
| +assertThrows('Object.getOwnPropertyDescriptor(proxy, "configurable")'); |
| +assertEquals( |
| + false, |
| + Object.getOwnPropertyDescriptor(proxy, "nonconfigurable").configurable); |
| + |
| +// "A property cannot be reported as non-existent, if it exists as an own |
| +// property of the target object and the target object is not extensible." |
| +Object.seal(target); |
| +handler.getOwnPropertyDescriptor = function(target, name) { return undefined; }; |
| +assertThrows('Object.getOwnPropertyDescriptor(proxy, "configurable")'); |
| +assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")'); |
| +assertEquals(undefined, Object.getOwnPropertyDescriptor(proxy, "nonexistent")); |
| + |
| +// "A property cannot be reported as existent, if it does not exist as an |
| +// own property of the target object and the target object is not extensible." |
| +var existent_desc = {value: "yes"}; |
| +handler.getOwnPropertyDescriptor = function() { return existent_desc; }; |
| +assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonexistent")'); |
| +assertEquals( |
| + {value: "yes", writable: false, enumerable: false, configurable: false}, |
| + Object.getOwnPropertyDescriptor(proxy, "configurable")); |