Home | History | Annotate | Download | only in regress
      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 
     32 var READ_ONLY   = 1;
     33 var DONT_ENUM   = 2;
     34 var DONT_DELETE = 4;
     35 
     36 function func1(){}
     37 function func2(){}
     38 
     39 var object = {__proto__:{}};
     40 %SetProperty(object, "foo", func1, DONT_ENUM | DONT_DELETE);
     41 %SetProperty(object, "bar", func1, DONT_ENUM | READ_ONLY);
     42 %SetProperty(object, "baz", func1, DONT_DELETE | READ_ONLY);
     43 %SetProperty(object.__proto__, "bif", func1, DONT_ENUM | DONT_DELETE | READ_ONLY);
     44 object.bif = func2;
     45 
     46 function 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.
     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");
     63 
     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");
     68 
     69 // Assignment to non-readonly. Assignment shouldn't change attributes!
     70 object.foo = func2;
     71 assertArrayEquals(["baz", "bif"], enumerable(object), "enum2");
     72 assertFalse(delete object.foo, "delete foo 2");
     73 
     74 // Delete should erase attributes if value set again.
     75 assertTrue(delete object.bar, "delete bar");
     76 assertFalse("bar" in object, "has bar");
     77 object.bar = func2;
     78 assertTrue("bar" in object, "has bar 2");
     79 assertEquals(func2, object.bar, "read bar 3");
     80 
     81 assertArrayEquals(["bar", "baz", "bif"], enumerable(object), "enum3");
     82 
     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");
     91