Skip to content

Commit

Permalink
test: update test to reflect changes to regenerator-runtime. Closes #91
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Apr 6, 2020
1 parent 45badff commit 9400a38
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions test/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,18 @@ function mark(genFun) {
genFun.prototype = Object.create(Gp);
return genFun;
} // Within the body of any async function, \`await x\` is transformed to
}
// \`yield regeneratorRuntime.awrap(x)\`, so that the runtime can test
// \`hasOwn.call(value, "__await")\` to determine if the yielded value is
// meant to be awaited.
function awrap(arg) {
return {
__await: arg
};
}
function AsyncIterator(generator) {
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
Expand All @@ -276,14 +275,14 @@ function AsyncIterator(generator) {
var value = result.value;
if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) {
return Promise.resolve(value.__await).then(function (value) {
return PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
});
}
return Promise.resolve(value).then(function (unwrapped) {
return PromiseImpl.resolve(value).then(function (unwrapped) {
// When a yielded Promise is resolved, its final value becomes
// the .value of the Promise<{value,done}> result for the
// current iteration.
Expand All @@ -301,7 +300,7 @@ function AsyncIterator(generator) {
function enqueue(method, arg) {
function callInvokeWithMethodAndArg() {
return new Promise(function (resolve, reject) {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
Expand Down Expand Up @@ -337,8 +336,12 @@ AsyncIterator.prototype[asyncIteratorSymbol] = function () {
// the final result produced by the iterator.
function async(innerFn, outerFn, self, tryLocsList) {
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList));
function async(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
if (PromiseImpl === void 0) PromiseImpl = Promise;
var iter = new AsyncIterator(
wrap(innerFn, outerFn, self, tryLocsList),
PromiseImpl
);
return isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
: iter.next().then(function (result) {
return result.done ? result.value : iter.next();
Expand Down Expand Up @@ -432,6 +435,7 @@ function maybeInvokeDelegate(delegate, context) {
context.delegate = null;
if (context.method === "throw") {
// Note: ["return"] must be used for ES3 parsing compatibility.
if (delegate.iterator["return"]) {
// If the delegate iterator has a return method, give it a
// chance to clean up.
Expand Down

0 comments on commit 9400a38

Please sign in to comment.