Class Global
- java.lang.Object
- 
- org.mozilla.javascript.ScriptableObject
- 
- org.mozilla.javascript.IdScriptableObject
- 
- org.mozilla.javascript.TopLevel
- 
- org.mozilla.javascript.ImporterTopLevel
- 
- org.mozilla.javascript.tools.shell.Global
 
 
 
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- ConstProperties,- DebuggableObject,- IdFunctionCall,- Scriptable,- SymbolScriptable
 
 public class Global extends ImporterTopLevel This class provides for sharing functions across multiple threads. This is of particular interest to server applications.- See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.mozilla.javascript.TopLevelTopLevel.Builtins
 - 
Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObjectScriptableObject.KeyComparator
 
- 
 - 
Field Summary- 
Fields inherited from class org.mozilla.javascript.ScriptableObjectCONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 - 
Fields inherited from interface org.mozilla.javascript.ScriptableNOT_FOUND
 
- 
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voiddefineClass(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Load a Java class that defines a JavaScript object using the conventions outlined in ScriptableObject.defineClass.static java.lang.Objectdeserialize(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)static java.lang.Objectdoctest(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Example: doctest("js> function f() {\n > return 3;\n > }\njs> f();\n3\n"); returns 2 (since 2 tests were executed).static voidgc(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)ShellConsolegetConsole(java.nio.charset.Charset cs)java.io.PrintStreamgetErr()java.io.InputStreamgetIn()java.io.PrintStreamgetOut()java.lang.String[]getPrompts(Context cx)static voidhelp(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Print a help message.voidinit(Context cx)voidinit(ContextFactory factory)voidinitQuitAction(QuitAction quitAction)Set the action to call from quit().RequireinstallRequire(Context cx, java.util.List<java.lang.String> modulePath, boolean sandboxed)booleanisInitialized()static voidload(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Load and execute a set of JavaScript source files.static voidloadClass(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Load and execute a script compiled to a class file.static java.lang.Objectprint(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Print the string values of its arguments.static voidquit(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Call embedding-specific quit action passing its argument as int32 exit code.static java.lang.ObjectreadFile(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)The readFile reads the given file content and convert it to a string using the specified character coding or default character coding if explicit coding argument is not given.static java.lang.Objectreadline(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)The readline reads one line from the standard input.static java.lang.ObjectreadUrl(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)The readUrl opens connection to the given URL, read all its data and converts them to a string using the specified character coding or default character coding if explicit coding argument is not given.static java.lang.ObjectrunCommand(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Execute the specified command with the given argument and options as a separate process and return the exit status of the process.intrunDoctest(Context cx, Scriptable scope, java.lang.String session, java.lang.String sourceName, int lineNumber)static voidseal(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)The seal function seals all supplied arguments.static voidserialize(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)voidsetErr(java.io.PrintStream err)voidsetIn(java.io.InputStream in)voidsetOut(java.io.PrintStream out)voidsetSealedStdLib(boolean value)static java.lang.Objectspawn(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)The spawn function runs a given function or script in a different thread.static java.lang.Objectsync(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)The sync function creates a synchronized function (in the sense of a Java synchronized method) from an existing function.static java.lang.Objecttoint32(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Convert the argument to int32 number.static doubleversion(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Get and set the language version.static java.lang.Objectwrite(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)Print just as in "print," but without the trailing newline.- 
Methods inherited from class org.mozilla.javascript.ImporterTopLevelexecIdCall, findPrototypeId, get, getClassName, has, importPackage, init, initPrototypeId, initStandardObjects
 - 
Methods inherited from class org.mozilla.javascript.TopLevelcacheBuiltins, getBuiltinCtor, getBuiltinCtor, getBuiltinPrototype, getBuiltinPrototype
 - 
Methods inherited from class org.mozilla.javascript.IdScriptableObjectactivatePrototypeMap, addIdFunctionProperty, defaultGet, defaultHas, defaultPut, defineOwnProperty, delete, delete, ensureType, exportAsJSClass, fillConstructorProperties, findInstanceIdInfo, findInstanceIdInfo, findPrototypeId, get, getAttributes, getAttributes, getInstanceIdName, getInstanceIdValue, getMaxInstanceId, getOwnPropertyDescriptor, has, hasPrototypeMap, initPrototypeConstructor, initPrototypeMethod, initPrototypeMethod, initPrototypeMethod, initPrototypeValue, initPrototypeValue, instanceIdInfo, put, put, setAttributes, setInstanceIdAttributes, setInstanceIdValue
 - 
Methods inherited from class org.mozilla.javascript.ScriptableObjectapplyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, equivalentValues, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
 
- 
 
- 
- 
- 
Constructor Detail- 
Globalpublic Global() 
 - 
Globalpublic Global(Context cx) 
 
- 
 - 
Method Detail- 
isInitializedpublic boolean isInitialized() 
 - 
initQuitActionpublic void initQuitAction(QuitAction quitAction) Set the action to call from quit().
 - 
initpublic void init(ContextFactory factory) 
 - 
initpublic void init(Context cx) 
 - 
installRequirepublic Require installRequire(Context cx, java.util.List<java.lang.String> modulePath, boolean sandboxed) 
 - 
helppublic static void help(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) Print a help message.This method is defined as a JavaScript function. 
 - 
gcpublic static void gc(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) 
 - 
printpublic static java.lang.Object print(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) Print the string values of its arguments.This method is defined as a JavaScript function. Note that its arguments are of the "varargs" form, which allows it to handle an arbitrary number of arguments supplied to the JavaScript function. 
 - 
writepublic static java.lang.Object write(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) Print just as in "print," but without the trailing newline.
 - 
quitpublic static void quit(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) Call embedding-specific quit action passing its argument as int32 exit code.This method is defined as a JavaScript function. 
 - 
versionpublic static double version(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) Get and set the language version.This method is defined as a JavaScript function. 
 - 
loadpublic static void load(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) Load and execute a set of JavaScript source files.This method is defined as a JavaScript function. 
 - 
defineClasspublic static void defineClass(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.reflect.InvocationTargetException Load a Java class that defines a JavaScript object using the conventions outlined in ScriptableObject.defineClass.This method is defined as a JavaScript function. - Throws:
- java.lang.IllegalAccessException- if access is not available to a reflected class member
- java.lang.InstantiationException- if unable to instantiate the named class
- java.lang.reflect.InvocationTargetException- if an exception is thrown during execution of methods of the named class
- See Also:
- ScriptableObject.defineClass(Scriptable,Class)
 
 - 
loadClasspublic static void loadClass(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException Load and execute a script compiled to a class file.This method is defined as a JavaScript function. When called as a JavaScript function, a single argument is expected. This argument should be the name of a class that implements the Script interface, as will any script compiled by jsc. - Throws:
- java.lang.IllegalAccessException- if access is not available to the class
- java.lang.InstantiationException- if unable to instantiate the named class
- java.lang.NoSuchMethodException
- java.lang.reflect.InvocationTargetException
 
 - 
serializepublic static void serialize(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
deserializepublic static java.lang.Object deserialize(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws java.io.IOException, java.lang.ClassNotFoundException - Throws:
- java.io.IOException
- java.lang.ClassNotFoundException
 
 - 
getPromptspublic java.lang.String[] getPrompts(Context cx) 
 - 
doctestpublic static java.lang.Object doctest(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) Example: doctest("js> function f() {\n > return 3;\n > }\njs> f();\n3\n"); returns 2 (since 2 tests were executed).
 - 
runDoctestpublic int runDoctest(Context cx, Scriptable scope, java.lang.String session, java.lang.String sourceName, int lineNumber) 
 - 
spawnpublic static java.lang.Object spawn(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) The spawn function runs a given function or script in a different thread.js> function g() { a = 7; } js> a = 3; 3 js> spawn(g) Thread[Thread-1,5,main] js> a 3 
 - 
syncpublic static java.lang.Object sync(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) The sync function creates a synchronized function (in the sense of a Java synchronized method) from an existing function. The new function synchronizes on the the second argument if it is defined, or otherwise thethisobject of its invocation. js> var o = { f : sync(function(x) { print("entry"); Packages.java.lang.Thread.sleep(x*1000); print("exit"); })}; js> spawn(function() {o.f(5);}); Thread[Thread-0,5,main] entry js> spawn(function() {o.f(5);}); Thread[Thread-1,5,main] js> exit entry exit
 - 
runCommandpublic static java.lang.Object runCommand(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws java.io.IOException Execute the specified command with the given argument and options as a separate process and return the exit status of the process.Usage: runCommand(command) runCommand(command, arg1, ..., argN) runCommand(command, arg1, ..., argN, options) All except the last arguments to runCommand are converted to strings and denote command name and its arguments. If the last argument is a JavaScript object, it is an option object. Otherwise it is converted to string denoting the last argument and options objects assumed to be empty. The following properties of the option object are processed:- args- provides an array of additional command arguments
- env- explicit environment object. All its enumerable properties define the corresponding environment variable names.
- input- the process input. If it is not java.io.InputStream, it is converted to string and sent to the process as its input. If not specified, no input is provided to the process.
- output- the process output instead of java.lang.System.out. If it is not instance of java.io.OutputStream, the process output is read, converted to a string, appended to the output property value converted to string and put as the new value of the output property.
- err- the process error output instead of java.lang.System.err. If it is not instance of java.io.OutputStream, the process error output is read, converted to a string, appended to the err property value converted to string and put as the new value of the err property.
- dir- the working direcotry to run the commands.
 - Throws:
- java.io.IOException
 
 - 
sealpublic static void seal(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) The seal function seals all supplied arguments.
 - 
readFilepublic static java.lang.Object readFile(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws java.io.IOException The readFile reads the given file content and convert it to a string using the specified character coding or default character coding if explicit coding argument is not given.Usage: readFile(filePath) readFile(filePath, charCoding) The first form converts file's context to string using the default character coding.- Throws:
- java.io.IOException
 
 - 
readUrlpublic static java.lang.Object readUrl(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws java.io.IOException The readUrl opens connection to the given URL, read all its data and converts them to a string using the specified character coding or default character coding if explicit coding argument is not given.Usage: readUrl(url) readUrl(url, charCoding) The first form converts file's context to string using the default charCoding.- Throws:
- java.io.IOException
 
 - 
toint32public static java.lang.Object toint32(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) Convert the argument to int32 number.
 - 
getConsolepublic ShellConsole getConsole(java.nio.charset.Charset cs) 
 - 
getInpublic java.io.InputStream getIn() 
 - 
setInpublic void setIn(java.io.InputStream in) 
 - 
getOutpublic java.io.PrintStream getOut() 
 - 
setOutpublic void setOut(java.io.PrintStream out) 
 - 
getErrpublic java.io.PrintStream getErr() 
 - 
setErrpublic void setErr(java.io.PrintStream err) 
 - 
setSealedStdLibpublic void setSealedStdLib(boolean value) 
 - 
readlinepublic static java.lang.Object readline(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws java.io.IOException The readline reads one line from the standard input. "Prompt" is optional.Usage: readline(prompt) - Throws:
- java.io.IOException
 
 
- 
 
-