Wed, 01 Oct 2014 07:47:24 -0700
Added tag jdk8u40-b08 for changeset 89551828b279
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 */
24 /**
25 * JDK-8007140: Java.extend crashes when attempting to extend java.lang.Object
26 *
27 * @test
28 * @run
29 */
32 // try various Java.extend cases
34 // Single interface
35 var runReached = false;
36 var r = new (Java.extend(java.lang.Runnable)) {
37 run: function() {
38 runReached = true;
39 }
40 };
42 r.run();
43 if (! runReached) {
44 fail("run was not called");
45 }
47 if (! (r instanceof java.lang.Runnable)) {
48 fail("r is not a Runnable");
49 }
51 // Multiple intefaces
52 var runReached = false;
53 var actionPerformedReached = false;
55 var obj = new (Java.extend(java.awt.event.ActionListener, java.lang.Runnable)) {
56 actionPerformed : function(e) {
57 actionPerformedReached = true;
58 },
60 run: function() {
61 runReached = true;
62 }
63 };
65 obj.actionPerformed(null);
66 if (! actionPerformedReached) {
67 fail("actionPerformed was not called");
68 }
70 obj.run();
71 if (! runReached) {
72 fail("run was not called");
73 }
75 if (! (obj instanceof java.lang.Runnable)) {
76 fail("obj is not a Runnable");
77 }
79 if (! (obj instanceof java.awt.event.ActionListener)) {
80 fail("obj is not an ActionListener");
81 }
83 // Single class
84 var obj = new (Java.extend(java.lang.Object)) {
85 toString: function() { return "I am an Object"; }
86 };
88 if (! (obj instanceof java.lang.Object)) {
89 fail("obj is not an instance of java.lang.Object");
90 }
92 if (obj.toString() != "I am an Object") {
93 fail("Object.toString did not get called");
94 }
96 // Single class and single interface
97 var runReached = false;
98 var obj = new (Java.extend(java.lang.Object, java.lang.Runnable)) {
99 run: function() {
100 runReached = true;
101 },
103 hashCode: function() {
104 return 12;
105 }
106 };
108 obj.run();
109 if (! runReached) {
110 fail("run was not called");
111 }
113 if (obj.hashCode() != 12) {
114 fail("hashCode does not return 12");
115 }