diff --git a/nashorn/README b/nashorn/README
index 242d6077b67..9cc6c723213 100644
--- a/nashorn/README
+++ b/nashorn/README
@@ -72,14 +72,11 @@ after which you can view the generated documentation at dist/javadoc/index.html.
- Running tests
Nashorn tests are TestNG based. Running tests requires downloading the
-TestNG library and placing its jar file into the lib subdirectory:
+TestNG library and placing its jar file into the test/lib subdirectory. This is
+done automatically when executing the "ant externals" command to get external
+test suites (see below).
- # download and install TestNG
- wget http://testng.org/testng-x.y.z.zip
- unzip testng-x.y.z.zip
- cp testng-x.y.z/testng-x.y.z.jar test/lib/testng.jar
-
-After that, you can run the tests using:
+Once TestNG is properly installed, you can run the tests using:
cd make
ant clean test
diff --git a/nashorn/make/build.xml b/nashorn/make/build.xml
index 4ffa61b32a5..58478741eb8 100644
--- a/nashorn/make/build.xml
+++ b/nashorn/make/build.xml
@@ -1,7 +1,7 @@
@@ -469,7 +469,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
-
+
@@ -499,7 +499,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
-
+
@@ -527,7 +527,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
-
+
@@ -546,7 +546,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
-
+
@@ -570,7 +570,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
-
+
@@ -589,7 +589,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
-
+
-
+
@@ -719,8 +719,8 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
-
-
+
+
@@ -730,12 +730,20 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
diff --git a/nashorn/make/project.properties b/nashorn/make/project.properties
index 35e1af9f146..aab32c62a83 100644
--- a/nashorn/make/project.properties
+++ b/nashorn/make/project.properties
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2015, 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
@@ -77,8 +77,11 @@ fxshell.jar = ${dist.dir}/nashornfx.jar
# configuration for java flight recorder
run.test.jvmargs.jfr=-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,dumponexit=true,dumponexitpath=${build.dir},stackdepth=128
+# test library location
+test.lib=${basedir}${file.separator}test${file.separator}lib
+
# jars refererred
-file.reference.testng.jar=test/lib/testng.jar
+file.reference.testng.jar=${test.lib}${file.separator}testng.jar
# Set testng verbose level
# From TestNG docs: "the verbosity level (0 to 10 where 10 is most detailed)
@@ -243,9 +246,9 @@ testjfx-test-sys-prop.test.js.framework=\
-fx \
${test.script.dir}${file.separator}jfx.js
-file.reference.jemmyfx.jar=test${file.separator}lib${file.separator}JemmyFX.jar
-file.reference.jemmycore.jar=test${file.separator}lib${file.separator}JemmyCore.jar
-file.reference.jemmyawtinput.jar=test${file.separator}lib${file.separator}JemmyAWTInput.jar
+file.reference.jemmyfx.jar=${test.lib}${file.separator}JemmyFX.jar
+file.reference.jemmycore.jar=${test.lib}${file.separator}JemmyCore.jar
+file.reference.jemmyawtinput.jar=${test.lib}${file.separator}JemmyAWTInput.jar
file.reference.jfxrt.jar=${java.home}${file.separator}lib${file.separator}ext${file.separator}jfxrt.jar
testjfx.run.test.classpath=\
${file.reference.jemmyfx.jar}${path.separator}\
diff --git a/nashorn/samples/find_nonfinals.js b/nashorn/samples/find_nonfinals.js
index affb753efa9..7824a37ba82 100644
--- a/nashorn/samples/find_nonfinals.js
+++ b/nashorn/samples/find_nonfinals.js
@@ -39,6 +39,7 @@
var Class = Java.type("java.lang.Class");
var System = Java.type("java.lang.System");
+var Thread = Java.type("java.lang.Thread");
var File = Java.type("java.io.File");
var JarFile = Java.type("java.util.jar.JarFile");
var Modifier = Java.type("java.lang.reflect.Modifier");
@@ -58,6 +59,10 @@ function findNashorn() {
function analyzeClass(cls) {
var methods = cls.getDeclaredMethods();
for each (var method in methods) {
+ var methodModifiers = method.modifiers;
+ if (Modifier.isAbstract(methodModifiers) || Modifier.isNative(methodModifiers)) {
+ continue;
+ }
// this requires -parameters option when compiling java sources
var params = method.parameters;
for each (var p in params) {
@@ -73,6 +78,8 @@ function analyzeClass(cls) {
}
var jarFile = findNashorn();
+var ctxtLoader = Thread.currentThread().contextClassLoader;
+
// load each class and use reflection to analyze each Class
new JarFile(jarFile).stream().forEach(
function(entry) {
@@ -80,8 +87,15 @@ new JarFile(jarFile).stream().forEach(
if (name.endsWith(".class")) {
var clsName = name.substring(0, name.lastIndexOf('.class'));
clsName = clsName.replace(/\//g, '.');
- var cls = Class.forName(clsName);
- analyzeClass(cls);
+ try {
+ // don't initialize to avoid for possible initialization errors
+ var cls = Class.forName(clsName, false, ctxtLoader);
+ analyzeClass(cls);
+ } catch (e) {
+ // print exception and continue analysis for other classes
+ print("Failed to analyze " + clsName);
+ e.printStackTrace();
+ }
}
}
)
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngine.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngine.java
index dc5170690c3..1d47dac4a94 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngine.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngine.java
@@ -354,8 +354,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
}, CREATE_GLOBAL_ACC_CTXT);
- nashornContext.initGlobal(newGlobal, this);
- newGlobal.setScriptContext(ctxt);
+ nashornContext.initGlobal(newGlobal, this, ctxt);
return newGlobal;
}
@@ -404,7 +403,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
return evalImpl(script, ctxt, getNashornGlobalFrom(ctxt));
}
- private static Object evalImpl(final Context.MultiGlobalCompiledScript mgcs, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException {
+ private Object evalImpl(final Context.MultiGlobalCompiledScript mgcs, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException {
final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != ctxtGlobal);
try {
@@ -413,8 +412,13 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
final ScriptFunction script = mgcs.getFunction(ctxtGlobal);
+ final ScriptContext oldCtxt = ctxtGlobal.getScriptContext();
ctxtGlobal.setScriptContext(ctxt);
- return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal));
+ try {
+ return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal));
+ } finally {
+ ctxtGlobal.setScriptContext(oldCtxt);
+ }
} catch (final Exception e) {
throwAsScriptException(e, ctxtGlobal);
throw new AssertionError("should not reach here");
@@ -425,7 +429,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
}
- private static Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException {
+ private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException {
if (script == null) {
return null;
}
@@ -436,8 +440,13 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
Context.setGlobal(ctxtGlobal);
}
+ final ScriptContext oldCtxt = ctxtGlobal.getScriptContext();
ctxtGlobal.setScriptContext(ctxt);
- return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal));
+ try {
+ return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal));
+ } finally {
+ ctxtGlobal.setScriptContext(oldCtxt);
+ }
} catch (final Exception e) {
throwAsScriptException(e, ctxtGlobal);
throw new AssertionError("should not reach here");
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java
index cabd1373366..e9fbd6bf61b 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java
@@ -47,6 +47,7 @@ import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.ConsString;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ECMAException;
+import jdk.nashorn.internal.runtime.JSONListAdapter;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
@@ -72,6 +73,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
private final ScriptObject sobj;
private final Global global;
private final boolean strict;
+ private final boolean jsonCompatible;
@Override
public boolean equals(final Object other) {
@@ -110,9 +112,9 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
}
if (sobj instanceof ScriptFunction) {
- final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args;
- final Object self = globalChanged? wrap(thiz, oldGlobal) : thiz;
- return wrap(ScriptRuntime.apply((ScriptFunction)sobj, unwrap(self, global), unwrapArray(modArgs, global)), global);
+ final Object[] modArgs = globalChanged? wrapArrayLikeMe(args, oldGlobal) : args;
+ final Object self = globalChanged? wrapLikeMe(thiz, oldGlobal) : thiz;
+ return wrapLikeMe(ScriptRuntime.apply((ScriptFunction)sobj, unwrap(self, global), unwrapArray(modArgs, global)));
}
throw new RuntimeException("not a function: " + toString());
@@ -140,8 +142,8 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
}
if (sobj instanceof ScriptFunction) {
- final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args;
- return wrap(ScriptRuntime.construct((ScriptFunction)sobj, unwrapArray(modArgs, global)), global);
+ final Object[] modArgs = globalChanged? wrapArrayLikeMe(args, oldGlobal) : args;
+ return wrapLikeMe(ScriptRuntime.construct((ScriptFunction)sobj, unwrapArray(modArgs, global)));
}
throw new RuntimeException("not a constructor: " + toString());
@@ -170,7 +172,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
return Context.getContext();
}
}, GET_CONTEXT_ACC_CTXT);
- return wrap(context.eval(global, s, sobj, null, false), global);
+ return wrapLikeMe(context.eval(global, s, sobj, null, false));
}
});
}
@@ -193,8 +195,8 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
final Object val = sobj.get(functionName);
if (val instanceof ScriptFunction) {
- final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args;
- return wrap(ScriptRuntime.apply((ScriptFunction)val, sobj, unwrapArray(modArgs, global)), global);
+ final Object[] modArgs = globalChanged? wrapArrayLikeMe(args, oldGlobal) : args;
+ return wrapLikeMe(ScriptRuntime.apply((ScriptFunction)val, sobj, unwrapArray(modArgs, global)));
} else if (val instanceof JSObject && ((JSObject)val).isFunction()) {
return ((JSObject)val).call(sobj, args);
}
@@ -218,7 +220,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
Objects.requireNonNull(name);
return inGlobal(new Callable