@@ -865,7 +865,9 @@ static JSValue js_evalScript(JSContext *ctx, JSValue this_val,
865
865
JSValue options_obj ;
866
866
BOOL backtrace_barrier = FALSE;
867
867
BOOL eval_function = FALSE;
868
+ BOOL eval_module = FALSE;
868
869
BOOL compile_only = FALSE;
870
+ BOOL compile_module = FALSE;
869
871
BOOL is_async = FALSE;
870
872
int flags ;
871
873
@@ -877,14 +879,33 @@ static JSValue js_evalScript(JSContext *ctx, JSValue this_val,
877
879
if (get_bool_option (ctx , & eval_function , options_obj ,
878
880
"eval_function" ))
879
881
return JS_EXCEPTION ;
882
+ if (get_bool_option (ctx , & eval_module , options_obj ,
883
+ "eval_module" ))
884
+ return JS_EXCEPTION ;
880
885
if (get_bool_option (ctx , & compile_only , options_obj ,
881
886
"compile_only" ))
882
887
return JS_EXCEPTION ;
888
+ if (get_bool_option (ctx , & compile_module , options_obj ,
889
+ "compile_module" ))
890
+ return JS_EXCEPTION ;
883
891
if (get_bool_option (ctx , & is_async , options_obj ,
884
892
"async" ))
885
893
return JS_EXCEPTION ;
886
894
}
887
895
896
+ if (eval_module ) {
897
+ obj = argv [0 ];
898
+ if (JS_VALUE_GET_TAG (obj ) != JS_TAG_MODULE )
899
+ return JS_ThrowTypeError (ctx , "not a module" );
900
+
901
+ if (JS_ResolveModule (ctx , obj ) < 0 )
902
+ return JS_EXCEPTION ;
903
+
904
+ js_module_set_import_meta (ctx , obj , FALSE, FALSE);
905
+
906
+ return JS_EvalFunction (ctx , obj );
907
+ }
908
+
888
909
if (!eval_function ) {
889
910
str = JS_ToCStringLen (ctx , & len , argv [0 ]);
890
911
if (!str )
@@ -894,7 +915,7 @@ static JSValue js_evalScript(JSContext *ctx, JSValue this_val,
894
915
/* install the interrupt handler */
895
916
JS_SetInterruptHandler (JS_GetRuntime (ctx ), interrupt_handler , NULL );
896
917
}
897
- flags = JS_EVAL_TYPE_GLOBAL ;
918
+ flags = compile_module ? JS_EVAL_TYPE_MODULE : JS_EVAL_TYPE_GLOBAL ;
898
919
if (backtrace_barrier )
899
920
flags |= JS_EVAL_FLAG_BACKTRACE_BARRIER ;
900
921
if (compile_only )
0 commit comments