B2G/gecko/testing/marionette/marionette-server.js
/**
   * Execute the given script either as a function body (executeScript)
   * or directly (for 'mochitest' like JS Marionette tests)
   *
   * @param object aRequest
   *        'value' member is the script to run
   *        'args' member holds the arguments to the script
   * @param boolean directInject
   *        if true, it will be run directly and not as a 
   *        function body
   */
Execute the given script either as a function body (executeScript)
or directly (for 'mochitest' like JS Marionette tests)

@param object aRequest
'value' member is the script to run
'args' member holds the arguments to the script
@param boolean directInject
if true, it will be run directly and not as a
function body
Execute the given script either as a function body ( executeScript ) or directly ( for ' mochitest ' like JS Marionette tests ) @param object aRequest ' value ' member is the script to run ' args ' member holds the arguments to the script @param boolean directInject if true it will be run directly and not as a function body
function MDA_execute(aRequest, directInject) {
    let timeout = aRequest.scriptTimeout ? aRequest.scriptTimeout : this.scriptTimeout;
    let command_id = this.command_id = this.getCommandId();
    let script;
    this.logRequest("execute", aRequest);
    if (aRequest.newSandbox == undefined) {
      aRequest.newSandbox = true;
    }
    if (this.context == "content") {
      this.sendAsync("executeScript",
                     {
                       value: aRequest.value,
                       args: aRequest.args,
                       newSandbox: aRequest.newSandbox,
                       timeout: timeout,
                       specialPowers: aRequest.specialPowers,
                       filename: aRequest.filename,
                       line: aRequest.line
                     },
                     command_id);
      return;
    }
    let curWindow = this.getCurrentWindow();
    let marionette = new Marionette(this, curWindow, "chrome",
                                    this.marionetteLog,
                                    timeout, this.testName);
    let _chromeSandbox = this.createExecuteSandbox(curWindow,
                                                   marionette,
                                                   aRequest.args,
                                                   aRequest.specialPowers,
                                                   command_id);
    if (!_chromeSandbox)
      return;
    try {
      _chromeSandbox.finish = function chromeSandbox_finish() {
        return marionette.generate_results();
      };
      if (directInject) {
        script = aRequest.value;
      }
      else {
        script = "let func = function() {" +
                       aRequest.value + 
                     "};" +
                     "func.apply(null, __marionetteParams);";
      }
      this.executeScriptInSandbox(_chromeSandbox, script, directInject,
                                  false, command_id, timeout);
    }
    catch (e) {
      let error = createStackMessage(e,
                                     "execute_script",
                                     aRequest.filename,
                                     aRequest.line,
                                     script);
      this.sendError(error[0], 17, error[1], command_id);
    }
  }
function MDA_execute ( aRequest , directInject ) { let timeout = aRequest . scriptTimeout ? aRequest . scriptTimeout : this . scriptTimeout ; let command_id = this . command_id = this . getCommandId ( ) ; let script ; this . logRequest ( "execute" , aRequest ) ; if ( aRequest . newSandbox == undefined ) { aRequest . newSandbox = true ; } if ( this . context == "content" ) { this . sendAsync ( "executeScript" , { value : aRequest . value , args : aRequest . args , newSandbox : aRequest . newSandbox , timeout : timeout , specialPowers : aRequest . specialPowers , filename : aRequest . filename , line : aRequest . line } , command_id ) ; return ; } let curWindow = this . getCurrentWindow ( ) ; let marionette = new Marionette ( this , curWindow , "chrome" , this . marionetteLog , timeout , this . testName ) ; let _chromeSandbox = this . createExecuteSandbox ( curWindow , marionette , aRequest . args , aRequest . specialPowers , command_id ) ; if ( ! _chromeSandbox ) return ; try { _chromeSandbox . finish = function chromeSandbox_finish ( ) { return marionette . generate_results ( ) ; } ; if ( directInject ) { script = aRequest . value ; } else { script = "let func = function() {" + aRequest . value + "};" + "func.apply(null, __marionetteParams);" ; } this . executeScriptInSandbox ( _chromeSandbox , script , directInject , false , command_id , timeout ) ; } catch ( e ) { let error = createStackMessage ( e , "execute_script" , aRequest . filename , aRequest . line , script ) ; this . sendError ( error [ 0 ] , 17 , error [ 1 ] , command_id ) ; } }
Execute the given script either as a function body (executeScript)
 or directly (for 'mochitest' like JS Marionette tests)
Execute the given script either as a function body ( executeScript ) or directly ( for ' mochitest ' like JS Marionette tests )
//if client does not send a value in newSandbox,  //then they expect the same behaviour as webdriver