@@ -500,11 +500,11 @@ JSModuleDef *QuickJSBinder::js_module_loader(JSContext *ctx, const char *module_
500500 JS_EvalFunction (ctx, func);
501501 JSValue val = variant_to_var (ctx, res);
502502 JS_SetModuleExport (ctx, m, " default" , val);
503- JS_FreeValue (ctx, val);
504503
505504 ModuleCache module ;
506505 module .md5 = FileAccess::get_md5 (file);
507506 module .module = m;
507+ module .res_value = val;
508508 module .flags = MODULE_FLAG_RESOURCE;
509509 module .module = static_cast <JSModuleDef *>(JS_VALUE_GET_PTR (func));
510510 binder->module_cache .set (file, module );
@@ -553,6 +553,7 @@ QuickJSBinder::ModuleCache *QuickJSBinder::js_compile_module(JSContext *ctx, con
553553 module .module = NULL ;
554554 module .flags = MODULE_FLAG_SCRIPT;
555555 module .module = static_cast <JSModuleDef *>(JS_VALUE_GET_PTR (func));
556+ module .res_value = JS_UNDEFINED;
556557 binder->module_cache .set (p_filename, module );
557558 } else {
558559 JSValue e = JS_GetException (ctx);
@@ -1144,17 +1145,20 @@ void QuickJSBinder::uninitialize() {
11441145 frame_callbacks.clear ();
11451146
11461147 { // modules
1147- # if MODULE_HAS_REFCOUNT
1148+
11481149 const String *file = module_cache.next (NULL );
11491150 while (file) {
11501151 const ModuleCache &m = module_cache.get (*file);
1152+ #if MODULE_HAS_REFCOUNT
11511153 if (m.module ) {
11521154 JSValue val = JS_MKPTR (JS_TAG_MODULE, m.module );
11531155 JS_FreeValue (ctx, val);
11541156 }
1157+ #endif
1158+ JS_FreeValue (ctx, m.res_value );
11551159 file = module_cache.next (file);
11561160 }
1157- # endif
1161+
11581162 module_cache.clear ();
11591163 }
11601164
0 commit comments