3743N/A/*
3743N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3743N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3743N/A *
3743N/A * This code is free software; you can redistribute it and/or modify it
3743N/A * under the terms of the GNU General Public License version 2 only, as
3743N/A * published by the Free Software Foundation.
3743N/A *
3743N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3743N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3743N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3743N/A * version 2 for more details (a copy is included in the LICENSE file that
3743N/A * accompanied this code).
3743N/A *
3743N/A * You should have received a copy of the GNU General Public License version
3743N/A * 2 along with this work; if not, write to the Free Software Foundation,
3743N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3743N/A *
3743N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3743N/A * or visit www.oracle.com if you need additional information or have any
3743N/A * questions.
3743N/A */
3743N/A
3743N/A/*
3743N/A * @test
3743N/A * @bug 6960211
3743N/A * @summary JavaScript engine allows creation of interface although methods not available.
3743N/A */
3743N/A
3743N/Aimport javax.script.*;
3743N/A
3743N/Apublic class GetInterfaceTest {
3743N/A public static void main(String[] args) throws Exception {
3743N/A ScriptEngineManager manager = new ScriptEngineManager();
3743N/A ScriptEngine engine = manager.getEngineByName("js");
3743N/A
3743N/A if (engine == null) {
3743N/A System.out.println("Warning: No engine engine found; test vacuously passes.");
3743N/A return;
3743N/A }
3743N/A
3743N/A // don't define any function.
3743N/A engine.eval("");
3743N/A
3743N/A Runnable runnable = ((Invocable)engine).getInterface(Runnable.class);
3743N/A if (runnable != null) {
3743N/A throw new RuntimeException("runnable is not null!");
3743N/A }
3743N/A
3743N/A // now define "run"
3743N/A engine.eval("function run() { println('this is run function'); }");
3743N/A runnable = ((Invocable)engine).getInterface(Runnable.class);
3743N/A // should not return null now!
3743N/A runnable.run();
3743N/A
3743N/A // define only one method of "Foo2"
3743N/A engine.eval("function bar() { println('bar function'); }");
3743N/A Foo2 foo2 = ((Invocable)engine).getInterface(Foo2.class);
3743N/A if (foo2 != null) {
3743N/A throw new RuntimeException("foo2 is not null!");
3743N/A }
3743N/A
3743N/A // now define other method of "Foo2"
3743N/A engine.eval("function bar2() { println('bar2 function'); }");
3743N/A foo2 = ((Invocable)engine).getInterface(Foo2.class);
3743N/A foo2.bar();
3743N/A foo2.bar2();
3743N/A }
3743N/A
3743N/A interface Foo {
3743N/A public void bar();
3743N/A }
3743N/A
3743N/A interface Foo2 extends Foo {
3743N/A public void bar2();
3743N/A }
3743N/A}