ref: 0fd82b60cff02f1fe2a74d820902bd1fc4667d7b
parent: f5b3d15f0cacbca32398f4409dd104634d214175
author: Tor Andersson <tor.andersson@artifex.com>
date: Mon Jan 18 08:33:03 EST 2016
Make js_try, js_savetry and js_endtry public functions/macros.
--- a/jsi.h
+++ b/jsi.h
@@ -117,16 +117,10 @@
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 */
--- a/jsrun.c
+++ b/jsrun.c
@@ -1144,7 +1144,7 @@
/* 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 @@
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)
--- a/mujs.h
+++ b/mujs.h
@@ -48,6 +48,15 @@
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,