Skip to content

Commit

Permalink
[js] Fix how exceptions are thrown in continuations
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jan 11, 2019
1 parent 82973f1 commit 72c5cb4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/vm/js/nqp-runtime/async-continuations.js
Expand Up @@ -27,13 +27,17 @@ function findReset(tag, ctx) {
op.continuationreset = function(ctx, currentHLL, tag, block) {
return new Promise(function(resolve, reject) {
if (block instanceof Cont) {
block.resetCtx.$$outside = resolve;
block.resetCtx.$$outsideResolve = resolve;
block.resetCtx.$$outsideReject = reject;
block.inside(Null);
} else {
const newCtx = new CtxJustReset(ctx, ctx, null);
newCtx.$$outside = resolve;
newCtx.$$outsideResolve = resolve;
newCtx.$$outsideReject = reject;
newCtx.$$tag = tag;
block.$$call(newCtx, null).then(value => newCtx.$$outside(nqp.retval(currentHLL, value)), reject);
block.$$call(newCtx, null).then(
value => newCtx.$$outsideResolve(nqp.retval(currentHLL, value)),
error => newCtx.$$outsideReject(error));
}
});
};
Expand All @@ -58,14 +62,16 @@ op.continuationcontrol = function(ctx, currentHLL, protect, tag, closure) {
return new Promise(function(resolve, reject) {
const resetCtx = findReset(tag, ctx);
const cont = new Cont(ctx, resolve, resetCtx);
closure.$$call(protect ? resetCtx : resetCtx.$$caller, null, cont).then(value => resetCtx.$$outside(nqp.retval(currentHLL, value)), reject);
closure.$$call(protect ? resetCtx : resetCtx.$$caller, null, cont).then(value => resetCtx.$$outsideResolve(nqp.retval(currentHLL, value)), reject);
});
};

op.continuationinvoke = function(ctx, currentHLL, cont, inject) {
return new Promise(function(resolve, reject) {
cont.resetCtx.$$caller = ctx;
cont.resetCtx.$$outside = resolve;
cont.resetCtx.$$outsideResolve = resolve;
cont.resetCtx.$$outsideReject = reject;

inject.$$call(cont.ctx, null).then(value => {
cont.inside(nqp.retval(currentHLL, value));
}, reject);
Expand Down

0 comments on commit 72c5cb4

Please sign in to comment.