function Promise()

in public/dexie.js [773:805]


  function Promise(fn) {
    if (typeof this !== "object")
      throw new TypeError("Promises must be constructed via new");
    this._listeners = [];
    this.onuncatched = nop; // Deprecate in next major. Not needed. Better to use global error handler.
    // A library may set `promise._lib = true;` after promise is created to make resolve() or reject()
    // execute the microtask engine implicitely within the call to resolve() or reject().
    // To remain A+ compliant, a library must only set `_lib=true` if it can guarantee that the stack
    // only contains library code when calling resolve() or reject().
    // RULE OF THUMB: ONLY set _lib = true for promises explicitely resolving/rejecting directly from
    // global scope (event handler, timer etc)!
    this._lib = false;
    // Current async scope
    var psd = (this._PSD = PSD);
    if (debug) {
      this._stackHolder = getErrorWithStack();
      this._prev = null;
      this._numPrev = 0; // Number of previous promises (for long stacks)
    }
    if (typeof fn !== "function") {
      if (fn !== INTERNAL) throw new TypeError("Not a function");
      // Private constructor (INTERNAL, state, value).
      // Used internally by Promise.resolve() and Promise.reject().
      this._state = arguments[1];
      this._value = arguments[2];
      if (this._state === false) handleRejection(this, this._value); // Map error, set stack and addPossiblyUnhandledError().
      return;
    }
    this._state = null; // null (=pending), false (=rejected) or true (=resolved)
    this._value = null; // error or result
    ++psd.ref; // Refcounting current scope
    executePromiseTask(this, fn);
  }