Add strict mode flag to constructor.

This commit is contained in:
Tor Andersson
2015-01-07 16:45:05 +01:00
parent c6d17c7f00
commit 8f790df9e5
4 changed files with 13 additions and 6 deletions

5
jsi.h
View File

@@ -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;

View File

@@ -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;

2
main.c
View File

@@ -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");

7
mujs.h
View File

@@ -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,