nashorn/test/script/basic/JDK-8015355.js
author psandoz
Tue, 13 Aug 2013 11:16:37 +0200
changeset 19424 c4524285927f
parent 18328 ebd24057f163
child 21685 ff0187bbe5c0
permissions -rw-r--r--
8022797: Clarify spliterator characteristics for collections containing no elements Reviewed-by: alanb, mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18328
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     1
/*
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     4
 * 
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     8
 * 
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    13
 * accompanied this code).
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    14
 * 
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    18
 * 
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    21
 * questions.
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    22
 */
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    23
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    24
/**
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    25
 * JDK-8015355: Array.prototype functions don't honour non-writable length and / or index properties
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    26
 * 
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    27
 * @test
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    28
 * @run
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    29
 */
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    30
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    31
function fail(msg) {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    32
    print(msg);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    33
}
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    34
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    35
function check(callback) {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    36
    try {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    37
        callback();
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    38
        fail("TypeError expected for " + callback);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    39
    } catch (e) {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    40
        if (! (e instanceof TypeError)) {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    41
            fail("TypeError expected, got " + e);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    42
        }
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    43
    }
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    44
}
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    45
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    46
var array = Object.defineProperty([],"length", { writable: false });
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    47
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    48
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    49
    array.push(0)
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    50
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    51
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    52
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    53
    array.pop()
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    54
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    55
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    56
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    57
    Object.defineProperty([,,],"0",{ writable: false }).reverse();
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    58
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    59
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    60
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    61
    array.shift()
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    62
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    63
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    64
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    65
    array.splice(0)
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    66
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    67
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    68
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    69
    array.unshift()
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    70
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    71
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    72
// try the above via call
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    73
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    74
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    75
    Array.prototype.push.call(array, 0);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    76
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    77
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    78
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    79
    Array.prototype.pop.call(array);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    80
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    81
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    82
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    83
    Array.prototype.shift.call(array);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    84
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    85
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    86
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    87
    Array.prototype.unshift.call(array);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    88
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    89
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    90
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    91
    Array.prototype.splice.call(array, 0);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    92
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    93
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    94
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    95
    Array.prototype.reverse.call(Object.defineProperty([,,],"0",{ writable: false }));
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    96
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    97
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    98
// try the above via apply
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
    99
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   100
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   101
    Array.prototype.push.apply(array, [ 0 ]);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   102
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   103
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   104
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   105
    Array.prototype.pop.apply(array);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   106
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   107
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   108
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   109
    Array.prototype.shift.apply(array);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   110
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   111
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   112
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   113
    Array.prototype.unshift.apply(array);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   114
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   115
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   116
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   117
    Array.prototype.splice.apply(array, [ 0 ]);
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   118
});
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   119
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   120
check(function() {
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   121
    Array.prototype.reverse.apply(Object.defineProperty([,,],"0",{ writable: false }));
ebd24057f163 8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
diff changeset
   122
});