| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // Make sure we are no longer extensible. | 69 // Make sure we are no longer extensible. |
| 70 assertFalse(Object.isExtensible(obj)); | 70 assertFalse(Object.isExtensible(obj)); |
| 71 assertTrue(Object.isSealed(obj)); | 71 assertTrue(Object.isSealed(obj)); |
| 72 | 72 |
| 73 // We should not be frozen, since we are still able to | 73 // We should not be frozen, since we are still able to |
| 74 // update values. | 74 // update values. |
| 75 assertFalse(Object.isFrozen(obj)); | 75 assertFalse(Object.isFrozen(obj)); |
| 76 | 76 |
| 77 // We should not allow new properties to be added. | 77 // We should not allow new properties to be added. |
| 78 try { | 78 obj.foo = 42; |
| 79 obj.foo = 42; | 79 assertEquals(obj.foo, undefined); |
| 80 assertUnreachable(); | |
| 81 } catch(e) { | |
| 82 assertTrue(/object is not extensible/.test(e)); | |
| 83 } | |
| 84 | 80 |
| 85 desc = Object.getOwnPropertyDescriptor(obj, 'x'); | 81 desc = Object.getOwnPropertyDescriptor(obj, 'x'); |
| 86 assertTrue(desc.writable); | 82 assertTrue(desc.writable); |
| 87 assertFalse(desc.configurable); | 83 assertFalse(desc.configurable); |
| 88 assertEquals(42, desc.value); | 84 assertEquals(42, desc.value); |
| 89 | 85 |
| 90 desc = Object.getOwnPropertyDescriptor(obj, 'z'); | 86 desc = Object.getOwnPropertyDescriptor(obj, 'z'); |
| 91 assertTrue(desc.writable); | 87 assertTrue(desc.writable); |
| 92 assertFalse(desc.configurable); | 88 assertFalse(desc.configurable); |
| 93 assertEquals("foobar", desc.value); | 89 assertEquals("foobar", desc.value); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 118 assertTrue(Object.isFrozen(obj2)); | 114 assertTrue(Object.isFrozen(obj2)); |
| 119 assertFalse(Object.isExtensible(obj2)); | 115 assertFalse(Object.isExtensible(obj2)); |
| 120 assertTrue(Object.isSealed(obj2)); | 116 assertTrue(Object.isSealed(obj2)); |
| 121 | 117 |
| 122 desc = Object.getOwnPropertyDescriptor(obj2, 'x'); | 118 desc = Object.getOwnPropertyDescriptor(obj2, 'x'); |
| 123 assertFalse(desc.configurable); | 119 assertFalse(desc.configurable); |
| 124 assertEquals(undefined, desc.value); | 120 assertEquals(undefined, desc.value); |
| 125 assertEquals(set, desc.set); | 121 assertEquals(set, desc.set); |
| 126 assertEquals(get, desc.get); | 122 assertEquals(get, desc.get); |
| 127 | 123 |
| 128 try { | 124 obj2.foo = 42; |
| 129 obj2.foo = 42; | 125 assertEquals(obj2.foo, undefined); |
| 130 assertUnreachable(); | |
| 131 } catch(e) { | |
| 132 assertTrue(/object is not extensible/.test(e)); | |
| 133 } | |
| 134 | |
| 135 | 126 |
| 136 // Test seal on arrays. | 127 // Test seal on arrays. |
| 137 var arr = new Array(42,43); | 128 var arr = new Array(42,43); |
| 138 | 129 |
| 139 desc = Object.getOwnPropertyDescriptor(arr, '0'); | 130 desc = Object.getOwnPropertyDescriptor(arr, '0'); |
| 140 assertTrue(desc.configurable); | 131 assertTrue(desc.configurable); |
| 141 assertTrue(desc.writable); | 132 assertTrue(desc.writable); |
| 142 assertEquals(42, desc.value); | 133 assertEquals(42, desc.value); |
| 143 | 134 |
| 144 desc = Object.getOwnPropertyDescriptor(arr, '1'); | 135 desc = Object.getOwnPropertyDescriptor(arr, '1'); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 var obj4 = {}; | 181 var obj4 = {}; |
| 191 Object.defineProperty(obj4, 'x', {configurable: true, writable: false}); | 182 Object.defineProperty(obj4, 'x', {configurable: true, writable: false}); |
| 192 Object.defineProperty(obj4, 'y', {configurable: false, writable: false}); | 183 Object.defineProperty(obj4, 'y', {configurable: false, writable: false}); |
| 193 Object.preventExtensions(obj4); | 184 Object.preventExtensions(obj4); |
| 194 | 185 |
| 195 assertFalse(Object.isSealed(obj4)); | 186 assertFalse(Object.isSealed(obj4)); |
| 196 | 187 |
| 197 // Make sure that Object.seal returns the sealed object. | 188 // Make sure that Object.seal returns the sealed object. |
| 198 var obj4 = {} | 189 var obj4 = {} |
| 199 assertTrue(obj4 === Object.seal(obj4)) | 190 assertTrue(obj4 === Object.seal(obj4)) |
| OLD | NEW |