aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorattila <none@none>2013-04-23 12:52:29 +0200
committerattila <none@none>2013-04-23 12:52:29 +0200
commitc2aeeaed59b41fd2d72599fab23fd69be593de88 (patch)
treee293585d6c2bd96c00947483016e78fb1e6db028 /test
parent32e5eedd39b0e7d84185ad04fe2e288f4fcbc81f (diff)
downloadnashorn-c2aeeaed59b41fd2d72599fab23fd69be593de88.tar.gz
8011065: Problems when script implements an interface with variadic methods
Reviewed-by: jlaskey, hannesw, sundar
Diffstat (limited to 'test')
-rw-r--r--test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java22
-rw-r--r--test/src/jdk/nashorn/api/scripting/VariableArityTestInterface.java31
2 files changed, 53 insertions, 0 deletions
diff --git a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java
index 48277aa8..918d1f05 100644
--- a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java
+++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java
@@ -906,4 +906,26 @@ public class ScriptEngineTest {
fail(se.getMessage());
}
}
+
+ @Test
+ /**
+ * Tests whether invocation of a JavaScript method through a variable arity Java method will pass the vararg array.
+ * Both non-vararg and vararg JavaScript methods are tested.
+ * @throws ScriptException
+ */
+ public void variableArityInterfaceTest() throws ScriptException {
+ final ScriptEngineManager m = new ScriptEngineManager();
+ final ScriptEngine e = m.getEngineByName("nashorn");
+ e.eval(
+ "function test1(i, strings) {" +
+ " return 'i == ' + i + ', strings instanceof java.lang.String[] == ' + (strings instanceof Java.type('java.lang.String[]')) + ', strings == ' + java.util.Arrays.toString(strings)" +
+ "}" +
+ "function test2() {" +
+ " return 'arguments[0] == ' + arguments[0] + ', arguments[1] instanceof java.lang.String[] == ' + (arguments[1] instanceof Java.type('java.lang.String[]')) + ', arguments[1] == ' + java.util.Arrays.toString(arguments[1])" +
+ "}"
+ );
+ final VariableArityTestInterface itf = ((Invocable)e).getInterface(VariableArityTestInterface.class);
+ Assert.assertEquals(itf.test1(42, "a", "b"), "i == 42, strings instanceof java.lang.String[] == true, strings == [a, b]");
+ Assert.assertEquals(itf.test2(44, "c", "d", "e"), "arguments[0] == 44, arguments[1] instanceof java.lang.String[] == true, arguments[1] == [c, d, e]");
+ }
}
diff --git a/test/src/jdk/nashorn/api/scripting/VariableArityTestInterface.java b/test/src/jdk/nashorn/api/scripting/VariableArityTestInterface.java
new file mode 100644
index 00000000..d3904522
--- /dev/null
+++ b/test/src/jdk/nashorn/api/scripting/VariableArityTestInterface.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.api.scripting;
+
+public interface VariableArityTestInterface {
+ public String test1(int i, String... strings);
+ public String test2(int i, String... strings);
+}