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