test/script/basic/JDK-8055796_2.js

Mon, 03 Oct 2016 11:11:43 -0700

author
asaha
date
Mon, 03 Oct 2016 11:11:43 -0700
changeset 2002
31dad6c4e1be
parent 969
e94c247e4673
permissions
-rw-r--r--

Added tag jdk8u121-b03 for changeset 112c17eb13c7

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

mercurial