Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/basic/JDK-8007140.js
32280 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* JDK-8007140: Java.extend crashes when attempting to extend java.lang.Object25*26* @test27* @run28*/293031// try various Java.extend cases3233// Single interface34var runReached = false;35var r = new (Java.extend(java.lang.Runnable)) {36run: function() {37runReached = true;38}39};4041r.run();42if (! runReached) {43fail("run was not called");44}4546if (! (r instanceof java.lang.Runnable)) {47fail("r is not a Runnable");48}4950// Multiple intefaces51var runReached = false;52var actionPerformedReached = false;5354var obj = new (Java.extend(java.awt.event.ActionListener, java.lang.Runnable)) {55actionPerformed : function(e) {56actionPerformedReached = true;57},5859run: function() {60runReached = true;61}62};6364obj.actionPerformed(null);65if (! actionPerformedReached) {66fail("actionPerformed was not called");67}6869obj.run();70if (! runReached) {71fail("run was not called");72}7374if (! (obj instanceof java.lang.Runnable)) {75fail("obj is not a Runnable");76}7778if (! (obj instanceof java.awt.event.ActionListener)) {79fail("obj is not an ActionListener");80}8182// Single class83var obj = new (Java.extend(java.lang.Object)) {84toString: function() { return "I am an Object"; }85};8687if (! (obj instanceof java.lang.Object)) {88fail("obj is not an instance of java.lang.Object");89}9091if (obj.toString() != "I am an Object") {92fail("Object.toString did not get called");93}9495// Single class and single interface96var runReached = false;97var obj = new (Java.extend(java.lang.Object, java.lang.Runnable)) {98run: function() {99runReached = true;100},101102hashCode: function() {103return 12;104}105};106107obj.run();108if (! runReached) {109fail("run was not called");110}111112if (obj.hashCode() != 12) {113fail("hashCode does not return 12");114}115116117