sundar@344: /* sundar@344: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. sundar@344: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@962: * sundar@344: * This code is free software; you can redistribute it and/or modify it sundar@344: * under the terms of the GNU General Public License version 2 only, as sundar@344: * published by the Free Software Foundation. attila@962: * sundar@344: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@344: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@344: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@344: * version 2 for more details (a copy is included in the LICENSE file that sundar@344: * accompanied this code). attila@962: * sundar@344: * You should have received a copy of the GNU General Public License version sundar@344: * 2 along with this work; if not, write to the Free Software Foundation, sundar@344: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@962: * sundar@344: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@344: * or visit www.oracle.com if you need additional information or have any sundar@344: * questions. sundar@344: */ sundar@344: sundar@344: /** sundar@344: * JDK-8015355: Array.prototype functions don't honour non-writable length and / or index properties attila@962: * sundar@344: * @test sundar@344: * @run sundar@344: */ sundar@344: sundar@344: function check(callback) { sundar@344: try { sundar@344: callback(); sundar@344: fail("TypeError expected for " + callback); sundar@344: } catch (e) { sundar@344: if (! (e instanceof TypeError)) { sundar@344: fail("TypeError expected, got " + e); sundar@344: } sundar@344: } sundar@344: } sundar@344: sundar@344: var array = Object.defineProperty([],"length", { writable: false }); sundar@344: sundar@344: check(function() { sundar@344: array.push(0) sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: array.pop() sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Object.defineProperty([,,],"0",{ writable: false }).reverse(); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: array.shift() sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: array.splice(0) sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: array.unshift() sundar@344: }); sundar@344: sundar@344: // try the above via call sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.push.call(array, 0); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.pop.call(array); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.shift.call(array); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.unshift.call(array); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.splice.call(array, 0); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.reverse.call(Object.defineProperty([,,],"0",{ writable: false })); sundar@344: }); sundar@344: sundar@344: // try the above via apply sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.push.apply(array, [ 0 ]); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.pop.apply(array); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.shift.apply(array); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.unshift.apply(array); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.splice.apply(array, [ 0 ]); sundar@344: }); sundar@344: sundar@344: check(function() { sundar@344: Array.prototype.reverse.apply(Object.defineProperty([,,],"0",{ writable: false })); sundar@344: });