@@ -75,7 +75,7 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len,
7575 return ret ;
7676}
7777
78- static int eval_file (JSContext * ctx , const char * filename , int module )
78+ static int eval_file (JSContext * ctx , const char * filename , int module , int strict )
7979{
8080 uint8_t * buf ;
8181 int ret , eval_flags ;
@@ -91,10 +91,13 @@ static int eval_file(JSContext *ctx, const char *filename, int module)
9191 module = (has_suffix (filename , ".mjs" ) ||
9292 JS_DetectModule ((const char * )buf , buf_len ));
9393 }
94- if (module )
94+ if (module ) {
9595 eval_flags = JS_EVAL_TYPE_MODULE ;
96- else
96+ } else {
9797 eval_flags = JS_EVAL_TYPE_GLOBAL ;
98+ if (strict )
99+ eval_flags |= JS_EVAL_FLAG_STRICT ;
100+ }
98101 ret = eval_buf (ctx , buf , buf_len , filename , eval_flags );
99102 js_free (ctx , buf );
100103 return ret ;
@@ -294,6 +297,7 @@ void help(void)
294297 "-i --interactive go to interactive mode\n"
295298 "-m --module load as ES6 module (default=autodetect)\n"
296299 " --script load as ES6 script (default=autodetect)\n"
300+ " --strict force strict mode\n"
297301 "-I --include file include an additional file\n"
298302 " --std make 'std' and 'os' available to the loaded script\n"
299303 "-T --trace trace memory allocation\n"
@@ -319,6 +323,7 @@ int main(int argc, char **argv)
319323 int trace_memory = 0 ;
320324 int empty_run = 0 ;
321325 int module = -1 ;
326+ int strict = 0 ;
322327 int load_std = 0 ;
323328 int dump_unhandled_promise_rejection = 1 ;
324329 size_t memory_limit = 0 ;
@@ -388,6 +393,10 @@ int main(int argc, char **argv)
388393 module = 0 ;
389394 continue ;
390395 }
396+ if (!strcmp (longopt , "strict" )) {
397+ strict = 1 ;
398+ continue ;
399+ }
391400 if (opt == 'd' || !strcmp (longopt , "dump" )) {
392401 dump_memory ++ ;
393402 continue ;
@@ -485,12 +494,20 @@ int main(int argc, char **argv)
485494 }
486495
487496 for (i = 0 ; i < include_count ; i ++ ) {
488- if (eval_file (ctx , include_list [i ], module ))
497+ if (eval_file (ctx , include_list [i ], 0 , strict ))
489498 goto fail ;
490499 }
491500
492501 if (expr ) {
493- if (eval_buf (ctx , expr , strlen (expr ), "<cmdline>" , 0 ))
502+ int eval_flags ;
503+ if (module > 0 ) {
504+ eval_flags = JS_EVAL_TYPE_MODULE ;
505+ } else {
506+ eval_flags = JS_EVAL_TYPE_GLOBAL ;
507+ if (strict )
508+ eval_flags |= JS_EVAL_FLAG_STRICT ;
509+ }
510+ if (eval_buf (ctx , expr , strlen (expr ), "<cmdline>" , eval_flags ))
494511 goto fail ;
495512 } else
496513 if (optind >= argc ) {
@@ -499,7 +516,7 @@ int main(int argc, char **argv)
499516 } else {
500517 const char * filename ;
501518 filename = argv [optind ];
502- if (eval_file (ctx , filename , module ))
519+ if (eval_file (ctx , filename , module , strict ))
503520 goto fail ;
504521 }
505522 if (interactive ) {
0 commit comments