diff --git a/jsrun.c b/jsrun.c index 533b272..1982635 100644 --- a/jsrun.c +++ b/jsrun.c @@ -16,7 +16,7 @@ static void jsR_run(js_State *J, js_Function *F); static void js_trystackoverflow(js_State *J) { STACK[TOP].type = JS_TLITSTR; - STACK[TOP].u.litstr = "try stack overflow"; + STACK[TOP].u.litstr = "exception stack overflow"; ++TOP; js_throw(J); } diff --git a/jsstate.c b/jsstate.c index 0f026d5..1dfb7fd 100644 --- a/jsstate.c +++ b/jsstate.c @@ -8,6 +8,16 @@ #include #include +static int js_ptry(js_State *J) { + if (J->trytop == JS_TRYLIMIT) { + STACK[TOP].type = JS_TLITSTR; + STACK[TOP].u.litstr = "exception stack overflow"; + ++TOP; + return 1; + } + return 0; +} + static void *js_defaultalloc(void *actx, void *ptr, int size) { if (size == 0) { @@ -31,6 +41,8 @@ static void js_defaultpanic(js_State *J) int js_ploadstring(js_State *J, const char *filename, const char *source) { + if (js_ptry(J)) + return 1; if (js_try(J)) return 1; js_loadstring(J, filename, source); @@ -40,6 +52,8 @@ int js_ploadstring(js_State *J, const char *filename, const char *source) int js_ploadfile(js_State *J, const char *filename) { + if (js_ptry(J)) + return 1; if (js_try(J)) return 1; js_loadfile(J, filename); @@ -50,6 +64,10 @@ int js_ploadfile(js_State *J, const char *filename) const char *js_trystring(js_State *J, int idx, const char *error) { const char *s; + if (js_ptry(J)) { + js_pop(J, 1); + return error; + } if (js_try(J)) { js_pop(J, 1); return error; @@ -62,6 +80,10 @@ const char *js_trystring(js_State *J, int idx, const char *error) double js_trynumber(js_State *J, int idx, double error) { double v; + if (js_ptry(J)) { + js_pop(J, 1); + return error; + } if (js_try(J)) { js_pop(J, 1); return error; @@ -74,6 +96,10 @@ double js_trynumber(js_State *J, int idx, double error) int js_tryinteger(js_State *J, int idx, int error) { int v; + if (js_ptry(J)) { + js_pop(J, 1); + return error; + } if (js_try(J)) { js_pop(J, 1); return error; @@ -86,6 +112,10 @@ int js_tryinteger(js_State *J, int idx, int error) int js_tryboolean(js_State *J, int idx, int error) { int v; + if (js_ptry(J)) { + js_pop(J, 1); + return error; + } if (js_try(J)) { js_pop(J, 1); return error; @@ -189,6 +219,11 @@ void js_loadfile(js_State *J, const char *filename) int js_dostring(js_State *J, const char *source) { + if (js_ptry(J)) { + js_report(J, "exception stack overflow"); + js_pop(J, 1); + return 1; + } if (js_try(J)) { js_report(J, js_trystring(J, -1, "Error")); js_pop(J, 1); @@ -204,6 +239,11 @@ int js_dostring(js_State *J, const char *source) int js_dofile(js_State *J, const char *filename) { + if (js_ptry(J)) { + js_report(J, "exception stack overflow"); + js_pop(J, 1); + return 1; + } if (js_try(J)) { js_report(J, js_trystring(J, -1, "Error")); js_pop(J, 1);