Home | History | Annotate | Download | only in bugs
      1 // Copyright 2013 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 var a = [];
     29 a[0xfffffffe] = 10;
     30 assertThrows("a.unshift(1);", RangeError);
     31 assertEquals(0xffffffff, a.length);
     32 assertEquals(10, a[0xffffffff]);
     33 assertEquals(undefined, a[0xfffffffe]);
     34 
     35 a = [1,2,3];
     36 a[0xfffffffe] = 10;
     37 assertThrows("a.splice(1,1,7,7,7,7,7);", RangeError);
     38 assertEquals([1,7,7,7,7,7,3], a.slice(0, 7));
     39 assertEquals(0xffffffff, a.length);
     40 assertEquals(10, a[0xfffffffe + 5 - 1]);
     41 
     42 a = [1];
     43 Object.defineProperty(a, "1", {writable:false, configurable:false, value: 100});
     44 assertThrows("a.unshift(4);", TypeError);
     45 assertEquals([1, 100, 100], a);
     46 var desc = Object.getOwnPropertyDescriptor(a, "1");
     47 assertEquals(false, desc.writable);
     48 assertEquals(false, desc.configurable);
     49 
     50 a = [1];
     51 var g = function() { return 100; };
     52 Object.defineProperty(a, "1", {get:g});
     53 assertThrows("a.unshift(0);", TypeError);
     54 assertEquals([1, 100, 100], a);
     55 desc = Object.getOwnPropertyDescriptor(a, "1");
     56 assertEquals(false, desc.configurable);
     57 assertEquals(g, desc.get);
     58 
     59 a = [1];
     60 var c = 0;
     61 var s = function(v) { c += 1; };
     62 Object.defineProperty(a, "1", {set:s});
     63 a.unshift(10);
     64 assertEquals([10, undefined, undefined], a);
     65 assertEquals(1, c);
     66 desc = Object.getOwnPropertyDescriptor(a, "1");
     67 assertEquals(false, desc.configurable);
     68 assertEquals(s, desc.set);
     69 
     70 a = [1];
     71 Object.defineProperty(a, "1", {configurable:false, value:10});
     72 assertThrows("a.splice(1,1);", TypeError);
     73 assertEquals([1, 10], a);
     74 desc = Object.getOwnPropertyDescriptor(a, "1");
     75 assertEquals(false, desc.configurable);
     76 
     77 a = [0,1,2,3,4,5,6];
     78 Object.defineProperty(a, "3", {configurable:false, writable:false, value:3});
     79 assertThrows("a.splice(1,4);", TypeError);
     80 assertEquals([0,5,6,3,,,,,], a);
     81 desc = Object.getOwnPropertyDescriptor(a, "3");
     82 assertEquals(false, desc.configurable);
     83 assertEquals(false, desc.writable);
     84 
     85 a = [0,1,2,3,4,5,6];
     86 Object.defineProperty(a, "5", {configurable:false, value:5});
     87 assertThrows("a.splice(1,4);", TypeError);
     88 assertEquals([0,5,6,3,4,5,,,], a);
     89 desc = Object.getOwnPropertyDescriptor(a, "5");
     90 assertEquals(false, desc.configurable);
     91 
     92 a = [1,2,3,,5];
     93 Object.defineProperty(a, "1", {configurable:false, writable:true, value:2});
     94 assertEquals(1, a.shift());
     95 assertEquals([2,3,,5], a);
     96 desc = Object.getOwnPropertyDescriptor(a, "1");
     97 assertEquals(false, desc.configurable);
     98 assertEquals(true, desc.writable);
     99 assertThrows("a.shift();", TypeError);
    100 assertEquals([3,3,,5], a);
    101 desc = Object.getOwnPropertyDescriptor(a, "1");
    102 assertEquals(false, desc.configurable);
    103 assertEquals(true, desc.writable);
    104 
    105 a = [1,2,3];
    106 Object.defineProperty(a, "2", {configurable:false, value:3});
    107 assertThrows("a.pop();", TypeError);
    108 assertEquals([1,2,3], a);
    109 desc = Object.getOwnPropertyDescriptor(a, "2");
    110 assertEquals(false, desc.configurable);
    111 
    112 a = [1,2,,,5];
    113 Object.defineProperty(a, "4", {writable:true, configurable:false, value:5});
    114 assertThrows("a.sort();", TypeError);
    115 assertEquals([1,2,5,,5], a);
    116 desc = Object.getOwnPropertyDescriptor(a, "2");
    117 assertEquals(true, desc.configurable);
    118 desc = Object.getOwnPropertyDescriptor(a, "4");
    119 assertEquals(false, desc.configurable);
    120 
    121 a = [1,2,3,,5,6];
    122 Object.defineProperty(a, "4", {value:5, writable:false});
    123 assertThrows("a.sort();", TypeError);
    124 assertEquals([1,2,3,5,5,6], a);
    125 desc = Object.getOwnPropertyDescriptor(a, "4");
    126 assertEquals(false, desc.writable);
    127