nashorn/test/script/basic/JDK-8049242.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 26652 56623a8db943
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:
25258
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     1
/*
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     4
 *
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     8
 *
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    13
 * accompanied this code).
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    14
 *
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    18
 *
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    21
 * questions.
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    22
 */
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    23
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    24
/**
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    25
 * JDK-8049242: Explicit constructor overload selection should work with StaticClass as well
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    26
 *
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    27
 * @test
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    28
 * @run
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    29
 */
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    30
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    31
// call explicit constructor
26652
56623a8db943 8057035: Some tests failed using java.awt.Color on Solaris without X11 libraries
yan
parents: 25258
diff changeset
    32
print(new (Java.type("java.lang.String")["(char[],int,int)"])(['a', 'b', 'c'],0, 3));
25258
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    33
// print the constructor itself
26652
56623a8db943 8057035: Some tests failed using java.awt.Color on Solaris without X11 libraries
yan
parents: 25258
diff changeset
    34
print(Java.type("java.lang.String")["(char[],int,int)"]);
25258
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    35
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    36
// store constructor to call later
26652
56623a8db943 8057035: Some tests failed using java.awt.Color on Solaris without X11 libraries
yan
parents: 25258
diff changeset
    37
var Color = Java.type("java.lang.String")["(char[],int,int)"];
25258
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    38
// call stored constructor
26652
56623a8db943 8057035: Some tests failed using java.awt.Color on Solaris without X11 libraries
yan
parents: 25258
diff changeset
    39
print(new Color(['j', 'a', 'v', 'a'], 1, 3))
25258
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    40
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    41
// check if default constructor works
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    42
var obj = new (Java.type("java.lang.Object")["()"])();
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    43
if (obj.class != Java.type("java.lang.Object").class) {
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    44
    fail("obj is a java.lang.Object");
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    45
}
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    46
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    47
// expected failure cases.
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    48
function checkIt(func) {
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    49
    try {
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    50
        func();
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    51
        throw new Error("should have thrown TypeError");
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    52
    } catch(e) {
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    53
        if (! (e instanceof TypeError)) {
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    54
            fail("Expected TypeError, got " + e);
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    55
        }
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    56
        print(e);
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    57
    }
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    58
}
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    59
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    60
// garbage signature string
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    61
checkIt(function() new (Java.type("java.lang.Object")["()xxxxx"])());
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    62
checkIt(function() new (Java.type("java.lang.Object")["("])());
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    63
checkIt(function() new (Java.type("java.lang.Object")[")"])());
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    64
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    65
// call constructor as normal method (without 'new')
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    66
checkIt(function() Color());
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    67
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    68
// try constructor on interface
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    69
checkIt(function() new (Java.type("java.lang.Runnable"))["()"]);
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    70
checkIt(function() new (Java.type("java.lang.Runnable"))["(int)"]);
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    71
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    72
// try constructor on abstrace class
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    73
try {
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    74
    new (Java.type("java.io.InputStream"))["()"];
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    75
    throw new Error("should have thrown exception!");
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    76
} catch (e) {
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    77
    print(e);
325380d7c38c 8049242: Explicit constructor overload selection should work with StaticClass as well
sundar
parents:
diff changeset
    78
}