sundar@966: /* sundar@966: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. sundar@966: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@966: * sundar@966: * This code is free software; you can redistribute it and/or modify it sundar@966: * under the terms of the GNU General Public License version 2 only, as sundar@966: * published by the Free Software Foundation. sundar@966: * sundar@966: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@966: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@966: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@966: * version 2 for more details (a copy is included in the LICENSE file that sundar@966: * accompanied this code). sundar@966: * sundar@966: * You should have received a copy of the GNU General Public License version sundar@966: * 2 along with this work; if not, write to the Free Software Foundation, sundar@966: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@966: * sundar@966: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@966: * or visit www.oracle.com if you need additional information or have any sundar@966: * questions. sundar@966: */ sundar@966: sundar@966: /** sundar@966: * JDK-8055762: Nashorn misses linker for netscape.javascript.JSObject instances sundar@969: * sundar@966: * @test sundar@969: * @option -scripting sundar@966: * @run sundar@966: */ sundar@966: sundar@966: // basic checks for special linkage for netscape.javascript.JSObject sundar@966: // instances. For this test, we just subclass that class rather than sundar@966: // involve actual browser script engine or javafx webkit objects. sundar@966: sundar@969: function main() { sundar@969: var JSObject; sundar@969: try { sundar@969: JSObject = Java.type("netscape.javascript.JSObject"); sundar@969: } catch (e) { sundar@969: if (e instanceof java.lang.ClassNotFoundException) { sundar@969: // pass vacuously by emitting the .EXPECTED file content sundar@969: var str = readFully(__DIR__ + "JDK-8055762.js.EXPECTED"); sundar@969: print(str.substring(0, str.length - 1)); sundar@969: return; sundar@969: } else{ sundar@969: fail("unexpected exception for JSObject", e); sundar@969: } sundar@969: } sundar@969: test(JSObject); sundar@969: } sundar@969: sundar@969: function test(JSObject) { sundar@969: var obj = new (Java.extend(JSObject))() { sundar@969: getMember: function(name) { sundar@969: if (name == "func") { sundar@969: return function(arg) { sundar@969: print("func called with " + arg); sundar@969: } sundar@966: } sundar@969: return name.toUpperCase(); sundar@969: }, sundar@969: sundar@969: getSlot: function(index) { sundar@969: return index^2; sundar@969: }, sundar@969: sundar@969: setMember: function(name, value) { sundar@969: print(name + " set to " + value); sundar@969: }, sundar@969: sundar@969: setSlot: function(index, value) { sundar@969: print("[" + index + "] set to " + value); sundar@966: } sundar@969: }; sundar@966: hannesw@1247: var a = "a"; sundar@969: print(obj["foo"]); hannesw@1247: print(obj[a + "bc"]); sundar@969: print(obj[2]); sundar@969: obj.bar = 23; hannesw@1247: obj[a + "bc"] = 23; sundar@969: obj[3] = 23; sundar@969: obj.func("hello"); sundar@969: } sundar@966: sundar@969: main();