new-promise-capability.js 522 B

123456789101112131415161718
  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. // 25.4.1.5 NewPromiseCapability(C)
  14. module.exports.f = function (C) {
  15. return new PromiseCapability(C);
  16. };