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

Print this page




 219             }
 220         }
 221 
 222         return getProto().invokeNoSuchProperty(name, programPoint);
 223     }
 224 
 225     @Override
 226     public void setSplitState(final int state) {
 227         getNonWithParent().setSplitState(state);
 228     }
 229 
 230     @Override
 231     public int getSplitState() {
 232         return getNonWithParent().getSplitState();
 233     }
 234 
 235     /**
 236      * Get first parent scope that is not an instance of WithObject.
 237      */
 238     private Scope getNonWithParent() {
 239         ScriptObject proto = getParentScope();
 240 
 241         while (proto != null && proto instanceof WithObject) {
 242             proto = ((WithObject)proto).getParentScope();
 243         }
 244 
 245         assert proto instanceof Scope : "with scope without parent scope";
 246         return (Scope) proto;
 247     }
 248 
 249 
 250     private static GuardedInvocation fixReceiverType(final GuardedInvocation link, final MethodHandle filter) {
 251         // The receiver may be an Object or a ScriptObject.
 252         final MethodType invType = link.getInvocation().type();
 253         final MethodType newInvType = invType.changeParameterType(0, filter.type().returnType());
 254         return link.asType(newInvType);
 255     }
 256 
 257     private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) {
 258         // If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its
 259         // expression.
 260         if (!"getMethod".equals(desc.getFirstOperator())) {
 261             return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER);
 262         }


 361     @SuppressWarnings("unused")
 362     private static boolean withExpressionGuard(final Object receiver, final PropertyMap map, final SwitchPoint sp) {
 363         return ((WithObject)receiver).expression.getMap() == map && (sp == null || !sp.hasBeenInvalidated());
 364     }
 365 
 366     /**
 367      * Drops the WithObject wrapper from the scope.
 368      * @param receiver WithObject wrapper.
 369      * @return The with scope.
 370      */
 371     public static Object withFilterScope(final Object receiver) {
 372         return ((WithObject)receiver).getProto();
 373     }
 374 
 375     /**
 376      * Get the with expression for this {@code WithObject}
 377      * @return the with expression
 378      */
 379     public ScriptObject getExpression() {
 380         return expression;
 381     }
 382 
 383     /**
 384      * Get the parent scope for this {@code WithObject}
 385      * @return the parent scope
 386      */
 387     public ScriptObject getParentScope() {
 388         return getProto();
 389     }
 390 
 391     private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
 392         return MH.findStatic(MethodHandles.lookup(), WithObject.class, name, MH.type(rtype, types));
 393     }
 394 }


 219             }
 220         }
 221 
 222         return getProto().invokeNoSuchProperty(name, programPoint);
 223     }
 224 
 225     @Override
 226     public void setSplitState(final int state) {
 227         getNonWithParent().setSplitState(state);
 228     }
 229 
 230     @Override
 231     public int getSplitState() {
 232         return getNonWithParent().getSplitState();
 233     }
 234 
 235     /**
 236      * Get first parent scope that is not an instance of WithObject.
 237      */
 238     private Scope getNonWithParent() {
 239         ScriptObject proto = getProto();
 240 
 241         while (proto != null && proto instanceof WithObject) {
 242             proto = proto.getProto();
 243         }
 244 
 245         assert proto instanceof Scope : "with scope without parent scope";
 246         return (Scope) proto;
 247     }
 248 
 249 
 250     private static GuardedInvocation fixReceiverType(final GuardedInvocation link, final MethodHandle filter) {
 251         // The receiver may be an Object or a ScriptObject.
 252         final MethodType invType = link.getInvocation().type();
 253         final MethodType newInvType = invType.changeParameterType(0, filter.type().returnType());
 254         return link.asType(newInvType);
 255     }
 256 
 257     private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) {
 258         // If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its
 259         // expression.
 260         if (!"getMethod".equals(desc.getFirstOperator())) {
 261             return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER);
 262         }


 361     @SuppressWarnings("unused")
 362     private static boolean withExpressionGuard(final Object receiver, final PropertyMap map, final SwitchPoint sp) {
 363         return ((WithObject)receiver).expression.getMap() == map && (sp == null || !sp.hasBeenInvalidated());
 364     }
 365 
 366     /**
 367      * Drops the WithObject wrapper from the scope.
 368      * @param receiver WithObject wrapper.
 369      * @return The with scope.
 370      */
 371     public static Object withFilterScope(final Object receiver) {
 372         return ((WithObject)receiver).getProto();
 373     }
 374 
 375     /**
 376      * Get the with expression for this {@code WithObject}
 377      * @return the with expression
 378      */
 379     public ScriptObject getExpression() {
 380         return expression;








 381     }
 382 
 383     private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
 384         return MH.findStatic(MethodHandles.lookup(), WithObject.class, name, MH.type(rtype, types));
 385     }
 386 }