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 = { |
| 45 get value() {}, |
| 46 set value(v) { Object.defineProperty(this, "value", {value: v}); } |
| 47 }; |
| 48 |
| 49 var create = Object.create(proto); |
| 50 |
| 51 assertEquals(create.value, undefined); |
| 52 assertDoesNotThrow(create.value = 4); |
| 53 assertEquals(create.value, 4); |
| 54 |
| 55 // These tests where provided in bug 959, but are all related to the this issue. |
| 56 var obj1 = {}; |
| 57 Object.defineProperty(obj1, 'p', {get: undefined, set: undefined}); |
| 58 assertTrue("p" in obj1); |
| 59 desc = Object.getOwnPropertyDescriptor(obj1, "p"); |
| 60 assertFalse(desc.configurable); |
| 61 assertFalse(desc.enumerable); |
| 62 assertEquals(desc.value, undefined); |
| 63 assertEquals(desc.get, undefined); |
| 64 assertEquals(desc.set, undefined); |
| 65 |
| 66 |
| 67 var obj2 = { get p() {}}; |
| 68 Object.defineProperty(obj2, 'p', {get: undefined}) |
| 69 assertTrue("p" in obj2); |
| 70 desc = Object.getOwnPropertyDescriptor(obj2, "p"); |
| 71 assertTrue(desc.configurable); |
| 72 assertTrue(desc.enumerable); |
| 73 assertEquals(desc.value, undefined); |
| 74 assertEquals(desc.get, undefined); |
| 75 assertEquals(desc.set, undefined); |
OLD | NEW |