src/jdk/nashorn/internal/runtime/ScriptRuntime.java

Print this page
rev 760 : 8037400: Remove getInitialMap getters and GlobalObject interface
Reviewed-by: lagergren, jlaskey, attila


 457     }
 458 
 459     /**
 460      * Test whether a char is valid JavaScript whitespace
 461      * @param ch a char
 462      * @return true if valid JavaScript whitespace
 463      */
 464     public static boolean isJSWhitespace(final char ch) {
 465         return Lexer.isJSWhitespace(ch);
 466     }
 467 
 468     /**
 469      * Entering a {@code with} node requires new scope. This is the implementation
 470      *
 471      * @param scope      existing scope
 472      * @param expression expression in with
 473      *
 474      * @return {@link WithObject} that is the new scope
 475      */
 476     public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
 477         final ScriptObject global = Context.getGlobalTrusted();
 478         if (expression == UNDEFINED) {
 479             throw typeError(global, "cant.apply.with.to.undefined");
 480         } else if (expression == null) {
 481             throw typeError(global, "cant.apply.with.to.null");
 482         }
 483 
 484         final Object wrappedExpr = JSType.toScriptObject(global, expression);
 485         if (wrappedExpr instanceof ScriptObject) {
 486             return new WithObject(scope, (ScriptObject)wrappedExpr);
 487         }
 488 
 489         throw typeError(global, "cant.apply.with.to.non.scriptobject");
 490     }
 491 
 492     /**
 493      * Exiting a {@code with} node requires restoring scope. This is the implementation
 494      *
 495      * @param scope existing scope
 496      *
 497      * @return restored scope




 457     }
 458 
 459     /**
 460      * Test whether a char is valid JavaScript whitespace
 461      * @param ch a char
 462      * @return true if valid JavaScript whitespace
 463      */
 464     public static boolean isJSWhitespace(final char ch) {
 465         return Lexer.isJSWhitespace(ch);
 466     }
 467 
 468     /**
 469      * Entering a {@code with} node requires new scope. This is the implementation
 470      *
 471      * @param scope      existing scope
 472      * @param expression expression in with
 473      *
 474      * @return {@link WithObject} that is the new scope
 475      */
 476     public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
 477         final Global global = Context.getGlobal();
 478         if (expression == UNDEFINED) {
 479             throw typeError(global, "cant.apply.with.to.undefined");
 480         } else if (expression == null) {
 481             throw typeError(global, "cant.apply.with.to.null");
 482         }
 483 
 484         final Object wrappedExpr = JSType.toScriptObject(global, expression);
 485         if (wrappedExpr instanceof ScriptObject) {
 486             return new WithObject(scope, (ScriptObject)wrappedExpr);
 487         }
 488 
 489         throw typeError(global, "cant.apply.with.to.non.scriptobject");
 490     }
 491 
 492     /**
 493      * Exiting a {@code with} node requires restoring scope. This is the implementation
 494      *
 495      * @param scope existing scope
 496      *
 497      * @return restored scope