Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 27 | |
| 28 // This regression includes a number of cases where we did not correctly | |
| 29 // update a accessor property to a data property using Object.defineProperty. | |
| 30 | |
| 31 var obj = { get value() {}, set value (v) { throw "Error";} }; | |
| 32 assertDoesNotThrow( | |
| 33 Object.defineProperty(obj, "value", | |
| 34 { value: 5, writable:true, configurable: true })); | |
| 35 var desc = Object.getOwnPropertyDescriptor(obj, "value"); | |
| 36 assertEquals(obj.value, 5); | |
| 37 assertTrue(desc.configurable); | |
| 38 assertTrue(desc.enumerable); | |
| 39 assertTrue(desc.writable); | |
| 40 assertEquals(desc.get, undefined); | |
| 41 assertEquals(desc.set, undefined); | |
| 42 | |
| 43 | |
| 44 var proto = {get value() {}, | |
| 45 set value(v) { Object.defineProperty(this, "value", {value: v}); }}; | |
|
Lasse Reichstein
2010/12/16 09:43:34
Indentation.
Rico
2010/12/16 12:17:55
Done.
| |
| 46 | |
| 47 var create = Object.create(proto); | |
| 48 | |
| 49 assertEquals(create.value, undefined); | |
| 50 assertDoesNotThrow(create.value = 4); | |
| 51 assertEquals(create.value, 4); | |
| 52 | |
| 53 // These tests where provided in bug 959, but are all related to the this issue. | |
| 54 var obj1 = {}; | |
| 55 Object.defineProperty(obj1, 'p', {get: undefined, set: undefined}); | |
| 56 assertTrue("p" in obj1); | |
| 57 desc = Object.getOwnPropertyDescriptor(obj1, "p"); | |
| 58 assertFalse(desc.configurable); | |
| 59 assertFalse(desc.enumerable); | |
| 60 assertEquals(desc.value, undefined); | |
| 61 assertEquals(desc.get, undefined); | |
| 62 assertEquals(desc.set, undefined); | |
| 63 | |
| 64 | |
| 65 var obj2 = { get p() {}}; | |
| 66 Object.defineProperty(obj2, 'p', {get: undefined}) | |
| 67 assertTrue("p" in obj2); | |
| 68 desc = Object.getOwnPropertyDescriptor(obj2, "p"); | |
| 69 assertTrue(desc.configurable); | |
| 70 assertTrue(desc.enumerable); | |
| 71 assertEquals(desc.value, undefined); | |
| 72 assertEquals(desc.get, undefined); | |
| 73 assertEquals(desc.set, undefined); | |
| 74 | |
| 75 | |
|
Rico
2010/12/16 12:17:55
Removed the rest of this test file, the stuff belo
| |
| 76 var obj3 = { get p() {return 42;}}; | |
| 77 print(obj3.p); | |
| 78 Object.defineProperty(obj3, 'p', {enumerable: false }) | |
| 79 print(obj3.p); | |
| 80 desc = Object.getOwnPropertyDescriptor(obj3, "p"); | |
| 81 assertTrue(desc.configurable); | |
| 82 assertFalse(desc.enumerable); | |
| 83 assertEquals(desc.value, undefined); | |
| 84 assertFalse(desc.get == undefined); | |
| 85 assertEquals(desc.set, undefined); | |
| OLD | NEW |