src/jdk/nashorn/internal/runtime/linker/NashornGuards.java

Print this page

        

@@ -29,10 +29,11 @@
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.ref.WeakReference;
 import jdk.internal.dynalink.CallSiteDescriptor;
+import jdk.nashorn.api.scripting.JSObject;
 import jdk.nashorn.internal.codegen.ObjectClassGenerator;
 import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.Property;
 import jdk.nashorn.internal.runtime.PropertyMap;
 import jdk.nashorn.internal.runtime.ScriptFunction;

@@ -41,10 +42,11 @@
 /**
  * Constructor of method handles used to guard call sites.
  */
 public final class NashornGuards {
     private static final MethodHandle IS_SCRIPTOBJECT   = findOwnMH("isScriptObject", boolean.class, Object.class);
+    private static final MethodHandle IS_NOT_JSOBJECT   = findOwnMH("isNotJSObject", boolean.class, Object.class);
     private static final MethodHandle IS_SCRIPTFUNCTION = findOwnMH("isScriptFunction", boolean.class, Object.class);
     private static final MethodHandle IS_MAP            = findOwnMH("isMap", boolean.class, Object.class, PropertyMap.class);
     private static final MethodHandle SAME_OBJECT       = findOwnMH("sameObject", boolean.class, Object.class, WeakReference.class);
     private static final MethodHandle IS_INSTANCEOF_2   = findOwnMH("isInstanceOf2", boolean.class, Object.class, Class.class, Class.class);
 

@@ -59,10 +61,18 @@
     public static MethodHandle getScriptObjectGuard() {
         return IS_SCRIPTOBJECT;
     }
 
     /**
+     * Get the guard that checks if an item is not a {@code JSObject}
+     * @return method handle for guard
+     */
+    public static MethodHandle getNotJSObjectGuard() {
+        return IS_NOT_JSOBJECT;
+    }
+
+    /**
      * Get the guard that checks if an item is a {@code ScriptFunction}
      * @return method handle for guard
      */
     public static MethodHandle getScriptFunctionGuard() {
         return IS_SCRIPTFUNCTION;

@@ -155,10 +165,15 @@
     private static boolean isScriptObject(final Object self) {
         return self instanceof ScriptObject;
     }
 
     @SuppressWarnings("unused")
+    private static boolean isNotJSObject(final Object self) {
+        return !(self instanceof JSObject);
+    }
+
+    @SuppressWarnings("unused")
     private static boolean isScriptFunction(final Object self) {
         return self instanceof ScriptFunction;
     }
 
     @SuppressWarnings("unused")