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 28a = [1]; 29Object.defineProperty(a, "1", {writable:false, configurable:false, value: 100}); 30assertThrows("a.unshift(4);", TypeError); 31assertEquals([1, 100, 100], a); 32var desc = Object.getOwnPropertyDescriptor(a, "1"); 33assertEquals(false, desc.writable); 34assertEquals(false, desc.configurable); 35 36a = [1]; 37var g = function() { return 100; }; 38Object.defineProperty(a, "1", {get:g}); 39assertThrows("a.unshift(0);", TypeError); 40assertEquals([1, 100, 100], a); 41desc = Object.getOwnPropertyDescriptor(a, "1"); 42assertEquals(false, desc.configurable); 43assertEquals(g, desc.get); 44 45a = [1]; 46var c = 0; 47var s = function(v) { c += 1; }; 48Object.defineProperty(a, "1", {set:s}); 49a.unshift(10); 50assertEquals([10, undefined, undefined], a); 51assertEquals(1, c); 52desc = Object.getOwnPropertyDescriptor(a, "1"); 53assertEquals(false, desc.configurable); 54assertEquals(s, desc.set); 55 56a = [1]; 57Object.defineProperty(a, "1", {configurable:false, value:10}); 58assertThrows("a.splice(1,1);", TypeError); 59assertEquals([1, 10], a); 60desc = Object.getOwnPropertyDescriptor(a, "1"); 61assertEquals(false, desc.configurable); 62 63a = [0,1,2,3,4,5,6]; 64Object.defineProperty(a, "3", {configurable:false, writable:false, value:3}); 65assertThrows("a.splice(1,4);", TypeError); 66assertEquals([0,5,6,3,,,,], a); 67desc = Object.getOwnPropertyDescriptor(a, "3"); 68assertEquals(false, desc.configurable); 69assertEquals(false, desc.writable); 70 71a = [0,1,2,3,4,5,6]; 72Object.defineProperty(a, "5", {configurable:false, value:5}); 73assertThrows("a.splice(1,4);", TypeError); 74assertEquals([0,5,6,3,4,5,,], a); 75desc = Object.getOwnPropertyDescriptor(a, "5"); 76assertEquals(false, desc.configurable); 77 78a = [1,2,3,,5]; 79Object.defineProperty(a, "1", {configurable:false, writable:true, value:2}); 80assertEquals(1, a.shift()); 81assertEquals([2,3,,5], a); 82desc = Object.getOwnPropertyDescriptor(a, "1"); 83assertEquals(false, desc.configurable); 84assertEquals(true, desc.writable); 85assertThrows("a.shift();", TypeError); 86assertEquals([3,3,,5], a); 87desc = Object.getOwnPropertyDescriptor(a, "1"); 88assertEquals(false, desc.configurable); 89assertEquals(true, desc.writable); 90 91a = [1,2,3]; 92Object.defineProperty(a, "2", {configurable:false, value:3}); 93assertThrows("a.pop();", TypeError); 94assertEquals([1,2,3], a); 95desc = Object.getOwnPropertyDescriptor(a, "2"); 96assertEquals(false, desc.configurable); 97