diff --git a/jsstate.c b/jsstate.c index 7ac4463..922c169 100644 --- a/jsstate.c +++ b/jsstate.c @@ -322,6 +322,11 @@ js_State *js_newstate(js_Alloc alloc, void *actx, int flags) J->nextref = 0; J->gcthresh = 0; /* reaches stability within ~ 2-5 GC cycles */ + if (js_try(J)) { + js_freestate(J); + return NULL; + } + J->R = jsV_newobject(J, JS_COBJECT, NULL); J->G = jsV_newobject(J, JS_COBJECT, NULL); J->E = jsR_newenvironment(J, J->G, NULL); @@ -329,5 +334,6 @@ js_State *js_newstate(js_Alloc alloc, void *actx, int flags) jsB_init(J); + js_endtry(J); return J; } diff --git a/main.c b/main.c index c0b2077..fb8c986 100644 --- a/main.c +++ b/main.c @@ -311,6 +311,10 @@ main(int argc, char **argv) } J = js_newstate(NULL, NULL, strict ? JS_STRICT : 0); + if (!J) { + fprintf(stderr, "Could not initialize MuJS.\n"); + exit(1); + } js_newcfunction(J, jsB_gc, "gc", 0); js_setglobal(J, "gc");