aboutsummaryrefslogtreecommitdiff
path: root/src/jdk/nashorn/internal/objects/NativeJava.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jdk/nashorn/internal/objects/NativeJava.java')
-rw-r--r--src/jdk/nashorn/internal/objects/NativeJava.java77
1 files changed, 75 insertions, 2 deletions
diff --git a/src/jdk/nashorn/internal/objects/NativeJava.java b/src/jdk/nashorn/internal/objects/NativeJava.java
index 7879bab4..7c6e60a9 100644
--- a/src/jdk/nashorn/internal/objects/NativeJava.java
+++ b/src/jdk/nashorn/internal/objects/NativeJava.java
@@ -36,6 +36,7 @@ import java.util.List;
import jdk.internal.dynalink.beans.StaticClass;
import jdk.internal.dynalink.support.TypeUtilities;
import jdk.nashorn.api.scripting.JSObject;
+import jdk.nashorn.api.scripting.ScriptUtils;
import jdk.nashorn.internal.objects.annotations.Attribute;
import jdk.nashorn.internal.objects.annotations.Function;
import jdk.nashorn.internal.objects.annotations.ScriptClass;
@@ -44,6 +45,7 @@ import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.ListAdapter;
import jdk.nashorn.internal.runtime.PropertyMap;
+import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
import jdk.nashorn.internal.runtime.linker.Bootstrap;
@@ -80,6 +82,77 @@ public final class NativeJava {
}
/**
+ * Returns synchronized wrapper version of the given ECMAScript function.
+ * @param self not used
+ * @param func the ECMAScript function whose synchronized version is returned.
+ * @param obj the object (i.e, lock) on which the function synchronizes.
+ * @return synchronized wrapper version of the given ECMAScript function.
+ */
+ @Function(name="synchronized", attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
+ public static Object synchronizedFunc(final Object self, final Object func, final Object obj) {
+ if (func instanceof ScriptFunction) {
+ return ((ScriptFunction)func).makeSynchronizedFunction(obj);
+ }
+
+ throw typeError("not.a.function", ScriptRuntime.safeToString(func));
+ }
+
+ /**
+ * Returns true if the specified object is a Java method.
+ * @param self not used
+ * @param obj the object that is checked if it is a Java method object or not
+ * @return tells whether given object is a Java method object or not.
+ */
+ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
+ public static boolean isJavaMethod(final Object self, final Object obj) {
+ return Bootstrap.isDynamicMethod(obj);
+ }
+
+ /**
+ * Returns true if the specified object is a java function (but not script function)
+ * @param self not used
+ * @param obj the object that is checked if it is a Java function or not
+ * @return tells whether given object is a Java function or not
+ */
+ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
+ public static boolean isJavaFunction(final Object self, final Object obj) {
+ return Bootstrap.isCallable(obj) && !(obj instanceof ScriptFunction);
+ }
+
+ /**
+ * Returns true if the specified object is a Java object but not a script object
+ * @param self not used
+ * @param obj the object that is checked
+ * @return tells whether given object is a Java object but not a script object
+ */
+ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
+ public static boolean isJavaObject(final Object self, final Object obj) {
+ return obj != null && !(obj instanceof ScriptObject);
+ }
+
+ /**
+ * Returns true if the specified object is a ECMAScript object, that is an instance of {@link ScriptObject}.
+ * @param self not used
+ * @param obj the object that is checked if it is a ECMAScript object or not
+ * @return tells whether given object is a ECMAScript object or not.
+ */
+ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
+ public static boolean isScriptObject(final Object self, final Object obj) {
+ return obj instanceof ScriptObject;
+ }
+
+ /**
+ * Returns true if the specified object is a ECMAScript function, that is an instance of {@link ScriptFunction}.
+ * @param self not used
+ * @param obj the object that is checked if it is a ECMAScript function or not
+ * @return tells whether given object is a ECMAScript function or not.
+ */
+ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
+ public static boolean isScriptFunction(final Object self, final Object obj) {
+ return obj instanceof ScriptFunction;
+ }
+
+ /**
* <p>
* Given a name of a Java type, returns an object representing that type in Nashorn. The Java class of the objects
* used to represent Java types in Nashorn is not {@link java.lang.Class} but rather {@link StaticClass}. They are
@@ -414,7 +487,7 @@ public final class NativeJava {
final Context ctx = Global.getThisContext();
try {
return ctx.findClass(typeName);
- } catch(ClassNotFoundException e) {
+ } catch(final ClassNotFoundException e) {
// The logic below compensates for a frequent user error - when people use dot notation to separate inner
// class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
// below will try alternative class names, replacing dots at the end of the name with dollar signs.
@@ -429,7 +502,7 @@ public final class NativeJava {
nextName.setCharAt(lastDot, '$');
try {
return ctx.findClass(nextName.toString());
- } catch(ClassNotFoundException cnfe) {
+ } catch(final ClassNotFoundException cnfe) {
// Intentionally ignored, so the loop retries with the next name
}
}