C# Class Rhino.Tools.Shell.Global

Inheritance: Rhino.ImporterTopLevel
Datei anzeigen Open project: hazzik/Rhino.Net

Public Methods

Method Description
DefineClass ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void

Load a Java class that defines a JavaScript object using the conventions outlined in ScriptableObject.defineClass.

Load a Java class that defines a JavaScript object using the conventions outlined in ScriptableObject.defineClass.

This method is defined as a JavaScript function.

Deserialize ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
Doctest ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object

Example: doctest("js> function f() {\n > return 3;\n > }\njs> f();\n3\n"); returns 2 (since 2 tests were executed).

Example: doctest("js> function f() {\n > return 3;\n > }\njs> f();\n3\n"); returns 2 (since 2 tests were executed).

Gc ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
GetConsole ( Encoding cs ) : ShellConsole
GetErr ( ) : TextWriter
GetIn ( ) : Stream
GetOut ( ) : TextWriter
GetPrompts ( Context cx ) : string[]
Global ( ) : System
Global ( Context cx ) : System
Help ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void

Print a help message.

Print a help message. This method is defined as a JavaScript function.

Init ( Context cx ) : void
Init ( ContextFactory factory ) : void
InitQuitAction ( QuitAction quitAction ) : void

Set the action to call from quit().

Set the action to call from quit().

InstallRequire ( Context cx, IList modulePath, bool sandboxed ) : Require
IsInitialized ( ) : bool
Load ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void

Load and execute a set of JavaScript source files.

Load and execute a set of JavaScript source files. This method is defined as a JavaScript function.

LoadClass ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void

Load and execute a script compiled to a class file.

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.

Print ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object

Print the string values of its arguments.

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.

Quit ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void

Call embedding-specific quit action passing its argument as int32 exit code.

Call embedding-specific quit action passing its argument as int32 exit code. This method is defined as a JavaScript function.

ReadFile ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object

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.

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.
ReadUrl ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object

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.

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.
RunCommand ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object

Execute the specified command with the given argument and options as a separate process and return the exit status of the process.

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.
RunDoctest ( Context cx, Scriptable scope, string session, string sourceName, int lineNumber ) : int
Seal ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void

The seal function seals all supplied arguments.

The seal function seals all supplied arguments.

Serialize ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
SetErr ( TextWriter err ) : void
SetIn ( Stream @in ) : void
SetOut ( TextWriter @out ) : void
SetSealedStdLib ( bool value ) : void
Spawn ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object

The spawn function runs a given function or script in a different thread.

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

Sync ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object

The sync function creates a synchronized function (in the sense of a Java synchronized method) from an existing function.

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 the this object 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

Toint32 ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object

Convert the argument to int32 number.

Convert the argument to int32 number.

Version ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : double

Get and set the language version.

Get and set the language version. This method is defined as a JavaScript function.

Private Methods

Method Description
DoctestOutputMatches ( string expected, string actual ) : bool

Compare actual result of doctest to expected, modulo some acceptable differences.

Compare actual result of doctest to expected, modulo some acceptable differences. Currently just trims the strings before comparing, but should ignore differences in line numbers for error messages for example.

GetCharCodingFromType ( string type ) : string
GetClass ( object args ) : Type
GetInstance ( System.Function function ) : Global
LoadJLine ( Encoding cs ) : bool
Pipe ( bool fromProcess, Stream from, Stream to ) : void
ReadReader ( TextReader reader ) : string
ReadReader ( TextReader reader, int initialBufferSize ) : string
ReadUrl ( string filePath, string charCoding, bool urlIsFile ) : string
ReportRuntimeError ( string msgId ) : Exception
ReportRuntimeError ( string msgId, string msgArg ) : Exception
RunProcess ( string cmd, string environment, Stream @in, Stream @out, Stream err ) : int

Runs the given process using Runtime.exec().

Runs the given process using Runtime.exec(). If any of in, out, err is null, the corresponding process stream will be closed immediately, otherwise it will be closed as soon as all data will be read from/written to process

ToInputStream ( object value ) : Stream
ToOutputStream ( object value ) : Stream

Method Details

DefineClass() public static method

Load a Java class that defines a JavaScript object using the conventions outlined in ScriptableObject.defineClass.
Load a Java class that defines a JavaScript object using the conventions outlined in ScriptableObject.defineClass.

This method is defined as a JavaScript function.

