1 // Copyright 2008 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
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.
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.
28 // Flags: --allow-natives-syntax
30 // Test for http://code.google.com/p/v8/issues/detail?id=334
39 var object = {__proto__:{}};
40 %AddNamedProperty(object, "foo", func1, DONT_ENUM | DONT_DELETE);
41 %AddNamedProperty(object, "bar", func1, DONT_ENUM | READ_ONLY);
42 %AddNamedProperty(object, "baz", func1, DONT_DELETE | READ_ONLY);
43 %AddNamedProperty(object.__proto__, "bif", func1, DONT_ENUM | DONT_DELETE);
46 function enumerable(obj) {
55 // Sanity check: expected initial state.
56 assertArrayEquals(["baz", "bif"], enumerable(object), "enum0");
57 assertFalse(delete object.foo, "delete foo");
58 assertFalse(delete object.baz, "delete baz");
59 assertEquals(func1, object.foo, "read foo");
60 assertEquals(func1, object.bar, "read bar");
61 assertEquals(func1, object.baz, "read baz");
62 assertEquals(func2, object.bif, "read bif");
64 // Can't assign to READ_ONLY.
65 object.bar = "NO WAY";
66 assertEquals(func1, object.bar, "read bar 2");
67 assertArrayEquals(["baz", "bif"], enumerable(object), "enum1");
69 // Assignment to non-readonly. Assignment shouldn't change attributes!
71 assertArrayEquals(["baz", "bif"], enumerable(object), "enum2");
72 assertFalse(delete object.foo, "delete foo 2");
74 // Delete should erase attributes if value set again.
75 assertTrue(delete object.bar, "delete bar");
76 assertFalse("bar" in object, "has bar");
78 assertTrue("bar" in object, "has bar 2");
79 assertEquals(func2, object.bar, "read bar 3");
81 assertArrayEquals(["bar", "baz", "bif"], enumerable(object), "enum3");
83 // Unshadowing a prototype property exposes its attributes.
84 assertTrue(delete object.bif, "delete bif");
85 assertArrayEquals(["bar", "baz"], enumerable(object), "enum4");
86 assertEquals(func1, object.bif, "read bif 2");
87 // Can't delete prototype property.
88 assertTrue(delete object.bif, "delete bif 2");
89 assertArrayEquals(["bar", "baz"], enumerable(object), "enum5");
90 assertEquals(func1, object.bif, "read bif3");