esnext.async-iterator.async-dispose.js 1012 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. // https://github.com/tc39/proposal-async-explicit-resource-management
  3. var call = require('../internals/function-call');
  4. var defineBuiltIn = require('../internals/define-built-in');
  5. var getBuiltIn = require('../internals/get-built-in');
  6. var getMethod = require('../internals/get-method');
  7. var hasOwn = require('../internals/has-own-property');
  8. var wellKnownSymbol = require('../internals/well-known-symbol');
  9. var AsyncIteratorPrototype = require('../internals/async-iterator-prototype');
  10. var ASYNC_DISPOSE = wellKnownSymbol('asyncDispose');
  11. var Promise = getBuiltIn('Promise');
  12. if (!hasOwn(AsyncIteratorPrototype, ASYNC_DISPOSE)) {
  13. defineBuiltIn(AsyncIteratorPrototype, ASYNC_DISPOSE, function () {
  14. var O = this;
  15. return new Promise(function (resolve, reject) {
  16. var $return = getMethod(O, 'return');
  17. if ($return) {
  18. Promise.resolve(call($return, O)).then(function () {
  19. resolve(undefined);
  20. }, reject);
  21. } else resolve(undefined);
  22. });
  23. });
  24. }