OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-proxies | 5 // Flags: --harmony-proxies |
6 | 6 |
7 // Check basic call to trap. | 7 // Check basic call to trap. |
8 | 8 |
9 var g_target, g_name, g_desc; | 9 var g_target, g_name, g_desc; |
10 var handler = { | 10 var handler = { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 Object.defineProperty(proxy, 0, desc); | 43 Object.defineProperty(proxy, 0, desc); |
44 assertTrue(typeof g_name === "string"); | 44 assertTrue(typeof g_name === "string"); |
45 assertEquals("0", g_name); | 45 assertEquals("0", g_name); |
46 | 46 |
47 // Step 10: Trap returns false. | 47 // Step 10: Trap returns false. |
48 handler.defineProperty = function(t, n, d) { return false; } | 48 handler.defineProperty = function(t, n, d) { return false; } |
49 assertThrows("Object.defineProperty(proxy, 'foo', desc)", TypeError); | 49 assertThrows("Object.defineProperty(proxy, 'foo', desc)", TypeError); |
50 | 50 |
51 // Step 15a: Trap returns true for adding a property to a non-extensible target. | 51 // Step 15a: Trap returns true for adding a property to a non-extensible target. |
52 handler.defineProperty = function(t, n, d) { return true; } | 52 handler.defineProperty = function(t, n, d) { return true; } |
53 Object.freeze(target); | 53 Object.preventExtensions(target); |
54 assertThrows("Object.defineProperty(proxy, 'foo', desc)", TypeError); | 54 assertThrows("Object.defineProperty(proxy, 'foo', desc)", TypeError); |
55 | 55 |
56 // Step 15b: Trap returns true for adding a non-configurable property. | 56 // Step 15b: Trap returns true for adding a non-configurable property. |
57 target = {}; | 57 target = {}; |
58 proxy = new Proxy(target, handler); | 58 proxy = new Proxy(target, handler); |
59 desc = {value: 1, writable: true, configurable: false, enumerable: true}; | 59 desc = {value: 1, writable: true, configurable: false, enumerable: true}; |
60 assertThrows("Object.defineProperty(proxy, 'foo', desc)", TypeError); | 60 assertThrows("Object.defineProperty(proxy, 'foo', desc)", TypeError); |
61 // No exception is thrown if a non-configurable property exists on the target. | 61 // No exception is thrown if a non-configurable property exists on the target. |
62 Object.defineProperty(target, "nonconf", | 62 Object.defineProperty(target, "nonconf", |
63 {value: 1, writable: true, configurable: false}); | 63 {value: 1, writable: true, configurable: false}); |
64 Object.defineProperty(proxy, "nonconf", {value: 2, configurable: false}); | 64 Object.defineProperty(proxy, "nonconf", {value: 2, configurable: false}); |
65 | 65 |
66 // Step 16a: Trap returns true for non-compatible property descriptor. | 66 // Step 16a: Trap returns true for non-compatible property descriptor. |
67 Object.defineProperty(target, "foo", | 67 Object.defineProperty(target, "foo", |
68 {value: 1, writable: false, configurable: false}); | 68 {value: 1, writable: false, configurable: false}); |
69 assertThrows("Object.defineProperty(proxy, 'foo', {value: 2})", TypeError); | 69 assertThrows("Object.defineProperty(proxy, 'foo', {value: 2})", TypeError); |
70 | 70 |
71 // Step 16b: Trap returns true for overwriting a configurable property | 71 // Step 16b: Trap returns true for overwriting a configurable property |
72 // with a non-configurable descriptor. | 72 // with a non-configurable descriptor. |
73 target.bar = "baz"; | 73 target.bar = "baz"; |
74 assertThrows("Object.defineProperty(proxy, 'bar', {configurable: false})", | 74 assertThrows("Object.defineProperty(proxy, 'bar', {configurable: false})", |
75 TypeError); | 75 TypeError); |
OLD | NEW |