Skip to content

Commit c02271b

Browse files
committed
[js] Make rethrowing a control exception from CONTROL work
1 parent 3bfea70 commit c02271b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/vm/js/Operations.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ class QAST::OperationsJS {
766766
my $*CTX := '$$sourceCtx';
767767
my $catch_body := $comp.as_js($handler, :want($T_OBJ));
768768
@setup.push("$handler_ctx.\$\${$type} = function(\$\$sourceCtx) \{\n");
769-
@setup.push("\$\$sourceCtx.\$\$handlerOuter = $outer_ctx;\n") if $type eq 'CATCH';
769+
@setup.push("\$\$sourceCtx.\$\${$type eq 'CATCH' ?? 'catch' !! 'control'}HandlerOuter = $outer_ctx;\n");
770770
@setup.push($catch_body);
771771
@setup.push( "return {$catch_body.expr};\n" ~ "\};\n");
772772
$has_catch := 1 if $type eq 'CATCH';

src/vm/js/nqp-runtime/ctx.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ class Ctx extends NQPObject {
112112

113113
exceptionsStack().push(exception);
114114
try {
115+
let wrapped = new Ctx(this, this, null);
115116
if (ctx[handler]) {
116-
ctx.unwind.ret = ctx[handler](this);
117+
ctx.unwind.ret = ctx[handler](wrapped);
117118
} else {
118-
ctx.unwind.ret = ctx.$$CONTROL(this);
119+
ctx.unwind.ret = ctx.$$CONTROL(wrapped);
119120
}
120121
} catch (e) {
121122
if (e instanceof ResumeException && e.exception === exception) {
@@ -130,6 +131,9 @@ class Ctx extends NQPObject {
130131
throw ctx.unwind;
131132
}
132133
ctx = ctx.$$caller;
134+
if (ctx && ctx.$$controlHandlerOuter) {
135+
ctx = ctx.$$controlHandlerOuter;
136+
}
133137
}
134138

135139
throw exception;
@@ -165,8 +169,8 @@ class Ctx extends NQPObject {
165169
throw ctx.unwind;
166170
}
167171
ctx = ctx.$$caller;
168-
if (ctx && ctx.$$handlerOuter) {
169-
ctx = ctx.$$handlerOuter;
172+
if (ctx && ctx.$$catchHandlerOuter) {
173+
ctx = ctx.$$catchHandlerOuter;
170174
}
171175
}
172176

@@ -226,16 +230,18 @@ class Ctx extends NQPObject {
226230
let ctx = lookFrom;
227231

228232
while (ctx) {
233+
//TODO - think about checking the label
229234
if (ctx[handler] || ctx.$$CONTROL) {
230235
exception.caught = ctx;
231236
ctx.exception = exception;
232237

233238
exceptionsStack().push(exception);
234239
try {
240+
let wrapped = new Ctx(this, this, null);
235241
if (ctx[handler]) {
236-
ctx.unwind.ret = ctx[handler](this);
242+
ctx.unwind.ret = ctx[handler](wrapped);
237243
} else {
238-
ctx.unwind.ret = ctx.$$CONTROL(this);
244+
ctx.unwind.ret = ctx.$$CONTROL(wrapped);
239245
}
240246
} catch (e) {
241247
if (e instanceof ResumeException && e.exception === exception) {
@@ -249,7 +255,11 @@ class Ctx extends NQPObject {
249255

250256
throw ctx.unwind;
251257
}
258+
252259
ctx = ctx.$$outer;
260+
if (ctx && ctx.$$controlHandlerOuter) {
261+
ctx = ctx.$$controlHandlerOuter;
262+
}
253263
}
254264

255265
this.$$getHLL().get('lexical_handler_not_found_error').$$call(this, null, new NQPInt(category), new NQPInt(0));

0 commit comments

Comments
 (0)