src/evaluator/shell.js
function createPromise(result, error) {
  // Create a pre-rejected promise for errors.
  if (error) {
    var deferred = ijsrt.q.defer();
    deferred.reject(error);

    return deferred.promise;
  }

  // Create a pre-resolved promise with the result when the result is not a promise.
  if ((result === null) || (result === undefined) ||
      (typeof result != 'object') ||
      (typeof result.then != 'function')) {
    var deferred = ijsrt.q.defer();
    deferred.resolve(result);

    return deferred.promise;
  }

  return result;
}
function createPromise(result, error) {
  // Create a pre-rejected promise for errors.
  if (error) {
    var deferred = ijsrt.q.defer();
    deferred.reject(error);

    return deferred.promise;
  }

  // Create a pre-resolved promise with the result when the result is not a promise.
  if ((result === null) || (result === undefined) ||
      (typeof result != 'object') ||
      (typeof result.then != 'function')) {
    var deferred = ijsrt.q.defer();
    deferred.resolve(result);

    return deferred.promise;
  }

  return result;
}
Converts a result/error tuple into a promise, if the result is not already a promise.