Make js_try, js_savetry and js_endtry public functions/macros.

This commit is contained in:
Tor Andersson
2016-01-18 13:33:03 +01:00
parent f5b3d15f0c
commit 0fd82b60cf
3 changed files with 33 additions and 9 deletions

10
jsi.h
View File

@@ -117,16 +117,10 @@ struct js_Jumpbuf
js_Instruction *pc;
};
void js_savetry(js_State *J, js_Instruction *pc);
void *js_savetrypc(js_State *J, js_Instruction *pc);
#define js_trypc(J, PC) \
setjmp((js_savetry(J, PC), J->trybuf[J->trytop++].buf))
#define js_try(J) \
setjmp((js_savetry(J, NULL), J->trybuf[J->trytop++].buf))
#define js_endtry(J) \
(--J->trytop)
setjmp(js_savetrypc(J, PC))
/* State struct */

23
jsrun.c
View File

@@ -1144,7 +1144,7 @@ int js_pcall(js_State *J, int n)
/* Exceptions */
void js_savetry(js_State *J, js_Instruction *pc)
void *js_savetrypc(js_State *J, js_Instruction *pc)
{
if (J->trytop == JS_TRYLIMIT)
js_error(J, "try: exception stack overflow");
@@ -1154,6 +1154,27 @@ void js_savetry(js_State *J, js_Instruction *pc)
J->trybuf[J->trytop].top = J->top;
J->trybuf[J->trytop].bot = J->bot;
J->trybuf[J->trytop].pc = pc;
return J->trybuf[J->trytop++].buf;
}
void *js_savetry(js_State *J)
{
if (J->trytop == JS_TRYLIMIT)
js_error(J, "try: exception stack overflow");
J->trybuf[J->trytop].E = J->E;
J->trybuf[J->trytop].envtop = J->envtop;
J->trybuf[J->trytop].tracetop = J->tracetop;
J->trybuf[J->trytop].top = J->top;
J->trybuf[J->trytop].bot = J->bot;
J->trybuf[J->trytop].pc = NULL;
return J->trybuf[J->trytop++].buf;
}
void js_endtry(js_State *J)
{
if (J->trytop == 0)
js_error(J, "endtry: exception stack underflow");
--J->trytop;
}
void js_throw(js_State *J)

9
mujs.h
View File

@@ -48,6 +48,15 @@ int js_ploadfile(js_State *J, const char *filename);
int js_pcall(js_State *J, int n);
int js_pconstruct(js_State *J, int n);
/* Exception handling */
void *js_savetry(js_State *J); /* returns a jmp_buf */
#define js_try(J) \
setjmp(js_savetry(J))
void js_endtry(js_State *J);
/* State constructor flags */
enum {
JS_STRICT = 1,