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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 obj1.foobar = 1001; | 282 obj1.foobar = 1001; |
283 assertEquals(obj1.foobar, 1001); | 283 assertEquals(obj1.foobar, 1001); |
284 | 284 |
285 | 285 |
286 // Redefine with non configurable data property. | 286 // Redefine with non configurable data property. |
287 Object.defineProperty(obj1, "foobar", dataNoConfigurable); | 287 Object.defineProperty(obj1, "foobar", dataNoConfigurable); |
288 desc = Object.getOwnPropertyDescriptor(obj1, "foobar"); | 288 desc = Object.getOwnPropertyDescriptor(obj1, "foobar"); |
289 assertEquals(obj1.foobar, 2000); | 289 assertEquals(obj1.foobar, 2000); |
290 assertEquals(desc.value, 2000); | 290 assertEquals(desc.value, 2000); |
291 assertFalse(desc.configurable); | 291 assertFalse(desc.configurable); |
292 assertFalse(desc.writable); | 292 assertTrue(desc.writable); |
293 assertFalse(desc.enumerable); | 293 assertFalse(desc.enumerable); |
294 assertEquals(desc.get, undefined); | 294 assertEquals(desc.get, undefined); |
295 assertEquals(desc.set, undefined); | 295 assertEquals(desc.set, undefined); |
296 | 296 |
297 // Try redefine again - shold fail because configurable is now false. | 297 // Try redefine again - shold fail because configurable is now false. |
298 try { | 298 try { |
299 Object.defineProperty(obj1, "foobar", dataConfigurable); | 299 Object.defineProperty(obj1, "foobar", dataConfigurable); |
300 assertTrue(false); | 300 assertTrue(false); |
301 } catch (e) { | 301 } catch (e) { |
302 assertTrue(/Cannot redefine property/.test(e)); | 302 assertTrue(/Cannot redefine property/.test(e)); |
303 } | 303 } |
304 | 304 |
305 // Try redefine again with accessor property - shold also fail. | 305 // Try redefine again with accessor property - shold also fail. |
306 try { | 306 try { |
307 Object.defineProperty(obj1, "foobar", dataConfigurable); | 307 Object.defineProperty(obj1, "foobar", dataConfigurable); |
308 assertTrue(false); | 308 assertTrue(false); |
309 } catch (e) { | 309 } catch (e) { |
310 assertTrue(/Cannot redefine property/.test(e)); | 310 assertTrue(/Cannot redefine property/.test(e)); |
311 } | 311 } |
312 | 312 |
313 | 313 |
314 // Redifine with the same descriptor - should succeed (step 6). | 314 // Redifine with the same descriptor - should succeed (step 6). |
315 Object.defineProperty(obj1, "foobar", dataNoConfigurable); | 315 Object.defineProperty(obj1, "foobar", dataNoConfigurable); |
316 desc = Object.getOwnPropertyDescriptor(obj1, "foobar"); | 316 desc = Object.getOwnPropertyDescriptor(obj1, "foobar"); |
317 assertEquals(obj1.foobar, 2000); | 317 assertEquals(obj1.foobar, 2000); |
318 assertEquals(desc.value, 2000); | 318 assertEquals(desc.value, 2000); |
319 assertFalse(desc.configurable); | 319 assertFalse(desc.configurable); |
320 assertFalse(desc.writable); | 320 assertTrue(desc.writable); |
321 assertFalse(desc.enumerable); | 321 assertFalse(desc.enumerable); |
322 assertEquals(desc.get, undefined); | 322 assertEquals(desc.get, undefined); |
323 assertEquals(desc.set, undefined); | 323 assertEquals(desc.set, undefined); |
324 | 324 |
325 | 325 |
326 // New object | 326 // New object |
327 var obj2 = {}; | 327 var obj2 = {}; |
328 | 328 |
329 // Make accessor - redefine to data | 329 // Make accessor - redefine to data |
330 Object.defineProperty(obj2, "foo", accessorConfigurable); | 330 Object.defineProperty(obj2, "foo", accessorConfigurable); |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 707 |
708 // Make sure we can redefine with +0. | 708 // Make sure we can redefine with +0. |
709 Object.defineProperty(obj5, 'pluszero', descPlusZero); | 709 Object.defineProperty(obj5, 'pluszero', descPlusZero); |
710 | 710 |
711 try { | 711 try { |
712 Object.defineProperty(obj5, 'pluszero', descMinusZero); | 712 Object.defineProperty(obj5, 'pluszero', descMinusZero); |
713 assertUnreachable(); | 713 assertUnreachable(); |
714 } catch (e) { | 714 } catch (e) { |
715 assertTrue(/Cannot redefine property/.test(e)); | 715 assertTrue(/Cannot redefine property/.test(e)); |
716 } | 716 } |
OLD | NEW |