function IsPromise(x) { if (Type(x) !== "Object") { return false; } if (!has_slot(x, "[[PromiseStatus]]")) { return false; } if (get_slot(x, "[[PromiseStatus]]") === undefined) { return false; } return true; }
let F = function (resolve, reject) { assert(has_slot(F, "[[Capability]]")); let promiseCapability = get_slot(F, "[[Capability]]"); if (promiseCapability["[[Resolve]]"] !== undefined) { throw new TypeError("Re-entrant call to get capabilities executor function"); } if (promiseCapability["[[Reject]]"] !== undefined) { throw new TypeError("Re-entrant call to get capabilities executor function"); } promiseCapability["[[Resolve]]"] = resolve; promiseCapability["[[Reject]]"] = reject; return undefined; };
function Promise(executor) { let promise = this; if (Type(promise) !== "Object") { throw new TypeError("Promise constructor called on non-object"); } if (!has_slot(promise, "[[PromiseStatus]]")) { throw new TypeError("Promise constructor called on an object not initialized as a promise."); } if (get_slot(promise, "[[PromiseStatus]]") !== undefined) { throw new TypeError("Promise constructor called on a promise that has already been constructed."); } if (!IsCallable(executor)) { throw new TypeError("Promise constructor called with non-callable executor function"); } return InitialisePromise(promise, executor); }