Class Global

    • Constructor Detail

      • Global

        public Global()
      • Global

        public Global​(Context cx)
    • Method Detail

      • isInitialized

        public boolean isInitialized()
      • initQuitAction

        public void initQuitAction​(QuitAction quitAction)
        Set the action to call from quit().
      • init

        public void init​(Context cx)
      • help

        public static void help​(Context cx,
                                Scriptable thisObj,
                                Object[] args,
                                Function funObj)
        Print a help message. This method is defined as a JavaScript function.
      • print

        public static Object print​(Context cx,
                                   Scriptable thisObj,
                                   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.
      • quit

        public static void quit​(Context cx,
                                Scriptable thisObj,
                                Object[] args,
                                Function funObj)
        Call embedding-specific quit action passing its argument as int32 exit code. This method is defined as a JavaScript function.
      • version

        public static double version​(Context cx,
                                     Scriptable thisObj,
                                     Object[] args,
                                     Function funObj)
        Get and set the language version. This method is defined as a JavaScript function.
      • load

        public static void load​(Context cx,
                                Scriptable thisObj,
                                Object[] args,
                                Function funObj)
        Load and execute a set of JavaScript source files. This method is defined as a JavaScript function.
      • doctest

        public static Object doctest​(Context cx,
                                     Scriptable thisObj,
                                     Object[] args,
                                     Function funObj)
        Example: doctest("js> function f() {\n > return 3;\n > }\njs> f();\n3\n"); returns 2 (since 2 tests were executed).
      • spawn

        public static Object spawn​(Context cx,
                                   Scriptable thisObj,
                                   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
      • sync

        public static Object sync​(Context cx,
                                  Scriptable thisObj,
                                  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 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
      • runCommand

        public static Object runCommand​(Context cx,
                                        Scriptable thisObj,
                                        Object[] args,
                                        Function funObj)
                                 throws 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:
        IOException
      • readFile

        public static Object readFile​(Context cx,
                                      Scriptable thisObj,
                                      Object[] args,
                                      Function funObj)
                               throws 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:
        IOException
      • readUrl

        public static Object readUrl​(Context cx,
                                     Scriptable thisObj,
                                     Object[] args,
                                     Function funObj)
                              throws 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:
        IOException
      • setSealedStdLib

        public void setSealedStdLib​(boolean value)