java.lang.Object
org.mozilla.javascript.tools.shell.Main

public class Main extends Object
The shell program.

Can execute scripts interactively or in batch mode at the command line. An example of controlling the JavaScript engine.

  • Field Details

    • shellContextFactory

      public static ShellContextFactory shellContextFactory
    • global

      public static Global global
    • errorReporter

      protected static ToolErrorReporter errorReporter
    • exitCode

      protected static int exitCode
    • EXITCODE_RUNTIME_ERROR

      private static final int EXITCODE_RUNTIME_ERROR
      See Also:
    • EXITCODE_FILE_NOT_FOUND

      private static final int EXITCODE_FILE_NOT_FOUND
      See Also:
    • processStdin

      static boolean processStdin
    • fileList

      static List<String> fileList
    • modulePath

      static List<String> modulePath
    • mainModule

      static String mainModule
    • sandboxed

      static boolean sandboxed
    • useRequire

      static boolean useRequire
    • require

      static Require require
    • securityImpl

      private static SecurityProxy securityImpl
    • scriptCache

      private static final Main.ScriptCache scriptCache
  • Constructor Details

    • Main

      public Main()
  • Method Details

    • main

      public static void main(String[] args)
      Main entry point.

      Process arguments as would a normal Java program. Also create a new Context and associate it with the current thread. Then set up the execution environment and begin to execute scripts.

    • exec

      public static int exec(String[] origArgs)
      Execute the given arguments, but don't System.exit at the end.
    • processFiles

      static void processFiles(Context cx, String[] args)
    • evalInlineScript

      static void evalInlineScript(Context cx, String scriptText)
    • getGlobal

      public static Global getGlobal()
    • getShellScope

      static Scriptable getShellScope()
    • getScope

      static Scriptable getScope(String path)
    • processOptions

      public static String[] processOptions(String[] args)
      Parse arguments.
    • initJavaPolicySecuritySupport

      private static void initJavaPolicySecuritySupport()
    • processSource

      public static void processSource(Context cx, String filename) throws IOException
      Evaluate JavaScript source.
      Parameters:
      cx - the current context
      filename - the name of the file to compile, or null for interactive mode.
      Throws:
      IOException - if the source could not be read
      RhinoException - thrown during evaluation of source
    • processFileNoThrow

      public static void processFileNoThrow(Context cx, Scriptable scope, String filename)
    • processFile

      public static void processFile(Context cx, Scriptable scope, String filename) throws IOException
      Throws:
      IOException
    • processFileSecure

      static void processFileSecure(Context cx, Scriptable scope, String path, Object securityDomain) throws IOException
      Throws:
      IOException
    • getDigest

      private static byte[] getDigest(Object source)
    • loadCompiledScript

      private static Script loadCompiledScript(Context cx, String path, byte[] data, Object securityDomain) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • printPromiseWarnings

      private static void printPromiseWarnings(Context cx)
    • getIn

      public static InputStream getIn()
    • setIn

      public static void setIn(InputStream in)
    • getOut

      public static PrintStream getOut()
    • setOut

      public static void setOut(PrintStream out)
    • getErr

      public static PrintStream getErr()
    • setErr

      public static void setErr(PrintStream err)
    • readFileOrUrl

      private static Object readFileOrUrl(String path, boolean convertToString) throws IOException
      Read file or url specified by path.
      Returns:
      file or url content as byte[] or as String if convertToString is true.
      Throws:
      IOException