sundar@969: /* sundar@969: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. sundar@969: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@969: * sundar@969: * This code is free software; you can redistribute it and/or modify it sundar@969: * under the terms of the GNU General Public License version 2 only, as sundar@969: * published by the Free Software Foundation. sundar@969: * sundar@969: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@969: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@969: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@969: * version 2 for more details (a copy is included in the LICENSE file that sundar@969: * accompanied this code). sundar@969: * sundar@969: * You should have received a copy of the GNU General Public License version sundar@969: * 2 along with this work; if not, write to the Free Software Foundation, sundar@969: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@969: * sundar@969: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@969: * or visit www.oracle.com if you need additional information or have any sundar@969: * questions. sundar@969: */ sundar@969: sundar@969: /** sundar@969: * JDK-8055796: JSObject and browser JSObject linkers should provide fallback to call underlying Java methods directly sundar@969: * sundar@969: * @test sundar@969: * @option -scripting sundar@969: * @run sundar@969: */ sundar@969: 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-8055796_2.js.EXPECTED"); sundar@969: print(str.substring(0, str.length - 1)); sundar@969: return; sundar@969: } else { sundar@969: fail("unexpected exception on JSObject", e); sundar@969: } sundar@969: } sundar@969: test(JSObject); sundar@969: } sundar@969: sundar@969: function test(JSObject) { sundar@969: var bjsobj = 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@969: } sundar@969: return name.toUpperCase(); sundar@969: }, sundar@969: sundar@969: getSlot: function(index) { sundar@969: return index*index; 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@969: } sundar@969: }; sundar@969: sundar@969: print("getMember('foo') =", bjsobj['getMember(String)']('foo')); sundar@969: print("getSlot(6) =", bjsobj['getSlot(int)'](6)); sundar@969: bjsobj['setMember(String, Object)']('bar', 'hello'); sundar@969: bjsobj['setSlot(int, Object)'](10, 42); sundar@969: } sundar@969: sundar@969: main();