mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-06 01:41:37 +08:00
Add strict mode flag to constructor.
This commit is contained in:
5
jsi.h
5
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;
|
||||
|
||||
@@ -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
2
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");
|
||||
|
||||
7
mujs.h
7
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,
|
||||
|
||||
Reference in New Issue
Block a user