new-promise-capability.js 614 B

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