src/jdk/nashorn/api/scripting/ScriptUtils.java
Print this page
@@ -23,10 +23,12 @@
* questions.
*/
package jdk.nashorn.api.scripting;
+import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
+
import java.lang.invoke.MethodHandle;
import jdk.internal.dynalink.beans.StaticClass;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ScriptFunction;
@@ -67,16 +69,17 @@
/**
* Create a wrapper function that calls {@code func} synchronized on {@code sync} or, if that is undefined,
* {@code self}. Used to implement "sync" function in resources/mozilla_compat.js.
*
- * @param func the function to invoke
+ * @param func the function to wrap
* @param sync the object to synchronize on
* @return a synchronizing wrapper function
*/
- public static Object makeSynchronizedFunction(final ScriptFunction func, final Object sync) {
- return func.makeSynchronizedFunction(sync);
+ public static Object makeSynchronizedFunction(final Object func, final Object sync) {
+ return func instanceof ScriptFunction?
+ ((ScriptFunction)func).makeSynchronizedFunction(sync) : UNDEFINED;
}
/**
* Make a script object mirror on given object if needed.
*