test/script/basic/JDK-8055762.js

Mon, 03 Nov 2014 09:49:52 +0100

author
attila
date
Mon, 03 Nov 2014 09:49:52 +0100
changeset 1090
99571b7922c0
parent 969
e94c247e4673
child 1247
a7dc7be2d635
permissions
-rw-r--r--

8059443: NPE when unboxing return values
Reviewed-by: lagergren, sundar

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

mercurial