test/jdk/javax/script/GetInterfaceTest.java
author coleenp
Mon, 30 Sep 2019 13:10:11 -0400
changeset 58409 a595e67d6683
parent 47216 71c04702a3d5
permissions -rw-r--r--
8184732: Deadlock detection improvements for 'special' locks Summary: Assert that special ranked locks cannot safepoint and allow_vm_block and remove locks from the exceptional lock list in no_safepoint_verifier. Reviewed-by: dholmes, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 16719
diff changeset
     2
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
     4
 *
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
     8
 *
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    13
 * accompanied this code).
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    14
 *
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    18
 *
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    21
 * questions.
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    22
 */
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    23
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    24
/*
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    25
 * @test
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    26
 * @bug 6960211
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    27
 * @summary JavaScript engine allows creation of interface although methods not available.
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    28
 */
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    29
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    30
import javax.script.*;
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    31
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    32
public class GetInterfaceTest {
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    33
    public static void main(String[] args) throws Exception {
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    34
        ScriptEngineManager manager = new ScriptEngineManager();
16038
de84354579d3 8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine
sundar
parents: 8772
diff changeset
    35
        ScriptEngine engine = manager.getEngineByName("nashorn");
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    36
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    37
        if (engine == null) {
16038
de84354579d3 8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine
sundar
parents: 8772
diff changeset
    38
            System.out.println("Warning: No js engine engine found; test vacuously passes.");
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    39
            return;
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    40
        }
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    41
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    42
        // don't define any function.
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    43
        engine.eval("");
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    44
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    45
        Runnable runnable = ((Invocable)engine).getInterface(Runnable.class);
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    46
        if (runnable != null) {
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    47
            throw new RuntimeException("runnable is not null!");
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    48
        }
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    49
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    50
        // now define "run"
16719
debc7896d82d 8010991: Enable test/javax/script/GetInterfaceTest.java again
sundar
parents: 16038
diff changeset
    51
        engine.eval("function run() { print('this is run function'); }");
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    52
        runnable = ((Invocable)engine).getInterface(Runnable.class);
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    53
        // should not return null now!
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    54
        runnable.run();
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    55
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    56
        // define only one method of "Foo2"
16719
debc7896d82d 8010991: Enable test/javax/script/GetInterfaceTest.java again
sundar
parents: 16038
diff changeset
    57
        engine.eval("function bar() { print('bar function'); }");
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    58
        Foo2 foo2 = ((Invocable)engine).getInterface(Foo2.class);
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    59
        if (foo2 != null) {
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    60
            throw new RuntimeException("foo2 is not null!");
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    61
        }
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    62
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    63
        // now define other method of "Foo2"
16719
debc7896d82d 8010991: Enable test/javax/script/GetInterfaceTest.java again
sundar
parents: 16038
diff changeset
    64
        engine.eval("function bar2() { print('bar2 function'); }");
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    65
        foo2 = ((Invocable)engine).getInterface(Foo2.class);
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    66
        foo2.bar();
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    67
        foo2.bar2();
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    68
    }
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    69
16719
debc7896d82d 8010991: Enable test/javax/script/GetInterfaceTest.java again
sundar
parents: 16038
diff changeset
    70
    public interface Foo {
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    71
        public void bar();
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    72
    }
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    73
16719
debc7896d82d 8010991: Enable test/javax/script/GetInterfaceTest.java again
sundar
parents: 16038
diff changeset
    74
    public interface Foo2 extends Foo {
8772
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    75
        public void bar2();
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    76
    }
e088a9afb9cc 6960211: JavaScript engine allows creation of interface although methods not available
sundar
parents:
diff changeset
    77
}