Skip to content

Commit 99eed3f

Browse files
author
Fabrice Bellard
committed
fixed exception handling happening when calling a function (bellard#24)
1 parent cb1ff4a commit 99eed3f

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

mquickjs.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5366,8 +5366,10 @@ JSValue JS_Call(JSContext *ctx, int call_flags)
53665366
(fd->def_type != JS_CFUNC_constructor &&
53675367
fd->def_type != JS_CFUNC_constructor_magic)) {
53685368
sp += 2; /* go back to the caller frame */
5369+
ctx->sp = sp;
5370+
ctx->fp = fp;
53695371
val = JS_ThrowTypeError(ctx, "not a constructor");
5370-
goto exception;
5372+
goto call_exception;
53715373
}
53725374

53735375
argc = call_flags & FRAME_CF_ARGC_MASK;
@@ -5376,9 +5378,9 @@ JSValue JS_Call(JSContext *ctx, int call_flags)
53765378
ctx->fp = fp;
53775379
n = JS_StackCheck(ctx, max_int(fd->arg_count - argc, 0));
53785380
if (n) {
5379-
val = JS_EXCEPTION;
53805381
sp += 2; /* go back to the caller frame */
5381-
goto exception;
5382+
val = JS_EXCEPTION;
5383+
goto call_exception;
53825384
}
53835385
pushed_argc = argc;
53845386
if (fd->arg_count > argc) {
@@ -5451,12 +5453,12 @@ JSValue JS_Call(JSContext *ctx, int call_flags)
54515453
int n_vars;
54525454
call_flags = JS_VALUE_GET_INT(sp[FRAME_OFFSET_CALL_FLAGS]);
54535455
if (call_flags & FRAME_CF_CTOR) {
5456+
ctx->sp = sp;
5457+
ctx->fp = fp;
54545458
/* Note: can recurse at this point */
5455-
SAVE();
54565459
val = js_call_constructor_start(ctx, func_obj);
5457-
RESTORE();
54585460
if (JS_IsException(val))
5459-
goto exception;
5461+
goto call_exception;
54605462
sp[FRAME_OFFSET_THIS_OBJ] = val;
54615463
func_obj = sp[FRAME_OFFSET_FUNC_OBJ];
54625464
p = JS_VALUE_TO_PTR(func_obj);
@@ -5476,7 +5478,7 @@ JSValue JS_Call(JSContext *ctx, int call_flags)
54765478
b->stack_size);
54775479
if (n) {
54785480
val = JS_EXCEPTION;
5479-
goto exception;
5481+
goto call_exception;
54805482
}
54815483
func_obj = sp[FRAME_OFFSET_FUNC_OBJ];
54825484
p = JS_VALUE_TO_PTR(func_obj);
@@ -5502,8 +5504,16 @@ JSValue JS_Call(JSContext *ctx, int call_flags)
55025504
} else {
55035505
not_a_function:
55045506
sp += 2; /* go back to the caller frame */
5507+
ctx->sp = sp;
5508+
ctx->fp = fp;
55055509
val = JS_ThrowTypeError(ctx, "not a function");
5506-
goto exception;
5510+
call_exception:
5511+
if (!pc) {
5512+
goto done;
5513+
} else {
5514+
RESTORE();
5515+
goto exception;
5516+
}
55075517
}
55085518
}
55095519
}
@@ -5515,7 +5525,8 @@ JSValue JS_Call(JSContext *ctx, int call_flags)
55155525
JSValue *stack_top, val2;
55165526
JSValueArray *vars;
55175527
int v;
5518-
/* exception before entering in the first function ? */
5528+
/* exception before entering in the first function ?
5529+
(XXX: remove this test) */
55195530
if (!pc)
55205531
goto done;
55215532
v = JS_VALUE_GET_SPECIAL_VALUE(val);

0 commit comments

Comments
 (0)