mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-06 09:51:41 +08:00
Make js_try, js_savetry and js_endtry public functions/macros.
This commit is contained in:
10
jsi.h
10
jsi.h
@@ -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
23
jsrun.c
@@ -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
9
mujs.h
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user