Home | History | Annotate | Download | only in mjsunit
      1 // Copyright 2015 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 function f(a, b, c, d) { return arguments; }
      6 
      7 // Ensure non-configurable argument elements stay non-configurable.
      8 (function () {
      9   var args = f(1);
     10   Object.defineProperty(args, "0", {value: 10, configurable: false});
     11   assertFalse(Object.getOwnPropertyDescriptor(args, "0").configurable);
     12   for (var i = 0; i < 10; i++) {
     13     args[i] = 1;
     14   }
     15   assertFalse(Object.getOwnPropertyDescriptor(args, "0").configurable);
     16 })();
     17 
     18 // Ensure read-only properties on the prototype chain cause TypeError.
     19 
     20 // Newly added.
     21 (function () {
     22   var o = [];
     23   var proto = {};
     24   var index = 3;
     25   function store(o, i, v) { "use strict"; o[i] = v; };
     26   o.__proto__ = proto;
     27   for (var i = 0; i < index; i++) {
     28     store(o, i, 0);
     29   }
     30   Object.defineProperty(proto, index, {value: 100, writable: false});
     31   assertThrows(function() { store(o, index, 0); });
     32   assertEquals(100, o[index]);
     33 })();
     34 
     35 // Reconfigured.
     36 (function () {
     37   var o = [];
     38   var proto = {3: 10000};
     39   var index = 3;
     40   function store(o, i, v) { "use strict"; o[i] = v; };
     41   o.__proto__ = proto;
     42   for (var i = 0; i < index; i++) {
     43     store(o, i, 0);
     44   }
     45   Object.defineProperty(proto, index, {value: 100, writable: false});
     46   assertThrows(function() { store(o, index, 0); });
     47   assertEquals(100, o[index]);
     48 })();
     49 
     50 // Newly added to arguments object.
     51 (function () {
     52   var o = [];
     53   var proto = f(100);
     54   var index = 3;
     55   function store(o, i, v) { "use strict"; o[i] = v; };
     56   o.__proto__ = proto;
     57   for (var i = 0; i < index; i++) {
     58     store(o, i, 0);
     59   }
     60   Object.defineProperty(proto, index, {value: 100, writable: false});
     61   assertThrows(function() { store(o, index, 0); });
     62   assertEquals(100, o[index]);
     63 })();
     64 
     65 // Reconfigured on to arguments object.
     66 (function () {
     67   var o = [];
     68   var proto = f(100, 200, 300, 400);
     69   var index = 3;
     70   function store(o, i, v) { "use strict"; o[i] = v; };
     71   o.__proto__ = proto;
     72   for (var i = 0; i < index; i++) {
     73     store(o, i, 0);
     74   }
     75   Object.defineProperty(proto, index, {value: 100, writable: false});
     76   assertThrows(function() { store(o, index, 0); });
     77   assertEquals(100, o[index]);
     78 })();
     79 
     80 // Extensions prevented object.
     81 (function () {
     82   var o = [];
     83   var proto = [0, 1, 2, 3];
     84   var index = 3;
     85   function store(o, i, v) { "use strict"; o[i] = v; };
     86   o.__proto__ = proto;
     87   for (var i = 0; i < index; i++) {
     88     store(o, i, 0);
     89   }
     90   Object.preventExtensions(proto);
     91   Object.defineProperty(proto, index, {value: 100, writable: false});
     92   assertThrows(function() { store(o, index, 0); });
     93   assertEquals(100, o[index]);
     94 })();
     95 
     96 // Extensions prevented arguments object.
     97 (function () {
     98   var o = [];
     99   var proto = f(100, 200, 300, 400);
    100   var index = 3;
    101   function store(o, i, v) { "use strict"; o[i] = v; };
    102   o.__proto__ = proto;
    103   for (var i = 0; i < index; i++) {
    104     store(o, i, 0);
    105   }
    106   Object.preventExtensions(proto);
    107   Object.defineProperty(proto, index, {value: 100, writable: false});
    108   assertThrows(function() { store(o, index, 0); });
    109   assertEquals(100, o[index]);
    110 })();
    111 
    112 // Array with large index.
    113 (function () {
    114   var o = [];
    115   var proto = [];
    116   var index = 3;
    117   function store(o, i, v) { "use strict"; o[i] = v; };
    118   o.__proto__ = proto;
    119   for (var i = 0; i < index; i++) {
    120     store(o, i, 0);
    121   }
    122   proto[1 << 30] = 1;
    123   Object.defineProperty(proto, index, {value: 100, writable: false});
    124   assertThrows(function() { store(o, index, 0); });
    125   assertEquals(100, o[index]);
    126 })();
    127 
    128 // Frozen object.
    129 (function () {
    130   var o = [];
    131   var proto = [0, 1, 2, 3];
    132   function store(o, i, v) { "use strict"; o[i] = v; };
    133   o.__proto__ = proto;
    134   for (var i = 0; i < 3; i++) {
    135     store(o, i, 0);
    136   }
    137   Object.freeze(proto);
    138   assertThrows(function() { store(o, 3, 0); });
    139   assertEquals(3, o[3]);
    140 })();
    141 
    142 // Frozen arguments object.
    143 (function () {
    144   var o = [];
    145   var proto = f(0, 1, 2, 3);
    146   function store(o, i, v) { "use strict"; o[i] = v; };
    147   o.__proto__ = proto;
    148   for (var i = 0; i < 3; i++) {
    149     store(o, i, 0);
    150   }
    151   Object.freeze(proto);
    152   assertThrows(function() { store(o, 3, 0); });
    153   assertEquals(3, o[3]);
    154 })();
    155