| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 assertTrue(Object.isExtensible(obj)); | 64 assertTrue(Object.isExtensible(obj)); |
| 65 assertFalse(Object.isFrozen(obj)); | 65 assertFalse(Object.isFrozen(obj)); |
| 66 | 66 |
| 67 Object.freeze(obj); | 67 Object.freeze(obj); |
| 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.isFrozen(obj)); | 71 assertTrue(Object.isFrozen(obj)); |
| 72 | 72 |
| 73 try { | 73 obj.foo = 42; |
| 74 obj.foo = 42; | 74 assertEquals(obj.foo, undefined); |
| 75 assertUnreachable(); | |
| 76 } catch(e) { | |
| 77 assertTrue(/object is not extensible/.test(e)); | |
| 78 } | |
| 79 | 75 |
| 80 desc = Object.getOwnPropertyDescriptor(obj, 'x'); | 76 desc = Object.getOwnPropertyDescriptor(obj, 'x'); |
| 81 assertFalse(desc.writable); | 77 assertFalse(desc.writable); |
| 82 assertFalse(desc.configurable); | 78 assertFalse(desc.configurable); |
| 83 assertEquals(42, desc.value); | 79 assertEquals(42, desc.value); |
| 84 | 80 |
| 85 desc = Object.getOwnPropertyDescriptor(obj, 'z'); | 81 desc = Object.getOwnPropertyDescriptor(obj, 'z'); |
| 86 assertFalse(desc.writable); | 82 assertFalse(desc.writable); |
| 87 assertFalse(desc.configurable); | 83 assertFalse(desc.configurable); |
| 88 assertEquals("foobar", desc.value); | 84 assertEquals("foobar", desc.value); |
| 89 | 85 |
| 90 // Make sure that even if we try overwrite a value that is not writable, it is | 86 // Make sure that even if we try overwrite a value that is not writable, it is |
| 91 // not changed. | 87 // not changed. |
| 92 obj.x = "tete"; | 88 obj.x = "tete"; |
| 93 assertEquals(42, obj.x); | 89 assertEquals(42, obj.x); |
| 94 obj.x = { get: function() {return 43}, set: function() {} }; | 90 obj.x = { get: function() {return 43}, set: function() {} }; |
| 95 assertEquals(42, obj.x); | 91 assertEquals(42, obj.x); |
| 96 | 92 |
| 97 // Test on accessors. | 93 // Test on accessors. |
| 98 var obj2 = {}; | 94 var obj2 = {}; |
| 99 function get() { return 43; }; | 95 function get() { return 43; }; |
| 100 function set() {}; | 96 function set() {}; |
| 101 Object.defineProperty(obj2, 'x', { get: get, set: set, configurable: true }); | 97 Object.defineProperty(obj2, 'x', { get: get, set: set, configurable: true }); |
| 102 | 98 |
| 103 desc = Object.getOwnPropertyDescriptor(obj2, 'x'); | 99 desc = Object.getOwnPropertyDescriptor(obj2, 'x'); |
| 104 assertTrue(desc.configurable); | 100 assertTrue(desc.configurable); |
| 105 assertEquals(undefined, desc.value); | 101 assertEquals(undefined, desc.value); |
| 106 assertEquals(set, desc.set); | 102 assertEquals(set, desc.set); |
| 107 assertEquals(get, desc.get); | 103 assertEquals(get, desc.get); |
| 108 | 104 |
| 109 assertTrue(Object.isExtensible(obj2)); | 105 assertTrue(Object.isExtensible(obj2)); |
| 110 assertFalse(Object.isFrozen(obj2)); | 106 assertFalse(Object.isFrozen(obj2)); |
| 111 Object.freeze(obj2); | 107 Object.freeze(obj2); |
| 112 assertTrue(Object.isFrozen(obj2)); | 108 assertTrue(Object.isFrozen(obj2)); |
| 113 assertFalse(Object.isExtensible(obj2)); | 109 assertFalse(Object.isExtensible(obj2)); |
| 114 | 110 |
| 115 desc = Object.getOwnPropertyDescriptor(obj2, 'x'); | 111 desc = Object.getOwnPropertyDescriptor(obj2, 'x'); |
| 116 assertFalse(desc.configurable); | 112 assertFalse(desc.configurable); |
| 117 assertEquals(undefined, desc.value); | 113 assertEquals(undefined, desc.value); |
| 118 assertEquals(set, desc.set); | 114 assertEquals(set, desc.set); |
| 119 assertEquals(get, desc.get); | 115 assertEquals(get, desc.get); |
| 120 | 116 |
| 121 try { | 117 obj2.foo = 42; |
| 122 obj2.foo = 42; | 118 assertEquals(obj2.foo, undefined); |
| 123 assertUnreachable(); | |
| 124 } catch(e) { | |
| 125 assertTrue(/object is not extensible/.test(e)); | |
| 126 } | |
| 127 | 119 |
| 128 | 120 |
| 129 // Test freeze on arrays. | 121 // Test freeze on arrays. |
| 130 var arr = new Array(42,43); | 122 var arr = new Array(42,43); |
| 131 | 123 |
| 132 desc = Object.getOwnPropertyDescriptor(arr, '0'); | 124 desc = Object.getOwnPropertyDescriptor(arr, '0'); |
| 133 assertTrue(desc.configurable); | 125 assertTrue(desc.configurable); |
| 134 assertTrue(desc.writable); | 126 assertTrue(desc.writable); |
| 135 assertEquals(42, desc.value); | 127 assertEquals(42, desc.value); |
| 136 | 128 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 var obj5 = {}; | 180 var obj5 = {}; |
| 189 Object.defineProperty(obj5, 'x', {configurable: true, writable: false}); | 181 Object.defineProperty(obj5, 'x', {configurable: true, writable: false}); |
| 190 Object.defineProperty(obj5, 'y', {configurable: false, writable: false}); | 182 Object.defineProperty(obj5, 'y', {configurable: false, writable: false}); |
| 191 Object.preventExtensions(obj5); | 183 Object.preventExtensions(obj5); |
| 192 | 184 |
| 193 assertFalse(Object.isFrozen(obj5)); | 185 assertFalse(Object.isFrozen(obj5)); |
| 194 | 186 |
| 195 // Make sure that Object.freeze returns the frozen object. | 187 // Make sure that Object.freeze returns the frozen object. |
| 196 var obj6 = {} | 188 var obj6 = {} |
| 197 assertTrue(obj6 === Object.freeze(obj6)) | 189 assertTrue(obj6 === Object.freeze(obj6)) |
| OLD | NEW |