ref: 41693fa6bd9b14046a26c697770688e478c57e9b
parent: 222ae8067b179597ab9e99529c39ff30533d6475
author: Tor Andersson <tor@ccxvii.net>
date: Thu Mar 6 17:21:11 EST 2014
Add protected functions to load and call code. So that clients don't need to know about js_try.
--- a/js.h
+++ b/js.h
@@ -34,9 +34,14 @@
js_State *js_newstate(js_Alloc alloc, void *actx);
js_Panic js_atpanic(js_State *J, js_Panic panic);
void js_freestate(js_State *J);
+void js_gc(js_State *J, int report);
+
int js_dostring(js_State *J, const char *source, int report);
int js_dofile(js_State *J, const char *filename);
-void js_gc(js_State *J, int report);
+int js_ploadstring(js_State *J, const char *filename, const char *source);
+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);
/* RegExp flags */
enum {
--- a/jsrun.c
+++ b/jsrun.c
@@ -966,6 +966,24 @@
}
}
+int js_pconstruct(js_State *J, int n)
+{
+ if (js_try(J))
+ return 1;
+ js_construct(J, n);
+ js_endtry(J);
+ return 0;
+}
+
+int js_pcall(js_State *J, int n)
+{
+ if (js_try(J))
+ return 1;
+ js_call(J, n);
+ js_endtry(J);
+ return 0;
+}
+
/* Exceptions */
void js_savetry(js_State *J, short *pc)
--- a/jsstate.c
+++ b/jsstate.c
@@ -22,6 +22,24 @@
/* return to javascript to abort */
}
+int js_ploadstring(js_State *J, const char *filename, const char *source)
+{
+ if (js_try(J))
+ return 1;
+ js_loadstring(J, filename, source);
+ js_endtry(J);
+ return 0;
+}
+
+int js_ploadfile(js_State *J, const char *filename)
+{
+ if (js_try(J))
+ return 1;
+ js_loadfile(J, filename);
+ js_endtry(J);
+ return 0;
+}
+
void js_loadstring(js_State *J, const char *filename, const char *source)
{
js_Ast *P;