aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorattila <none@none>2014-01-30 20:14:29 +0100
committerattila <none@none>2014-01-30 20:14:29 +0100
commit858b836f66666648a09720711712e5d5b2ba8c5a (patch)
tree2e7b80695bd3e999984e452d371656c8aaa1c336 /test
parentf49f5e1db8fb56d4fb78dcca0115cdfce77d2831 (diff)
downloadnashorn-858b836f66666648a09720711712e5d5b2ba8c5a.tar.gz
8032681: Issues with Nashorn
Reviewed-by: ahgross, jlaskey, sundar
Diffstat (limited to 'test')
-rw-r--r--test/script/basic/JDK-8014647.js7
-rw-r--r--test/script/basic/JDK-8014647.js.EXPECTED4
-rw-r--r--test/script/basic/javaclassoverrides.js13
-rw-r--r--test/script/basic/javaclassoverrides.js.EXPECTED6
-rw-r--r--test/script/sandbox/javaextend.js15
-rw-r--r--test/script/sandbox/javaextend.js.EXPECTED2
-rw-r--r--test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java19
-rw-r--r--test/src/jdk/nashorn/test/models/ClassWithFinalFinalizer.java31
-rw-r--r--test/src/jdk/nashorn/test/models/ClassWithInheritedFinalFinalizer.java29
9 files changed, 111 insertions, 15 deletions
diff --git a/test/script/basic/JDK-8014647.js b/test/script/basic/JDK-8014647.js
index 8ecc2110..8d06848f 100644
--- a/test/script/basic/JDK-8014647.js
+++ b/test/script/basic/JDK-8014647.js
@@ -32,9 +32,10 @@ var RunnableImpl1 = Java.extend(java.lang.Runnable, function() { print("I'm runn
var RunnableImpl2 = Java.extend(java.lang.Runnable, function() { print("I'm runnable 2!") })
var r1 = new RunnableImpl1()
var r2 = new RunnableImpl2()
-var r3 = new RunnableImpl2(function() { print("I'm runnable 3!") })
+var RunnableImpl3 = Java.extend(RunnableImpl2);
+var r3 = new RunnableImpl3({ run: function() { print("I'm runnable 3!") }})
r1.run()
r2.run()
r3.run()
-print("r1.class === r2.class: " + (r1.class === r2.class))
-print("r2.class === r3.class: " + (r2.class === r3.class))
+print("r1.class !== r2.class: " + (r1.class !== r2.class))
+print("r2.class !== r3.class: " + (r2.class !== r3.class))
diff --git a/test/script/basic/JDK-8014647.js.EXPECTED b/test/script/basic/JDK-8014647.js.EXPECTED
index 641a13b1..f4f51dcc 100644
--- a/test/script/basic/JDK-8014647.js.EXPECTED
+++ b/test/script/basic/JDK-8014647.js.EXPECTED
@@ -1,5 +1,5 @@
I'm runnable 1!
I'm runnable 2!
I'm runnable 3!
-r1.class === r2.class: false
-r2.class === r3.class: true
+r1.class !== r2.class: true
+r2.class !== r3.class: true
diff --git a/test/script/basic/javaclassoverrides.js b/test/script/basic/javaclassoverrides.js
index e7ad61d8..2fa7a857 100644
--- a/test/script/basic/javaclassoverrides.js
+++ b/test/script/basic/javaclassoverrides.js
@@ -46,7 +46,8 @@ var R2 = Java.extend(java.lang.Runnable, {
var r1 = new R1
var r2 = new R2
// Create one with an instance-override too
-var r3 = new R2(function() { print("r3.run() invoked") })
+var R3 = Java.extend(R2)
+var r3 = new R3({ run: function() { print("r3.run() invoked") }})
// Run 'em - we're passing them through a Thread to make sure they indeed
// are full-blown Runnables
@@ -60,9 +61,9 @@ runInThread(r2)
runInThread(r3)
// Two class-override classes differ
-print("r1.class != r2.class: " + (r1.class != r2.class))
-// However, adding instance-overrides doesn't change the class
-print("r2.class == r3.class: " + (r2.class == r3.class))
+print("r1.class !== r2.class: " + (r1.class !== r2.class))
+// instance-override class also differs
+print("r2.class !== r3.class: " + (r2.class !== r3.class))
function checkAbstract(r) {
try {
@@ -77,10 +78,10 @@ function checkAbstract(r) {
// overrides nor instance overrides are present
var RAbstract = Java.extend(java.lang.Runnable, {})
checkAbstract(new RAbstract()) // class override (empty)
-checkAbstract(new RAbstract() {}) // class+instance override (empty)
+checkAbstract(new (Java.extend(RAbstract))() {}) // class+instance override (empty)
// Check we delegate to superclass if neither class
// overrides nor instance overrides are present
var ExtendsList = Java.extend(java.util.ArrayList, {})
print("(new ExtendsList).size() = " + (new ExtendsList).size())
-print("(new ExtendsList(){}).size() = " + (new ExtendsList(){}).size()) \ No newline at end of file
+print("(new (Java.extend(ExtendsList)){}).size() = " + (new (Java.extend(ExtendsList)){}).size())
diff --git a/test/script/basic/javaclassoverrides.js.EXPECTED b/test/script/basic/javaclassoverrides.js.EXPECTED
index 6c534302..ceec09cf 100644
--- a/test/script/basic/javaclassoverrides.js.EXPECTED
+++ b/test/script/basic/javaclassoverrides.js.EXPECTED
@@ -1,9 +1,9 @@
R1.run() invoked
R2.run() invoked
r3.run() invoked
-r1.class != r2.class: true
-r2.class == r3.class: true
+r1.class !== r2.class: true
+r2.class !== r3.class: true
Got exception: java.lang.UnsupportedOperationException
Got exception: java.lang.UnsupportedOperationException
(new ExtendsList).size() = 0
-(new ExtendsList(){}).size() = 0
+(new (Java.extend(ExtendsList)){}).size() = 0
diff --git a/test/script/sandbox/javaextend.js b/test/script/sandbox/javaextend.js
index 33cc6b01..60eab74d 100644
--- a/test/script/sandbox/javaextend.js
+++ b/test/script/sandbox/javaextend.js
@@ -51,6 +51,21 @@ try {
print(e)
}
+// Can't extend a class with explicit non-overridable finalizer
+try {
+ Java.extend(model("ClassWithFinalFinalizer"))
+} catch(e) {
+ print(e)
+}
+
+// Can't extend a class with inherited non-overridable finalizer
+try {
+ Java.extend(model("ClassWithInheritedFinalFinalizer"))
+} catch(e) {
+ print(e)
+}
+
+
// Can't extend two classes
try {
Java.extend(java.lang.Thread,java.lang.Number)
diff --git a/test/script/sandbox/javaextend.js.EXPECTED b/test/script/sandbox/javaextend.js.EXPECTED
index 69c78189..c7277459 100644
--- a/test/script/sandbox/javaextend.js.EXPECTED
+++ b/test/script/sandbox/javaextend.js.EXPECTED
@@ -1,6 +1,8 @@
TypeError: Can not extend final class jdk.nashorn.test.models.FinalClass.
TypeError: Can not extend class jdk.nashorn.test.models.NoAccessibleConstructorClass as it has no public or protected constructors.
TypeError: Can not extend/implement non-public class/interface jdk.nashorn.test.models.NonPublicClass.
+TypeError: Can not extend class because jdk.nashorn.test.models.ClassWithFinalFinalizer has a final finalize method.
+TypeError: Can not extend class because jdk.nashorn.test.models.ClassWithFinalFinalizer has a final finalize method.
TypeError: Can not extend multiple classes java.lang.Number and java.lang.Thread. At most one of the specified types can be a class, the rest must all be interfaces.
abcdabcd
run-object
diff --git a/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java b/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java
index 9cea21ba..6d0d40f6 100644
--- a/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java
+++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java
@@ -33,8 +33,8 @@ import java.lang.reflect.Proxy;
import java.util.Objects;
import javax.script.Invocable;
import javax.script.ScriptEngine;
-import javax.script.ScriptException;
import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
import org.testng.annotations.Test;
/**
@@ -130,6 +130,23 @@ public class ScriptEngineSecurityTest {
}
}
+
+ @Test
+ public void securitySystemExitFromFinalizerThread() throws ScriptException {
+ if (System.getSecurityManager() == null) {
+ // pass vacuously
+ return;
+ }
+
+ final ScriptEngineManager m = new ScriptEngineManager();
+ final ScriptEngine e = m.getEngineByName("nashorn");
+ e.eval("var o = Java.extend(Java.type('javax.imageio.spi.ServiceRegistry'), { deregisterAll: this.exit.bind(null, 1234)});\n" +
+ "new o(new java.util.ArrayList().iterator())");
+ System.gc();
+ System.runFinalization();
+ // NOTE: this test just exits the VM if it fails.
+ }
+
@Test
public void securitySystemLoadLibrary() {
if (System.getSecurityManager() == null) {
diff --git a/test/src/jdk/nashorn/test/models/ClassWithFinalFinalizer.java b/test/src/jdk/nashorn/test/models/ClassWithFinalFinalizer.java
new file mode 100644
index 00000000..ba0d86d8
--- /dev/null
+++ b/test/src/jdk/nashorn/test/models/ClassWithFinalFinalizer.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.test.models;
+
+public class ClassWithFinalFinalizer {
+ protected final void finalize() {
+ }
+}
diff --git a/test/src/jdk/nashorn/test/models/ClassWithInheritedFinalFinalizer.java b/test/src/jdk/nashorn/test/models/ClassWithInheritedFinalFinalizer.java
new file mode 100644
index 00000000..80393fbb
--- /dev/null
+++ b/test/src/jdk/nashorn/test/models/ClassWithInheritedFinalFinalizer.java
@@ -0,0 +1,29 @@
+/*
+ * 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.test.models;
+
+public class ClassWithInheritedFinalFinalizer extends ClassWithFinalFinalizer {
+}