code: function resolve(newState, newValue) {
      if (webdriver.promise.Deferred.State_.PENDING !== state) {
        return;
      }
  
      if (newValue === self) {
        // See promise a+, 2.3.1
        // http://promises-aplus.github.io/promises-spec/#point-48
        throw TypeError('A promise may not resolve to itself');
      }
  
      state = webdriver.promise.Deferred.State_.BLOCKED;
  
      if (webdriver.promise.isPromise(newValue)) {
        var onFulfill = goog.partial(notifyAll, newState);
        var onReject = goog.partial(
            notifyAll, webdriver.promise.Deferred.State_.REJECTED);
        if (newValue instanceof webdriver.promise.Deferred) {
          newValue.then(onFulfill, onReject);
        } else {
          webdriver.promise.asap(newValue, onFulfill, onReject);
        }
  
      } else {
        notifyAll(newState, newValue);
      }
    }
docs: Resolves this deferred. If the new value is a promise, this function will
  wait for it to be resolved before notifying the registered listeners.
  @param {!webdriver.promise.Deferred.State_} newState The deferred's new
  state.
  @param {*} newValue The deferred's new value.