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

Print this page




 193      *
 194      * @param key  Property key.
 195      * @param deep Whether the search should look up proto chain.
 196      * @param start the object on which the lookup was originally initiated
 197      *
 198      * @return FindPropertyData or null if not found.
 199      */
 200     @Override
 201     FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) {
 202         // We call findProperty on 'expression' with 'expression' itself as start parameter.
 203         // This way in ScriptObject.setObject we can tell the property is from a 'with' expression
 204         // (as opposed from another non-scope object in the proto chain such as Object.prototype).
 205         final FindProperty exprProperty = expression.findProperty(key, true, expression);
 206         if (exprProperty != null) {
 207              return exprProperty;
 208         }
 209         return super.findProperty(key, deep, start);
 210     }
 211 
 212     @Override













 213     public void setSplitState(final int state) {
 214         getNonWithParent().setSplitState(state);
 215     }
 216 
 217     @Override
 218     public int getSplitState() {
 219         return getNonWithParent().getSplitState();
 220     }
 221 
 222     /**
 223      * Get first parent scope that is not an instance of WithObject.
 224      */
 225     private Scope getNonWithParent() {
 226         ScriptObject proto = getParentScope();
 227 
 228         while (proto != null && proto instanceof WithObject) {
 229             proto = ((WithObject)proto).getParentScope();
 230         }
 231 
 232         assert proto instanceof Scope : "with scope without parent scope";




 193      *
 194      * @param key  Property key.
 195      * @param deep Whether the search should look up proto chain.
 196      * @param start the object on which the lookup was originally initiated
 197      *
 198      * @return FindPropertyData or null if not found.
 199      */
 200     @Override
 201     FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) {
 202         // We call findProperty on 'expression' with 'expression' itself as start parameter.
 203         // This way in ScriptObject.setObject we can tell the property is from a 'with' expression
 204         // (as opposed from another non-scope object in the proto chain such as Object.prototype).
 205         final FindProperty exprProperty = expression.findProperty(key, true, expression);
 206         if (exprProperty != null) {
 207              return exprProperty;
 208         }
 209         return super.findProperty(key, deep, start);
 210     }
 211 
 212     @Override
 213     protected Object invokeNoSuchProperty(final String name, final int programPoint) {
 214         FindProperty find = expression.findProperty(NO_SUCH_PROPERTY_NAME, true);
 215         if (find != null) {
 216             final Object func = find.getObjectValue();
 217             if (func instanceof ScriptFunction) {
 218                 return ScriptRuntime.apply((ScriptFunction)func, expression, name);
 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";