new-promise-capability.js 584 B

12345678910111213141516171819
  1. 'use strict';
  2. var aFunction = require('../internals/a-function');
  3. var PromiseCapability = function (C) {
  4. var resolve, reject;
  5. this.promise = new C(function ($$resolve, $$reject) {
  6. if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor');
  7. resolve = $$resolve;
  8. reject = $$reject;
  9. });
  10. this.resolve = aFunction(resolve);
  11. this.reject = aFunction(reject);
  12. };
  13. // `NewPromiseCapability` abstract operation
  14. // https://tc39.es/ecma262/#sec-newpromisecapability
  15. module.exports.f = function (C) {
  16. return new PromiseCapability(C);
  17. };