B2G/gecko/testing/marionette/marionette-elements.js
/**
   * Find an element or elements starting at the document root or
   * given node, using the given search strategy. Search
   * will continue until the search timelimit has been reached.
   *
   * @param nsIDOMWindow win
   *        The window to search in
   * @param object values
   *        The 'using' member of values will tell us which search
   *        method to use. The 'value' member tells us the value we
   *        are looking for.
   *        If this object has an 'element' member, this will be used
   *        as the start node instead of the document root
   *        If this object has a 'time' member, this number will be
   *        used to see if we have hit the search timelimit.
   * @param function on_success
   *        The notification callback used when we are returning successfully.
   * @param function on_error
            The callback to invoke when an error occurs.
   * @param boolean all
   *        If true, all found elements will be returned.
   *        If false, only the first element will be returned.
   *
   * @return nsIDOMElement or list of nsIDOMElements
   *        Returns the element(s) by calling the on_success function.
   */
Find an element or elements starting at the document root or
given node, using the given search strategy. Search
will continue until the search timelimit has been reached.

@param nsIDOMWindow win
The window to search in
@param object values
The 'using' member of values will tell us which search
method to use. The 'value' member tells us the value we
are looking for.
If this object has an 'element' member, this will be used
as the start node instead of the document root
If this object has a 'time' member, this number will be
used to see if we have hit the search timelimit.
@param function on_success
The notification callback used when we are returning successfully.
@param function on_error
The callback to invoke when an error occurs.
@param boolean all
If true, all found elements will be returned.
If false, only the first element will be returned.

@return nsIDOMElement or list of nsIDOMElements
Returns the element(s) by calling the on_success function.
Find an element or elements starting at the document root or given node using the given search strategy . Search will continue until the search timelimit has been reached . @param nsIDOMWindow win The window to search in @param object values The ' using ' member of values will tell us which search method to use . The ' value ' member tells us the value we are looking for . If this object has an ' element ' member this will be used as the start node instead of the document root If this object has a ' time ' member this number will be used to see if we have hit the search timelimit . @param function on_success The notification callback used when we are returning successfully . @param function on_error The callback to invoke when an error occurs . @param boolean all If true all found elements will be returned . If false only the first element will be returned . @return nsIDOMElement or list of nsIDOMElements Returns the element ( s ) by calling the on_success function .
function EM_find(win, values, searchTimeout, on_success, on_error, all, command_id) {
    let startTime = values.time ? values.time : new Date().getTime();
    let startNode = (values.element != undefined) ?
                    this.getKnownElement(values.element, win) : win.document;
    if (this.elementStrategies.indexOf(values.using) < 0) {
      throw new ElementException("No such strategy.", 17, null);
    }
    let found = all ? this.findElements(values.using, values.value, win.document, startNode) :
                      this.findElement(values.using, values.value, win.document, startNode);
    if (found) {
      let type = Object.prototype.toString.call(found);
      if ((type == '[object Array]') || (type == '[object HTMLCollection]') || (type == '[object NodeList]')) {
        let ids = []
        for (let i = 0 ; i < found.length ; i++) {
          ids.push(this.addToKnownElements(found[i]));
        }
        on_success(ids, command_id);
      }
      else {
        let id = this.addToKnownElements(found);
        on_success(id, command_id);
      }
      return;
    } else {
      if (!searchTimeout || new Date().getTime() - startTime > searchTimeout) {
        on_error("Unable to locate element: " + values.value, 7, null, command_id);
      } else {
        values.time = startTime;
        this.timer.initWithCallback(this.find.bind(this, win, values,
                                                   searchTimeout,
                                                   on_success, on_error, all,
                                                   command_id),
                                    100,
                                    Components.interfaces.nsITimer.TYPE_ONE_SHOT);
      }
    }
  }
function EM_find ( win , values , searchTimeout , on_success , on_error , all , command_id ) { let startTime = values . time ? values . time : new Date ( ) . getTime ( ) ; let startNode = ( values . element != undefined ) ? this . getKnownElement ( values . element , win ) : win . document ; if ( this . elementStrategies . indexOf ( values . using ) < 0 ) { throw new ElementException ( "No such strategy." , 17 , null ) ; } let found = all ? this . findElements ( values . using , values . value , win . document , startNode ) : this . findElement ( values . using , values . value , win . document , startNode ) ; if ( found ) { let type = Object . prototype . toString . call ( found ) ; if ( ( type == '[object Array]' ) || ( type == '[object HTMLCollection]' ) || ( type == '[object NodeList]' ) ) { let ids = [ ] for ( let i = 0 ; i < found . length ; i ++ ) { ids . push ( this . addToKnownElements ( found [ i ] ) ) ; } on_success ( ids , command_id ) ; } else { let id = this . addToKnownElements ( found ) ; on_success ( id , command_id ) ; } return ; } else { if ( ! searchTimeout || new Date ( ) . getTime ( ) - startTime > searchTimeout ) { on_error ( "Unable to locate element: " + values . value , 7 , null , command_id ) ; } else { values . time = startTime ; this . timer . initWithCallback ( this . find . bind ( this , win , values , searchTimeout , on_success , on_error , all , command_id ) , 100 , Components . interfaces . nsITimer . TYPE_ONE_SHOT ) ; } } }
Find an element or elements starting at the document root or
 given node, using the given search strategy.
Find an element or elements starting at the document root or given node using the given search strategy .