OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 14 matching lines...) Expand all Loading... |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Tests the Object.seal and Object.isSealed methods - ES 15.2.3.9 and | 28 // Tests the Object.seal and Object.isSealed methods - ES 15.2.3.9 and |
29 // ES 15.2.3.12 | 29 // ES 15.2.3.12 |
30 | 30 |
31 | 31 |
32 // Test that we throw an error if an object is not passed as argument. | 32 // Test that we throw an error if an object is not passed as argument. |
33 var non_objects = new Array(undefined, null, 1, -1, 0, 42.43); | 33 var non_objects = new Array(undefined, null, 1, -1, 0, 42.43); |
34 for (var key in non_objects) { | 34 for (var key in non_objects) { |
| 35 var exception = false; |
35 try { | 36 try { |
36 Object.seal(non_objects[key]); | 37 Object.seal(non_objects[key]); |
37 assertUnreachable(); | |
38 } catch(e) { | 38 } catch(e) { |
| 39 exception = true; |
39 assertTrue(/Object.seal called on non-object/.test(e)); | 40 assertTrue(/Object.seal called on non-object/.test(e)); |
40 } | 41 } |
| 42 assertTrue(exception); |
41 } | 43 } |
42 | 44 |
43 for (var key in non_objects) { | 45 for (var key in non_objects) { |
| 46 exception = false; |
44 try { | 47 try { |
45 Object.isSealed(non_objects[key]); | 48 Object.isSealed(non_objects[key]); |
46 assertUnreachable(); | |
47 } catch(e) { | 49 } catch(e) { |
| 50 exception = true; |
48 assertTrue(/Object.isSealed called on non-object/.test(e)); | 51 assertTrue(/Object.isSealed called on non-object/.test(e)); |
49 } | 52 } |
| 53 assertTrue(exception); |
50 } | 54 } |
51 | 55 |
52 // Test normal data properties. | 56 // Test normal data properties. |
53 var obj = { x: 42, z: 'foobar' }; | 57 var obj = { x: 42, z: 'foobar' }; |
54 var desc = Object.getOwnPropertyDescriptor(obj, 'x'); | 58 var desc = Object.getOwnPropertyDescriptor(obj, 'x'); |
55 assertTrue(desc.writable); | 59 assertTrue(desc.writable); |
56 assertTrue(desc.configurable); | 60 assertTrue(desc.configurable); |
57 assertEquals(42, desc.value); | 61 assertEquals(42, desc.value); |
58 | 62 |
59 desc = Object.getOwnPropertyDescriptor(obj, 'z'); | 63 desc = Object.getOwnPropertyDescriptor(obj, 'z'); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 var obj4 = {}; | 185 var obj4 = {}; |
182 Object.defineProperty(obj4, 'x', {configurable: true, writable: false}); | 186 Object.defineProperty(obj4, 'x', {configurable: true, writable: false}); |
183 Object.defineProperty(obj4, 'y', {configurable: false, writable: false}); | 187 Object.defineProperty(obj4, 'y', {configurable: false, writable: false}); |
184 Object.preventExtensions(obj4); | 188 Object.preventExtensions(obj4); |
185 | 189 |
186 assertFalse(Object.isSealed(obj4)); | 190 assertFalse(Object.isSealed(obj4)); |
187 | 191 |
188 // Make sure that Object.seal returns the sealed object. | 192 // Make sure that Object.seal returns the sealed object. |
189 var obj4 = {}; | 193 var obj4 = {}; |
190 assertTrue(obj4 === Object.seal(obj4)); | 194 assertTrue(obj4 === Object.seal(obj4)); |
OLD | NEW |