Interface IJavascriptRuntime

All Known Implementing Classes:
JavascriptRuntime

public interface IJavascriptRuntime
An interface for interacting with a JavaScript environment which includes methods for building strings that represent functions and constructors as well as providing a means to execute commands.
Author:
Rob Terpilowski
  • Method Summary

    Modifier and Type Method Description
    JSObject execute​(String command)
    Execute the specified command returning a value (if any)
    String getArrayConstructor​(String javascriptObjectType, Object[] ary)
    Gets an array parameter constructor as a String, which then can be passed to the execute() method.
    String getArrayFunction​(String function, Object[] ary)
    Gets an array function as a String, which then can be passed to the execute() method.
    String getConstructor​(String javascriptObjectType, Object... args)
    Gets a constructor as a string which then can be passed to the execute().
    String getFunction​(String function, Object... args)
    Gets a function as a String, which then can be passed to the execute() method.
    String getFunction​(String variable, String function, Object... args)
    Gets a function as a String, which then can be passed to the execute() method.
  • Method Details

    • execute

      JSObject execute​(String command)
      Execute the specified command returning a value (if any)
      Parameters:
      command - The JavaScript command to execute
      Returns:
      The underlying JavaScript object that was returned by the script.
    • getConstructor

      String getConstructor​(String javascriptObjectType, Object... args)
      Gets a constructor as a string which then can be passed to the execute().
      Parameters:
      javascriptObjectType - The type of JavaScript object to create
      args - The args of the constructor
      Returns:
      A string which can be passed to the JavaScript environment to create a new object.
    • getArrayConstructor

      String getArrayConstructor​(String javascriptObjectType, Object[] ary)
      Gets an array parameter constructor as a String, which then can be passed to the execute() method. Note, this is where the parameter to the constructor is an array, rather than the varargs which are broken down into separate parameters.
      Parameters:
      javascriptObjectType - type The type of JavaScript object array to create
      ary - The array elements
      Returns:
      A string which can be passed to the JavaScript environment to create a new array.
    • getFunction

      String getFunction​(String variable, String function, Object... args)
      Gets a function as a String, which then can be passed to the execute() method.
      Parameters:
      variable - The variable to invoke the function on.
      function - The function to invoke
      args - Arguments the function requires
      Returns:
      A string which can be passed to the JavaScript environment to invoke the function
    • getFunction

      String getFunction​(String function, Object... args)
      Gets a function as a String, which then can be passed to the execute() method.
      Parameters:
      function - The function to invoke
      args - Arguments the function requires
      Returns:
      A string which can be passed to the JavaScript environment to invoke the function
    • getArrayFunction

      String getArrayFunction​(String function, Object[] ary)
      Gets an array function as a String, which then can be passed to the execute() method.
      Parameters:
      function - The function to invoke
      ary - The array of arguments to pass to the function.
      Returns:
      A string which can be passed to the JavaScript environment to invoke the function