aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorattila <none@none>2013-11-01 15:36:33 +0100
committerattila <none@none>2013-11-01 15:36:33 +0100
commitb02c322eb0f4705b5f13dd118ddecd01a89d66ad (patch)
treecd698301c7beca8dad4bdd9ae7fbaeaa01c9cc60 /test
parentf18981c761509d7dd82faf8bc0f9cd1ebdf96c25 (diff)
downloadnashorn-b02c322eb0f4705b5f13dd118ddecd01a89d66ad.tar.gz
8027236: Ensure ScriptObject and ConsString aren't visible to Java
Reviewed-by: lagergren, sundar
Diffstat (limited to 'test')
-rw-r--r--test/script/basic/JDK-8027236.js37
-rw-r--r--test/script/basic/JDK-8027236.js.EXPECTED1
-rw-r--r--test/src/jdk/nashorn/api/javaaccess/ConsStringTest.java99
3 files changed, 137 insertions, 0 deletions
diff --git a/test/script/basic/JDK-8027236.js b/test/script/basic/JDK-8027236.js
new file mode 100644
index 00000000..02f9e8d8
--- /dev/null
+++ b/test/script/basic/JDK-8027236.js
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+
+/**
+ * JDK-8027236: Ensure ScriptObject and ConsString aren't visible to Java
+ *
+ * @test
+ * @run
+ */
+
+// Check that ConsString is flattened
+var m = new java.util.HashMap()
+var x = "f"
+x += "oo"
+m.put(x, "bar")
+print(m.get("foo"))
+// Note: many more tests are run by the JavaExportImportTest TestNG class.
diff --git a/test/script/basic/JDK-8027236.js.EXPECTED b/test/script/basic/JDK-8027236.js.EXPECTED
new file mode 100644
index 00000000..5716ca59
--- /dev/null
+++ b/test/script/basic/JDK-8027236.js.EXPECTED
@@ -0,0 +1 @@
+bar
diff --git a/test/src/jdk/nashorn/api/javaaccess/ConsStringTest.java b/test/src/jdk/nashorn/api/javaaccess/ConsStringTest.java
new file mode 100644
index 00000000..1eadfb77
--- /dev/null
+++ b/test/src/jdk/nashorn/api/javaaccess/ConsStringTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.javaaccess;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import jdk.nashorn.api.scripting.JSObject;
+import org.testng.TestNG;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ConsStringTest {
+ private static ScriptEngine e = null;
+
+ public static void main(final String[] args) {
+ TestNG.main(args);
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws ScriptException {
+ e = new ScriptEngineManager().getEngineByName("nashorn");
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ e = null;
+ }
+
+ @Test
+ public void testConsStringFlattening() throws ScriptException {
+ final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
+ final Map<Object, Object> m = new HashMap<>();
+ b.put("m", m);
+ e.eval("var x = 'f'; x += 'oo'; var y = 'b'; y += 'ar'; m.put(x, y)");
+ assertEquals("bar", m.get("foo"));
+ }
+
+ @Test
+ public void testConsStringFromMirror() throws ScriptException {
+ final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
+ final Map<Object, Object> m = new HashMap<>();
+ e.eval("var x = 'f'; x += 'oo'; var obj = {x: x};");
+ assertEquals("foo", ((JSObject)b.get("obj")).getMember("x"));
+ }
+
+ @Test
+ public void testArrayConsString() throws ScriptException {
+ final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
+ final ArrayHolder h = new ArrayHolder();
+ b.put("h", h);
+ e.eval("var x = 'f'; x += 'oo'; h.array = [x];");
+ assertEquals(1, h.array.length);
+ assertEquals("foo", h.array[0]);
+ }
+
+
+ public static class ArrayHolder {
+ private Object[] array;
+
+ public void setArray(Object[] array) {
+ this.array = array;
+ }
+
+ public Object[] getArray() {
+ return array;
+ }
+ }
+}