< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java

Print this page




  27 
  28 import static jdk.nashorn.internal.lookup.Lookup.MH;
  29 
  30 import java.lang.invoke.MethodHandle;
  31 import java.lang.invoke.MethodHandles;
  32 import java.lang.invoke.MethodType;
  33 import java.lang.invoke.SwitchPoint;
  34 import jdk.internal.dynalink.CallSiteDescriptor;
  35 import jdk.internal.dynalink.linker.GuardedInvocation;
  36 import jdk.internal.dynalink.linker.LinkRequest;
  37 import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
  38 import jdk.nashorn.api.scripting.AbstractJSObject;
  39 import jdk.nashorn.api.scripting.ScriptObjectMirror;
  40 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
  41 import jdk.nashorn.internal.runtime.linker.NashornGuards;
  42 
  43 /**
  44  * This class supports the handling of scope in a with body.
  45  *
  46  */
  47 public final class WithObject extends ScriptObject implements Scope {
  48     private static final MethodHandle WITHEXPRESSIONGUARD    = findOwnMH("withExpressionGuard",  boolean.class, Object.class, PropertyMap.class, SwitchPoint.class);
  49     private static final MethodHandle WITHEXPRESSIONFILTER   = findOwnMH("withFilterExpression", Object.class, Object.class);
  50     private static final MethodHandle WITHSCOPEFILTER        = findOwnMH("withFilterScope",      Object.class, Object.class);
  51     private static final MethodHandle BIND_TO_EXPRESSION_OBJ = findOwnMH("bindToExpression",     Object.class, Object.class, Object.class);
  52     private static final MethodHandle BIND_TO_EXPRESSION_FN  = findOwnMH("bindToExpression",     Object.class, ScriptFunction.class, Object.class);
  53 
  54     /** With expression object. */
  55     private final ScriptObject expression;
  56 
  57     /**
  58      * Constructor
  59      *
  60      * @param scope scope object
  61      * @param expression with expression
  62      */
  63     WithObject(final ScriptObject scope, final ScriptObject expression) {
  64         super(scope, null);
  65         setIsScope();
  66         this.expression = expression;
  67     }
  68 
  69     /**
  70      * Delete a property based on a key.
  71      * @param key Any valid JavaScript value.
  72      * @param strict strict mode execution.
  73      * @return True if deleted.
  74      */
  75     @Override
  76     public boolean delete(final Object key, final boolean strict) {
  77         final ScriptObject self = expression;
  78         final String propName = JSType.toString(key);
  79 
  80         final FindProperty find = self.findProperty(propName, true);
  81 
  82         if (find != null) {
  83             return self.delete(propName, strict);
  84         }
  85 




  27 
  28 import static jdk.nashorn.internal.lookup.Lookup.MH;
  29 
  30 import java.lang.invoke.MethodHandle;
  31 import java.lang.invoke.MethodHandles;
  32 import java.lang.invoke.MethodType;
  33 import java.lang.invoke.SwitchPoint;
  34 import jdk.internal.dynalink.CallSiteDescriptor;
  35 import jdk.internal.dynalink.linker.GuardedInvocation;
  36 import jdk.internal.dynalink.linker.LinkRequest;
  37 import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
  38 import jdk.nashorn.api.scripting.AbstractJSObject;
  39 import jdk.nashorn.api.scripting.ScriptObjectMirror;
  40 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
  41 import jdk.nashorn.internal.runtime.linker.NashornGuards;
  42 
  43 /**
  44  * This class supports the handling of scope in a with body.
  45  *
  46  */
  47 public final class WithObject extends Scope {
  48     private static final MethodHandle WITHEXPRESSIONGUARD    = findOwnMH("withExpressionGuard",  boolean.class, Object.class, PropertyMap.class, SwitchPoint.class);
  49     private static final MethodHandle WITHEXPRESSIONFILTER   = findOwnMH("withFilterExpression", Object.class, Object.class);
  50     private static final MethodHandle WITHSCOPEFILTER        = findOwnMH("withFilterScope",      Object.class, Object.class);
  51     private static final MethodHandle BIND_TO_EXPRESSION_OBJ = findOwnMH("bindToExpression",     Object.class, Object.class, Object.class);
  52     private static final MethodHandle BIND_TO_EXPRESSION_FN  = findOwnMH("bindToExpression",     Object.class, ScriptFunction.class, Object.class);
  53 
  54     /** With expression object. */
  55     private final ScriptObject expression;
  56 
  57     /**
  58      * Constructor
  59      *
  60      * @param scope scope object
  61      * @param expression with expression
  62      */
  63     WithObject(final ScriptObject scope, final ScriptObject expression) {
  64         super(scope, null);

  65         this.expression = expression;
  66     }
  67 
  68     /**
  69      * Delete a property based on a key.
  70      * @param key Any valid JavaScript value.
  71      * @param strict strict mode execution.
  72      * @return True if deleted.
  73      */
  74     @Override
  75     public boolean delete(final Object key, final boolean strict) {
  76         final ScriptObject self = expression;
  77         final String propName = JSType.toString(key);
  78 
  79         final FindProperty find = self.findProperty(propName, true);
  80 
  81         if (find != null) {
  82             return self.delete(propName, strict);
  83         }
  84 


< prev index next >