/// IllegalAccessException /// if access is not available /// to a reflected class member /// /// InstantiationException /// if unable to instantiate /// the named class /// /// InvocationTargetException /// if an exception is thrown /// during execution of methods of the named class ///
public static DefineClass ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return void

Deserialize() public static method

public static Deserialize ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

Doctest() public static method

Example: doctest("js> function f() {\n > return 3;\n > }\njs> f();\n3\n"); returns 2 (since 2 tests were executed).
Example: doctest("js> function f() {\n > return 3;\n > }\njs> f();\n3\n"); returns 2 (since 2 tests were executed).
public static Doctest ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

Gc() public static method

public static Gc ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return void

GetConsole() public method

public GetConsole ( Encoding cs ) : ShellConsole
cs System.Text.Encoding
return ShellConsole

GetErr() public method

public GetErr ( ) : TextWriter
return System.IO.TextWriter

GetIn() public method

public GetIn ( ) : Stream
return Stream

GetOut() public method

public GetOut ( ) : TextWriter
return System.IO.TextWriter

GetPrompts() public method

public GetPrompts ( Context cx ) : string[]
cx Rhino.Context
return string[]

Global() public method

public Global ( ) : System
return System

Global() public method

public Global ( Context cx ) : System
cx Rhino.Context
return System

Help() public static method

Print a help message.
Print a help message. This method is defined as a JavaScript function.
public static Help ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return void

Init() public method

public Init ( Context cx ) : void
cx Rhino.Context
return void

Init() public method

public Init ( ContextFactory factory ) : void
factory ContextFactory
return void

InitQuitAction() public method

Set the action to call from quit().
Set the action to call from quit().
public InitQuitAction ( QuitAction quitAction ) : void
quitAction QuitAction
return void

InstallRequire() public method

public InstallRequire ( Context cx, IList modulePath, bool sandboxed ) : Require
cx Rhino.Context
modulePath IList
sandboxed bool
return Rhino.Commonjs.Module.Require

IsInitialized() public method

public IsInitialized ( ) : bool
return bool

Load() public static method

Load and execute a set of JavaScript source files.
Load and execute a set of JavaScript source files. This method is defined as a JavaScript function.
public static Load ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return void

LoadClass() public static method

Load and execute a script compiled to a class file.
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.

/// IllegalAccessException /// if access is not available /// to the class /// /// InstantiationException /// if unable to instantiate /// the named class ///
public static LoadClass ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return void

Print() public static method

Print the string values of its arguments.
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.
public static Print ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

Quit() public static method

Call embedding-specific quit action passing its argument as int32 exit code.
Call embedding-specific quit action passing its argument as int32 exit code. This method is defined as a JavaScript function.
public static Quit ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return void

ReadFile() public static method

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.
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.
public static ReadFile ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

ReadUrl() public static method

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.
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.
public static ReadUrl ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

RunCommand() public static method

Execute the specified command with the given argument and options as a separate process and return the exit status of the process.
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.
public static RunCommand ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

RunDoctest() public method

public RunDoctest ( Context cx, Scriptable scope, string session, string sourceName, int lineNumber ) : int
cx Rhino.Context
scope Scriptable
session string
sourceName string
lineNumber int
return int

Seal() public static method

The seal function seals all supplied arguments.
The seal function seals all supplied arguments.
public static Seal ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return void

Serialize() public static method

public static Serialize ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : void
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return void

SetErr() public method

public SetErr ( TextWriter err ) : void
err System.IO.TextWriter
return void

SetIn() public method

public SetIn ( Stream @in ) : void
@in Stream
return void

SetOut() public method

public SetOut ( TextWriter @out ) : void
@out System.IO.TextWriter
return void

SetSealedStdLib() public method

public SetSealedStdLib ( bool value ) : void
value bool
return void

Spawn() public static method

The spawn function runs a given function or script in a different thread.
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
public static Spawn ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

Sync() public static method

The sync function creates a synchronized function (in the sense of a Java synchronized method) from an existing function.
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 the this object 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
public static Sync ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

Toint32() public static method

Convert the argument to int32 number.
Convert the argument to int32 number.
public static Toint32 ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : object
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return object

Version() public static method

Get and set the language version.
Get and set the language version. This method is defined as a JavaScript function.
public static Version ( Context cx, Scriptable thisObj, object args, System.Function funObj ) : double
cx Rhino.Context
thisObj Scriptable
args object
funObj System.Function
return double