nashorn/test/script/basic/JDK-8035312.js
author twisti
Wed, 11 Nov 2015 14:40:38 -1000
changeset 34173 01bb07d23a5b
parent 27525 e7d3c00b9fb8
permissions -rw-r--r--
8141133: [JVMCI] crash during safepoint deopt if rethrow_exception is set Reviewed-by: twisti Contributed-by: Gilles Duboscq <gilles.m.duboscq@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     1
/*
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     4
 *
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     8
 *
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    13
 * accompanied this code).
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    14
 *
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    18
 *
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    21
 * questions.
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    22
 */
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    23
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    24
/**
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    25
 * JDK-8035312 push to frozen array must not increase length property
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    26
 *
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    27
 * @test
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    28
 * @run
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    29
 * @fork
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    30
 * @option -Dnashorn.debug=true
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    31
 */
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    32
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    33
function printArrayDataClass(x) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    34
    if (typeof Debug !== 'undefined') {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    35
	print(Debug.getArrayDataClass(x));
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    36
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    37
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    38
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    39
function gpush(x, elem) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    40
    try {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    41
	print("Pushing " + elem + " to " + x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    42
	x.push(elem);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    43
    } catch (e) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    44
	print("caught error" + e);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    45
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    46
    print("\tarray is now [" + x + "] length is = " + x.length);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    47
    print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    48
    printArrayDataClass(x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    49
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    50
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    51
function gpop(x) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    52
    try {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    53
	print("Popping from " + x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    54
	x.pop();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    55
    } catch (e) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    56
	if (!(e instanceof TypeError)) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    57
	    print("e of wrong type " + e);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    58
	}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    59
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    60
    print("\tarray is now [" + x + "] length is = " + x.length);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    61
    print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    62
    printArrayDataClass(x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    63
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    64
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    65
function checkArray(x) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    66
    print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    67
    print(">>> Push test");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    68
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    69
    var olen = x.length;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    70
    gpush(x, 0);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    71
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    72
    print("x.length === " + x.length + " (should be " + olen + ")");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    73
    print("x[3] === " + x[3] + " (should be 0)");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    74
    print("x[4] === " + x[4] + " (should be undefined)");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    75
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    76
    print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    77
    print(">>> Pop test");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    78
    gpop(x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    79
    gpop(x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    80
    print("x.length === " + x.length + " (should be " + olen + ")");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    81
    print("x === " + x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    82
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    83
    for (var i = 0 ; i < 5; i++) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    84
	gpop(x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    85
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    86
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    87
    print("x.length === " + x.length + " (should be " + olen + ")");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    88
    print("x === " + x);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    89
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    90
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    91
print("*** Freezing");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    92
var frozen = [1,2,3];
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    93
Object.freeze(frozen);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    94
checkArray(frozen);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    95
printArrayDataClass(frozen);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    96
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    97
//so far so good
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    98
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
    99
print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   100
print("*** Other length not writable issues");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   101
var lengthNotWritable = [1,2,3];
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   102
Object.defineProperty(lengthNotWritable, "length", { writable: false });
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   103
checkArray(lengthNotWritable);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   104
printArrayDataClass(lengthNotWritable);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   105
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   106
function set(array, from, to, stride) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   107
    //add three elements
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   108
    for (var i = from; i < to; i+=stride) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   109
	try {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   110
	    print("Writing " + i);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   111
	    array[i] = i;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   112
	    printArrayDataClass(array);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   113
	} catch (e) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   114
	    print(e instanceof TypeError);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   115
	}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   116
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   117
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   118
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   119
//define empty array with non writable length
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   120
var arr = [1];
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   121
Object.defineProperty(arr, "length", { writable: false });
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   122
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   123
var olen2 = arr.length;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   124
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   125
set(arr, 0, 3, 1);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   126
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   127
if (arr.length != olen2) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   128
    throw new ("error: " +  arr.length + " != " + olen2);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   129
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   130
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   131
print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   132
print("array writing 0-3, with 1 stride, array = " + arr);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   133
print("length = " + arr.length + ", but elements are: " + arr[0] + " " + arr[1] + " " + arr[2]);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   134
print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   135
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   136
//do the same but sparse/deleted range
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   137
var arr2 = [1];
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   138
Object.defineProperty(arr2, "length", { writable: false });
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   139
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   140
print("initial length = " + arr2.length);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   141
var olen3 = arr2.length;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   142
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   143
set(arr2, 0, 30, 3);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   144
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   145
if (arr2.length != olen3) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   146
    throw new ("error: " +  arr2.length + " != " + olen3);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   147
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   148
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   149
print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   150
var larger = 20;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   151
print("array writing 0-" + larger + ", with 3 stride, array = " + arr2);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   152
print("length = " + arr2.length + ", but elements are: " + arr2[0] + " " + arr2[1] + " " + arr2[2]);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   153
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   154
for (var i = 0; i < larger; i++) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   155
    if (arr2[i] === undefined) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   156
	continue;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   157
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   158
    print(arr2[i] + " has length " + arr2.length);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   159
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   160
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   161
print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   162
var elem = 0x7fffffff - 10;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   163
printArrayDataClass(arr2);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   164
print("adding a new element high up in the array");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   165
print("length before element was added " + arr2.length);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   166
print("putting sparse at " + elem);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   167
arr2[elem] = "sparse";
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   168
print("length after element was added " + arr2.length + " should be the same");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   169
printArrayDataClass(arr2);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   170
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   171
print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   172
print("Printing arr2 - this will fail if length is > 28 and it is " + arr2.length);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   173
print("arr2 = [" + arr2 + "]");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   174
print("new length that should not be writable = " + arr2.length);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   175
print(arr2[elem] === "sparse");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   176
print(arr2[elem]);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   177
for (var i = 0; i < larger; i++) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   178
    print(arr2[i]);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   179
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   180
for (var key in arr2) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   181
    print(key + ":" + arr2[key]);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   182
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   183
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   184
//issues reported by sundar - generic setter doesn't go through push/pop bulkable
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   185
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   186
function sundarExample2(arr, _writable) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   187
    print("Checking if push works for bulkable non bulkable arrays - Setting length property not allowed");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   188
    arr[0] = "bar";
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   189
    print(arr.length + " should be 1"); // should be 1
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   190
    print(arr[0] + " should be bar");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   191
    print("["+ arr + "] should be [bar]");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   192
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   193
    //    Object.defineProperty(arr, "length", { configurable: _writable });
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   194
    Object.defineProperty(arr, "length", { writable: _writable });
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   195
    arr[1] = "baz";
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   196
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   197
    if (_writable) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   198
	print(arr.length + " should be 2");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   199
	print(arr[0] + " should be bar");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   200
	print(arr[1] + " should be baz");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   201
	print("["+ arr + "] should be [bar,baz]");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   202
    } else {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   203
	print(arr.length + " should STILL be 1");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   204
	print(arr[0] + " should be bar");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   205
	print(arr[1] + " should be baz");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   206
	print("["+ arr + "] should be [bar]");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   207
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   208
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   209
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   210
var newArr1 = [];
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   211
sundarExample2(newArr1, false);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   212
print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   213
try {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   214
    sundarExample2(newArr1, true);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   215
    print("should not get here");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   216
} catch (e) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   217
    if (!(e instanceof TypeError)) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   218
	print("Wrong exception");
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   219
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   220
    print("got TypeError when redefining length, as expected")
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   221
}
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   222
print();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   223
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   224
sundarExample2([], true);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents:
diff changeset
   225
print("Done");