B2G/gecko/testing/marionette/marionette-server.js
/**
   * Executes a script in the given sandbox.
   *
   * @param Sandbox sandbox
   *        Sandbox in which the script will run
   * @param string script
   *        The script to run
   * @param boolean directInject
   *        If true, then the script will be run as is,
   *        and not as a function body (as you would
   *        do using the WebDriver spec)
   * @param boolean async
   *        True if the script is asynchronous
   */
Executes a script in the given sandbox.
@param Sandbox sandbox
Sandbox in which the script will run
@param string script
The script to run
@param boolean directInject
If true, then the script will be run as is,
and not as a function body (as you would
do using the WebDriver spec)
@param boolean async
True if the script is asynchronous
Executes a script in the given sandbox . @param Sandbox sandbox Sandbox in which the script will run @param string script The script to run @param boolean directInject If true then the script will be run as is and not as a function body ( as you would do using the WebDriver spec ) @param boolean async True if the script is asynchronous
function MDA_executeScriptInSandbox(sandbox, script,
     directInject, async, command_id, timeout) {
    if (directInject && async &&
        (timeout == null || timeout == 0)) {
      this.sendError("Please set a timeout", 21, null, command_id);
      return;
    }
    if (this.importedScripts.exists()) {
      let stream = Cc["@mozilla.org/network/file-input-stream;1"].  
                    createInstance(Ci.nsIFileInputStream);
      stream.init(this.importedScripts, -1, 0, 0);
      let data = NetUtil.readInputStreamToString(stream, stream.available());
      script = data + script;
    }
    let res = Cu.evalInSandbox(script, sandbox, "1.8", "dummy file", 0);
    if (directInject && !async &&
        (res == undefined || res.passed == undefined)) {
      this.sendError("finish() not called", 500, null, command_id);
      return;
    }
    if (!async) {
      this.sendResponse(this.curBrowser.elementManager.wrapValue(res),
                        command_id);
    }
  }
function MDA_executeScriptInSandbox ( sandbox , script , directInject , async , command_id , timeout ) { if ( directInject && async && ( timeout == null || timeout == 0 ) ) { this . sendError ( "Please set a timeout" , 21 , null , command_id ) ; return ; } if ( this . importedScripts . exists ( ) ) { let stream = Cc [ "@mozilla.org/network/file-input-stream;1" ] . createInstance ( Ci . nsIFileInputStream ) ; stream . init ( this . importedScripts , - 1 , 0 , 0 ) ; let data = NetUtil . readInputStreamToString ( stream , stream . available ( ) ) ; script = data + script ; } let res = Cu . evalInSandbox ( script , sandbox , "1.8" , "dummy file" , 0 ) ; if ( directInject && ! async && ( res == undefined || res . passed == undefined ) ) { this . sendError ( "finish() not called" , 500 , null , command_id ) ; return ; } if ( ! async ) { this . sendResponse ( this . curBrowser . elementManager . wrapValue ( res ) , command_id ) ; } }
Executes a script in the given sandbox.
Executes a script in the given sandbox .