lib/commands/execute.js
function (script, args, timeout, hash, data) {
    var deferred = Q.defer();
    var ret = JSON.parse(data);
    var checker = function (yData) {
      if (JSON.parse(yData).value.userRet === true) {
        this.events.emit('driver:message', {key: 'waitFor', value: '', uuid: hash, hash: hash});
        deferred.resolve();
      } else {
        Q.when(this.webdriverClient.execute.bind(this.webdriverClient, {script: script, arguments: args})())
          .then(checker);
      }
    }.bind(this);

    setTimeout(function () {
      this.events.emit('driver:message', {key: 'waitFor', value: 'Interrupted by timeout', uuid: hash, hash: hash});
      deferred.resolve();
    }.bind(this), timeout);

    if (ret.value.userRet === true) {
      this.events.emit('driver:message', {key: 'waitFor', value: '', uuid: hash, hash: hash});
      deferred.resolve();
    } else {
      Q.when(this.webdriverClient.execute.bind(this.webdriverClient, {script: script, arguments: args})())
        .then(checker);
    }

    return deferred.promise;
  }
function (script, args, timeout, hash, data) {
    var deferred = Q.defer();
    var ret = JSON.parse(data);
    var checker = function (yData) {
      if (JSON.parse(yData).value.userRet === true) {
        this.events.emit('driver:message', {key: 'waitFor', value: '', uuid: hash, hash: hash});
        deferred.resolve();
      } else {
        Q.when(this.webdriverClient.execute.bind(this.webdriverClient, {script: script, arguments: args})())
          .then(checker);
      }
    }.bind(this);

    setTimeout(function () {
      this.events.emit('driver:message', {key: 'waitFor', value: 'Interrupted by timeout', uuid: hash, hash: hash});
      deferred.resolve();
    }.bind(this), timeout);

    if (ret.value.userRet === true) {
      this.events.emit('driver:message', {key: 'waitFor', value: '', uuid: hash, hash: hash});
      deferred.resolve();
    } else {
      Q.when(this.webdriverClient.execute.bind(this.webdriverClient, {script: script, arguments: args})())
        .then(checker);
    }

    return deferred.promise;
  }
function ( script , args , timeout , hash , data ) { var deferred = Q . defer ( ) ; var ret = JSON . parse ( data ) ; var checker = function ( yData ) { if ( JSON . parse ( yData ) . value . userRet === true ) { this . events . emit ( 'driver:message' , { key : 'waitFor' , value : '' , uuid : hash , hash : hash } ) ; deferred . resolve ( ) ; } else { Q . when ( this . webdriverClient . execute . bind ( this . webdriverClient , { script : script , arguments : args } ) ( ) ) . then ( checker ) ; } } . bind ( this ) ; setTimeout ( function ( ) { this . events . emit ( 'driver:message' , { key : 'waitFor' , value : 'Interrupted by timeout' , uuid : hash , hash : hash } ) ; deferred . resolve ( ) ; } . bind ( this ) , timeout ) ; if ( ret . value . userRet === true ) { this . events . emit ( 'driver:message' , { key : 'waitFor' , value : '' , uuid : hash , hash : hash } ) ; deferred . resolve ( ) ; } else { Q . when ( this . webdriverClient . execute . bind ( this . webdriverClient , { script : script , arguments : args } ) ( ) ) . then ( checker ) ; } return deferred . promise ; }
Sends out an event with the results of the `waitFor` call

@method _setExecuteCb
@param {function} script Script to execute
@param {array} args Arguments to pass to the function
@param {integer} timeout Timeout of the function
@param {string} hash Unique hash of that fn call
@param {string} data Serialized JSON with the reuslts of the toFrame call
@return {object} Promise
@private
Sends out an event with the results of the waitFor call