• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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// Flags: --allow-natives-syntax
29
30// Test for http://code.google.com/p/v8/issues/detail?id=334
31
32var READ_ONLY   = 1;
33var DONT_ENUM   = 2;
34var DONT_DELETE = 4;
35
36function func1(){}
37function func2(){}
38
39var 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);
44object.bif = func2;
45
46function enumerable(obj) {
47  var res = [];
48  for (var i in obj) {
49    res.push(i);
50  }
51  res.sort();
52  return res;
53}
54
55// Sanity check: expected initial state.
56assertArrayEquals(["baz", "bif"], enumerable(object), "enum0");
57assertFalse(delete object.foo, "delete foo");
58assertFalse(delete object.baz, "delete baz");
59assertEquals(func1, object.foo, "read foo");
60assertEquals(func1, object.bar, "read bar");
61assertEquals(func1, object.baz, "read baz");
62assertEquals(func2, object.bif, "read bif");
63
64// Can't assign to READ_ONLY.
65object.bar = "NO WAY";
66assertEquals(func1, object.bar, "read bar 2");
67assertArrayEquals(["baz", "bif"], enumerable(object), "enum1");
68
69// Assignment to non-readonly. Assignment shouldn't change attributes!
70object.foo = func2;
71assertArrayEquals(["baz", "bif"], enumerable(object), "enum2");
72assertFalse(delete object.foo, "delete foo 2");
73
74// Delete should erase attributes if value set again.
75assertTrue(delete object.bar, "delete bar");
76assertFalse("bar" in object, "has bar");
77object.bar = func2;
78assertTrue("bar" in object, "has bar 2");
79assertEquals(func2, object.bar, "read bar 3");
80
81assertArrayEquals(["bar", "baz", "bif"], enumerable(object), "enum3");
82
83// Unshadowing a prototype property exposes its attributes.
84assertTrue(delete object.bif, "delete bif");
85assertArrayEquals(["bar", "baz"], enumerable(object), "enum4");
86assertEquals(func1, object.bif, "read bif 2");
87// Can't delete prototype property.
88assertTrue(delete object.bif, "delete bif 2");
89assertArrayEquals(["bar", "baz"], enumerable(object), "enum5");
90assertEquals(func1, object.bif, "read bif3");
91