nashorn/test/script/basic/JDK-8161579.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 42378 88f74d63d093
permissions -rw-r--r--
8173888: Test for JDK-8169481 causes stack overflows in parser tests Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42378
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     1
/*
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     4
 * 
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     8
 * 
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    13
 * accompanied this code).
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    14
 * 
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    18
 * 
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    21
 * questions.
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    22
 */
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    23
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    24
/**
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    25
 * JDK-8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    26
 *
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    27
 * @test
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    28
 * @run
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    29
 */
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    30
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    31
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    32
var AbstractJSObject = Java.type("jdk.nashorn.api.scripting.AbstractJSObject");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    33
var JavaStringArray = Java.type("java.lang.String[]");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    34
var JavaArrayList = Java.type("java.util.ArrayList");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    35
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    36
var arrayLikeJSObject = new AbstractJSObject() {
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    37
    hasMember: function(name) { return name == "length"; },
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    38
    getMember: function(name) { return name == "length" ? 3 : null; },
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    39
    hasSlot: function(slot) { return slot >= 0 && slot <= 2; },
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    40
    getSlot: function(slot) { return "abc"[slot]; },
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    41
    isArray: function() { return true; }
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    42
}
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    43
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    44
var javaStringArray = new JavaStringArray(3);
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    45
javaStringArray[0] = "x";
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    46
javaStringArray[1] = "y";
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    47
javaStringArray[2] = "z";
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    48
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    49
var javaArrayList = new JavaArrayList();
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    50
javaArrayList.add("i");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    51
javaArrayList.add("j");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    52
javaArrayList.add("k");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    53
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    54
Assert.assertEquals([1, 2, 3].concat(arrayLikeJSObject).join(), "1,2,3,a,b,c");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    55
Assert.assertEquals([1, 2, 3].concat(javaStringArray).join(), "1,2,3,x,y,z");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    56
Assert.assertEquals([1, 2, 3].concat(javaArrayList).join(), "1,2,3,i,j,k");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    57
Assert.assertEquals([1, 2, 3].concat("foo").join(), "1,2,3,foo");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    58
Assert.assertEquals([1, 2, 3].concat(4).join(), "1,2,3,4");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    59
Assert.assertEquals([1, 2, 3].concat(false).join(), "1,2,3,false");
88f74d63d093 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions
hannesw
parents:
diff changeset
    60