shithub: libmujs

Download patch

ref: 8f790df9e5bd8bfe104e3af1965ea5f0dac8ce34
parent: c6d17c7f00505b3d41f051a0b6c0753e9faf17e9
author: Tor Andersson <tor.andersson@artifex.com>
date: Wed Jan 7 11:45:05 EST 2015

Add strict mode flag to constructor.

--- a/jsi.h
+++ b/jsi.h
@@ -137,6 +137,8 @@
 
 	js_StringNode *strings;
 
+	int strict;
+
 	/* parser input source */
 	const char *filename;
 	const char *source;
@@ -155,9 +157,6 @@
 	const char *text;
 	double number;
 	js_Ast *gcast; /* list of allocated nodes to free after parsing */
-
-	/* compiler state */
-	int strict;
 
 	/* runtime environment */
 	js_Object *Object_prototype;
--- a/jsstate.c
+++ b/jsstate.c
@@ -175,7 +175,7 @@
 	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;
 
@@ -191,6 +191,9 @@
 	memset(J, 0, sizeof(*J));
 	J->actx = actx;
 	J->alloc = alloc;
+
+	if (flags & JS_STRICT)
+		J->strict = 1;
 
 	J->trace[0].name = "?";
 	J->trace[0].file = "[C]";
--- a/main.c
+++ b/main.c
@@ -126,7 +126,7 @@
 	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");
--- a/mujs.h
+++ b/mujs.h
@@ -32,7 +32,7 @@
 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);
@@ -45,6 +45,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 {