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
31var obj = { get value() {}, set value (v) { throw "Error";} };
32assertDoesNotThrow(
33    Object.defineProperty(obj, "value",
34                          { value: 5, writable:true, configurable: true }));
35var desc = Object.getOwnPropertyDescriptor(obj, "value");
36assertEquals(obj.value, 5);
37assertTrue(desc.configurable);
38assertTrue(desc.enumerable);
39assertTrue(desc.writable);
40assertEquals(desc.get, undefined);
41assertEquals(desc.set, undefined);
42
43
44var proto = {
45  get value() {},
46  set value(v) { Object.defineProperty(this, "value", {value: v}); }
47};
48
49var create = Object.create(proto);
50
51assertEquals(create.value, undefined);
52assertDoesNotThrow(create.value = 4);
53assertEquals(create.value, 4);
54
55// These tests where provided in bug 959, but are all related to the this issue.
56var obj1 = {};
57Object.defineProperty(obj1, 'p', {get: undefined, set: undefined});
58assertTrue("p" in obj1);
59desc = Object.getOwnPropertyDescriptor(obj1, "p");
60assertFalse(desc.configurable);
61assertFalse(desc.enumerable);
62assertEquals(desc.value, undefined);
63assertEquals(desc.get, undefined);
64assertEquals(desc.set, undefined);
65
66
67var obj2 = { get p() {}};
68Object.defineProperty(obj2, 'p', {get: undefined})
69assertTrue("p" in obj2);
70desc = Object.getOwnPropertyDescriptor(obj2, "p");
71assertTrue(desc.configurable);
72assertTrue(desc.enumerable);
73assertEquals(desc.value, undefined);
74assertEquals(desc.get, undefined);
75assertEquals(desc.set, undefined);
76