nashorn/test/script/basic/JDK-8055762.js
author hannesw
Mon, 15 Dec 2014 12:32:34 +0100
changeset 28125 118973efb1d3
parent 26240 4639082d6375
permissions -rw-r--r--
8062030: Nashorn bug retrieving array property after key string concatenation Reviewed-by: sundar, lagergren, attila
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26236
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     1
/*
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     4
 *
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     8
 *
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    13
 * accompanied this code).
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    14
 *
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    18
 *
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    21
 * questions.
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    22
 */
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    23
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    24
/**
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    25
 * JDK-8055762: Nashorn misses linker for netscape.javascript.JSObject instances
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    26
 *
26236
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    27
 * @test
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    28
 * @option -scripting
26236
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    29
 * @run
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    30
 */
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    31
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    32
// basic checks for special linkage for netscape.javascript.JSObject
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    33
// instances. For this test, we just subclass that class rather than
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    34
// involve actual browser script engine or javafx webkit objects.
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    35
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    36
function main() {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    37
    var JSObject;
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    38
    try {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    39
        JSObject = Java.type("netscape.javascript.JSObject");
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    40
    } catch (e) {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    41
        if (e instanceof java.lang.ClassNotFoundException) {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    42
            // pass vacuously by emitting the .EXPECTED file content
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    43
            var str = readFully(__DIR__ + "JDK-8055762.js.EXPECTED");
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    44
            print(str.substring(0, str.length - 1));
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    45
            return;
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    46
        } else{
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    47
            fail("unexpected exception for JSObject", e);
26236
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    48
        }
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    49
    }
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    50
    test(JSObject);
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    51
}
26236
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    52
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    53
function test(JSObject) {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    54
    var obj = new (Java.extend(JSObject))() {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    55
        getMember: function(name) {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    56
            if (name == "func") {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    57
                return function(arg) {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    58
                    print("func called with " + arg);
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    59
                }
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    60
            }
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    61
            return name.toUpperCase();
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    62
        },
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    63
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    64
        getSlot: function(index) {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    65
            return index^2;
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    66
        },
26236
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    67
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    68
        setMember: function(name, value) {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    69
            print(name + " set to " + value);
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    70
        },
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    71
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    72
        setSlot: function(index, value) {
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    73
            print("[" + index + "] set to " + value);
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    74
        }
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    75
    };
26236
78b5ece438c0 8055762: Nashorn misses linker for netscape.javascript.JSObject instances
sundar
parents:
diff changeset
    76
28125
118973efb1d3 8062030: Nashorn bug retrieving array property after key string concatenation
hannesw
parents: 26240
diff changeset
    77
    var a = "a";
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    78
    print(obj["foo"]);
28125
118973efb1d3 8062030: Nashorn bug retrieving array property after key string concatenation
hannesw
parents: 26240
diff changeset
    79
    print(obj[a + "bc"]);
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    80
    print(obj[2]);
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    81
    obj.bar = 23;
28125
118973efb1d3 8062030: Nashorn bug retrieving array property after key string concatenation
hannesw
parents: 26240
diff changeset
    82
    obj[a + "bc"] = 23;
26240
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    83
    obj[3] = 23;
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    84
    obj.func("hello");
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    85
}
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    86
4639082d6375 8055899: Two nashorn tests fail in 8u40 nightly build with ClassNotFoundException
sundar
parents: 26236
diff changeset
    87
main();