Class Main
- java.lang.Object
-
- org.mozilla.javascript.tools.shell.Main
-
public class Main extends java.lang.Object
The shell program.Can execute scripts interactively or in batch mode at the command line. An example of controlling the JavaScript engine.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Main.IProxy
Proxy class to avoid proliferation of anonymous classes.(package private) static class
Main.ScriptCache
(package private) static class
Main.ScriptReference
-
Field Summary
Fields Modifier and Type Field Description protected static ToolErrorReporter
errorReporter
protected static int
exitCode
private static int
EXITCODE_FILE_NOT_FOUND
private static int
EXITCODE_RUNTIME_ERROR
(package private) static java.util.List<java.lang.String>
fileList
static Global
global
(package private) static java.lang.String
mainModule
(package private) static java.util.List<java.lang.String>
modulePath
(package private) static boolean
processStdin
(package private) static Require
require
(package private) static boolean
sandboxed
private static Main.ScriptCache
scriptCache
private static SecurityProxy
securityImpl
static ShellContextFactory
shellContextFactory
(package private) static boolean
useRequire
-
Constructor Summary
Constructors Constructor Description Main()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static void
evalInlineScript(Context cx, java.lang.String scriptText)
static int
exec(java.lang.String[] origArgs)
Execute the given arguments, but don't System.exit at the end.private static byte[]
getDigest(java.lang.Object source)
static java.io.PrintStream
getErr()
static Global
getGlobal()
static java.io.InputStream
getIn()
static java.io.PrintStream
getOut()
(package private) static Scriptable
getScope(java.lang.String path)
(package private) static Scriptable
getShellScope()
private static void
initJavaPolicySecuritySupport()
private static Script
loadCompiledScript(Context cx, java.lang.String path, byte[] data, java.lang.Object securityDomain)
static void
main(java.lang.String[] args)
Main entry point.private static void
printPromiseWarnings(Context cx)
static void
processFile(Context cx, Scriptable scope, java.lang.String filename)
static void
processFileNoThrow(Context cx, Scriptable scope, java.lang.String filename)
(package private) static void
processFiles(Context cx, java.lang.String[] args)
(package private) static void
processFileSecure(Context cx, Scriptable scope, java.lang.String path, java.lang.Object securityDomain)
static java.lang.String[]
processOptions(java.lang.String[] args)
Parse arguments.static void
processSource(Context cx, java.lang.String filename)
Evaluate JavaScript source.private static java.lang.Object
readFileOrUrl(java.lang.String path, boolean convertToString)
Read file or url specified bypath
.static void
setErr(java.io.PrintStream err)
static void
setIn(java.io.InputStream in)
static void
setOut(java.io.PrintStream out)
-
-
-
Field Detail
-
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:
- Constant Field Values
-
EXITCODE_FILE_NOT_FOUND
private static final int EXITCODE_FILE_NOT_FOUND
- See Also:
- Constant Field Values
-
processStdin
static boolean processStdin
-
fileList
static java.util.List<java.lang.String> fileList
-
modulePath
static java.util.List<java.lang.String> modulePath
-
mainModule
static java.lang.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
-
-
Method Detail
-
main
public static void main(java.lang.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(java.lang.String[] origArgs)
Execute the given arguments, but don't System.exit at the end.
-
processFiles
static void processFiles(Context cx, java.lang.String[] args)
-
evalInlineScript
static void evalInlineScript(Context cx, java.lang.String scriptText)
-
getGlobal
public static Global getGlobal()
-
getShellScope
static Scriptable getShellScope()
-
getScope
static Scriptable getScope(java.lang.String path)
-
processOptions
public static java.lang.String[] processOptions(java.lang.String[] args)
Parse arguments.
-
initJavaPolicySecuritySupport
private static void initJavaPolicySecuritySupport()
-
processSource
public static void processSource(Context cx, java.lang.String filename) throws java.io.IOException
Evaluate JavaScript source.- Parameters:
cx
- the current contextfilename
- the name of the file to compile, or null for interactive mode.- Throws:
java.io.IOException
- if the source could not be readRhinoException
- thrown during evaluation of source
-
processFileNoThrow
public static void processFileNoThrow(Context cx, Scriptable scope, java.lang.String filename)
-
processFile
public static void processFile(Context cx, Scriptable scope, java.lang.String filename) throws java.io.IOException
- Throws:
java.io.IOException
-
processFileSecure
static void processFileSecure(Context cx, Scriptable scope, java.lang.String path, java.lang.Object securityDomain) throws java.io.IOException
- Throws:
java.io.IOException
-
getDigest
private static byte[] getDigest(java.lang.Object source)
-
loadCompiledScript
private static Script loadCompiledScript(Context cx, java.lang.String path, byte[] data, java.lang.Object securityDomain) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
printPromiseWarnings
private static void printPromiseWarnings(Context cx)
-
getIn
public static java.io.InputStream getIn()
-
setIn
public static void setIn(java.io.InputStream in)
-
getOut
public static java.io.PrintStream getOut()
-
setOut
public static void setOut(java.io.PrintStream out)
-
getErr
public static java.io.PrintStream getErr()
-
setErr
public static void setErr(java.io.PrintStream err)
-
readFileOrUrl
private static java.lang.Object readFileOrUrl(java.lang.String path, boolean convertToString) throws java.io.IOException
Read file or url specified bypath
.- Returns:
- file or url content as
byte[]
or asString
ifconvertToString
is true. - Throws:
java.io.IOException
-
-