JDK-8007140.js revision 59:c04f54d5b672
1/* 2 * Copyright (c) 2010, 2013, 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-8007140: Java.extend crashes when attempting to extend java.lang.Object 26 * 27 * @test 28 * @run 29 */ 30 31 32// try various Java.extend cases 33 34// Single interface 35var runReached = false; 36var r = new (Java.extend(java.lang.Runnable)) { 37 run: function() { 38 runReached = true; 39 } 40}; 41 42r.run(); 43if (! runReached) { 44 fail("run was not called"); 45} 46 47if (! (r instanceof java.lang.Runnable)) { 48 fail("r is not a Runnable"); 49} 50 51// Multiple intefaces 52var runReached = false; 53var actionPerformedReached = false; 54 55var obj = new (Java.extend(java.awt.event.ActionListener, java.lang.Runnable)) { 56 actionPerformed : function(e) { 57 actionPerformedReached = true; 58 }, 59 60 run: function() { 61 runReached = true; 62 } 63}; 64 65obj.actionPerformed(null); 66if (! actionPerformedReached) { 67 fail("actionPerformed was not called"); 68} 69 70obj.run(); 71if (! runReached) { 72 fail("run was not called"); 73} 74 75if (! (obj instanceof java.lang.Runnable)) { 76 fail("obj is not a Runnable"); 77} 78 79if (! (obj instanceof java.awt.event.ActionListener)) { 80 fail("obj is not an ActionListener"); 81} 82 83// Single class 84var obj = new (Java.extend(java.lang.Object)) { 85 toString: function() { return "I am an Object"; } 86}; 87 88if (! (obj instanceof java.lang.Object)) { 89 fail("obj is not an instance of java.lang.Object"); 90} 91 92if (obj.toString() != "I am an Object") { 93 fail("Object.toString did not get called"); 94} 95 96// Single class and single interface 97var runReached = false; 98var obj = new (Java.extend(java.lang.Object, java.lang.Runnable)) { 99 run: function() { 100 runReached = true; 101 }, 102 103 hashCode: function() { 104 return 12; 105 } 106}; 107 108obj.run(); 109if (! runReached) { 110 fail("run was not called"); 111} 112 113if (obj.hashCode() != 12) { 114 fail("hashCode does not return 12"); 115} 116