1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 |
|
---|
5 | var $SyntaxError = require('es-errors/syntax');
|
---|
6 | var $TypeError = require('es-errors/type');
|
---|
7 | var $Promise = GetIntrinsic('%Promise%', true);
|
---|
8 |
|
---|
9 | var callBound = require('call-bound');
|
---|
10 |
|
---|
11 | var CreateIterResultObject = require('./CreateIterResultObject');
|
---|
12 | var IteratorComplete = require('./IteratorComplete');
|
---|
13 | var IteratorValue = require('./IteratorValue');
|
---|
14 | var PromiseResolve = require('./PromiseResolve');
|
---|
15 |
|
---|
16 | var isObject = require('../helpers/isObject');
|
---|
17 |
|
---|
18 | var $then = callBound('Promise.prototype.then', true);
|
---|
19 |
|
---|
20 | // https://262.ecma-international.org/10.0/#sec-asyncfromsynciteratorcontinuation
|
---|
21 |
|
---|
22 | module.exports = function AsyncFromSyncIteratorContinuation(result) {
|
---|
23 | if (!isObject(result)) {
|
---|
24 | throw new $TypeError('Assertion failed: Type(O) is not Object');
|
---|
25 | }
|
---|
26 |
|
---|
27 | if (arguments.length > 1) {
|
---|
28 | throw new $SyntaxError('although AsyncFromSyncIteratorContinuation should take a second argument, it is not used in this implementation');
|
---|
29 | }
|
---|
30 |
|
---|
31 | if (!$Promise) {
|
---|
32 | throw new $SyntaxError('This environment does not support Promises.');
|
---|
33 | }
|
---|
34 |
|
---|
35 | return new $Promise(function (resolve) {
|
---|
36 | var done = IteratorComplete(result); // step 2
|
---|
37 | var value = IteratorValue(result); // step 4
|
---|
38 | var valueWrapper = PromiseResolve($Promise, value); // step 6
|
---|
39 |
|
---|
40 | // eslint-disable-next-line no-shadow
|
---|
41 | var onFulfilled = function (value) { // steps 8-9
|
---|
42 | return CreateIterResultObject(value, done); // step 8.a
|
---|
43 | };
|
---|
44 | resolve($then(valueWrapper, onFulfilled)); // step 11
|
---|
45 | }); // step 12
|
---|
46 | };
|
---|