From 8f790df9e5bd8bfe104e3af1965ea5f0dac8ce34 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 7 Jan 2015 16:45:05 +0100 Subject: [PATCH] Add strict mode flag to constructor. --- jsi.h | 5 ++--- jsstate.c | 5 ++++- main.c | 2 +- mujs.h | 7 ++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/jsi.h b/jsi.h index 0df949e..03a986d 100644 --- a/jsi.h +++ b/jsi.h @@ -137,6 +137,8 @@ struct js_State js_StringNode *strings; + int strict; + /* parser input source */ const char *filename; const char *source; @@ -156,9 +158,6 @@ struct js_State double number; js_Ast *gcast; /* list of allocated nodes to free after parsing */ - /* compiler state */ - int strict; - /* runtime environment */ js_Object *Object_prototype; js_Object *Array_prototype; diff --git a/jsstate.c b/jsstate.c index 4f5d135..1948f05 100644 --- a/jsstate.c +++ b/jsstate.c @@ -175,7 +175,7 @@ void *js_getcontext(js_State *J) return J->uctx; } -js_State *js_newstate(js_Alloc alloc, void *actx) +js_State *js_newstate(js_Alloc alloc, void *actx, int flags) { js_State *J; @@ -192,6 +192,9 @@ js_State *js_newstate(js_Alloc alloc, void *actx) J->actx = actx; J->alloc = alloc; + if (flags & JS_STRICT) + J->strict = 1; + J->trace[0].name = "?"; J->trace[0].file = "[C]"; J->trace[0].line = 0; diff --git a/main.c b/main.c index 6e63e80..5c2abe6 100644 --- a/main.c +++ b/main.c @@ -126,7 +126,7 @@ main(int argc, char **argv) js_State *J; int i; - J = js_newstate(NULL, NULL); + J = js_newstate(NULL, NULL, JS_STRICT); js_newcfunction(J, jsB_gc, "gc", 0); js_setglobal(J, "gc"); diff --git a/mujs.h b/mujs.h index 1d9b13f..dd3da50 100644 --- a/mujs.h +++ b/mujs.h @@ -32,7 +32,7 @@ typedef void (*js_CFunction)(js_State *J); typedef void (*js_Finalize)(js_State *J, void *p); /* Basic functions */ -js_State *js_newstate(js_Alloc alloc, void *actx); +js_State *js_newstate(js_Alloc alloc, void *actx, int flags); void js_setcontext(js_State *J, void *uctx); void *js_getcontext(js_State *J); js_Panic js_atpanic(js_State *J, js_Panic panic); @@ -46,6 +46,11 @@ 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); +/* State constructor flags */ +enum { + JS_STRICT = 1, +}; + /* RegExp flags */ enum { JS_REGEXP_G = 1,