Class BasicRhinoShell

java.lang.Object
org.mozilla.javascript.ScriptableObject
org.codelibs.maven.yuicompressor.BasicRhinoShell
All Implemented Interfaces:
Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable, org.mozilla.javascript.SymbolScriptable

public class BasicRhinoShell extends org.mozilla.javascript.ScriptableObject
Basic Rhino Shell for executing JavaScript.

Can execute scripts interactively or in batch mode at the command line. Based on Mozilla Rhino's BasicRhinoShell example.

Author:
Norris Boyd, David Bernard, CodeLibs Project
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObject

    org.mozilla.javascript.ScriptableObject.KeyComparator
  • Field Summary

    Fields inherited from class org.mozilla.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

    Fields inherited from interface org.mozilla.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    exec(String[] args, org.mozilla.javascript.ErrorReporter reporter)
    Main entry point for executing JavaScript.
     
    void
    Display help message.
    static void
    load(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
    Load and execute JavaScript source files.
    static void
    print(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
    Print the string values of arguments.
    static String[]
    processOptions(org.mozilla.javascript.Context cx, String[] args)
    Parse and process command line options.
    void
    Quit the shell (only affects interactive mode).
    Read a file and return its contents as a string.
    static double
    version(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
    Get and set the JavaScript language version.
    static void
    warn(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
    Report a warning.

    Methods inherited from class org.mozilla.javascript.ScriptableObject

    applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChangeForSlot, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, equivalentValues, get, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, has, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, put, putConst, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BasicRhinoShell

      public BasicRhinoShell()
  • Method Details

    • getClassName

      public String getClassName()
      Specified by:
      getClassName in interface org.mozilla.javascript.Scriptable
      Specified by:
      getClassName in class org.mozilla.javascript.ScriptableObject
    • exec

      public static void exec(String[] args, org.mozilla.javascript.ErrorReporter reporter)
      Main entry point for executing JavaScript.

      Process arguments and set up the execution environment.

      Parameters:
      args - command line arguments
      reporter - error reporter for JavaScript errors
    • processOptions

      public static String[] processOptions(org.mozilla.javascript.Context cx, String[] args)
      Parse and process command line options.
      Parameters:
      cx - the JavaScript context
      args - command line arguments
      Returns:
      remaining arguments after options are processed
    • help

      public void help()
      Display help message.

      This method is defined as a JavaScript function.

    • print

      public static void print(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
      Print the string values of arguments.

      This method is defined as a JavaScript function.

    • quit

      public void quit()
      Quit the shell (only affects interactive mode).

      This method is defined as a JavaScript function.

    • warn

      public static void warn(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
      Report a warning.

      This method is defined as a JavaScript function.

    • readFile

      public String readFile(String path)
      Read a file and return its contents as a string.

      This method is defined as a JavaScript function.

      Parameters:
      path - the file path
      Returns:
      file contents
      Throws:
      RuntimeException - if file cannot be read
    • version

      public static double version(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
      Get and set the JavaScript language version.

      This method is defined as a JavaScript function.

    • load

      public static void load(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
      Load and execute JavaScript source files.

      This method is defined as a JavaScript function.