text: 'use strict';
  var tryCatch = require('./tryCatch');
  var resolveThenable = require('./resolveThenable');
  var states = require('./states');
  
  exports.resolve = function (self, value) {
    var result = tryCatch(getThen, value);
    if (result.status === 'error') {
      return exports.reject(self, result.value);
    }
    var thenable = result.value;
  
    if (thenable) {
      resolveThenable.safely(self, thenable);
    } else {
      self.state = states.FULFILLED;
      self.outcome = value;
      var i = -1;
      var len = self.queue.length;
      while (++i < len) {
        self.queue[i].callFulfilled(value);
      }
    }
    return self;
  };
  exports.reject = function (self, error) {
    self.state = states.REJECTED;
    self.outcome = error;
    var i = -1;
    var len = self.queue.length;
    while (++i < len) {
      self.queue[i].callRejected(error);
    }
    return self;
  };
  
  function getThen(obj) {
    // Make sure we only access the accessor once as required by the spec
    var then = obj && obj.then;
    if (obj && typeof obj === 'object' && typeof then === 'function') {
      return function appyThen() {
        then.apply(obj, arguments);
      };
    }
  }