From be61a3110039db43b6fedee0a3f76ed50bef8dbe Mon Sep 17 00:00:00 2001 From: Lily Skye Date: Tue, 3 Sep 2024 00:36:59 -0600 Subject: [PATCH] Split JS_SetModuleLoaderFunc into three separate functions, one for each of its args --- src/qjsc/qjsc.c | 4 ++- src/quickjs-modulesys/quickjs-modulesys.c | 6 ++--- src/quickjs/quickjs.c | 30 ++++++++++++++--------- src/quickjs/quickjs.h | 20 ++++++++------- src/run-test262/run-test262.c | 8 ++++-- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/qjsc/qjsc.c b/src/qjsc/qjsc.c index 31e6c68e3..cd828e22a 100644 --- a/src/qjsc/qjsc.c +++ b/src/qjsc/qjsc.c @@ -675,7 +675,9 @@ int main(int argc, char **argv) #endif /* loader for ES6 modules */ - JS_SetModuleLoaderFunc(rt, NULL, jsc_module_loader, NULL); + JS_SetModuleNormalizeFunc(rt, NULL); + JS_SetModuleLoaderFunc(rt, jsc_module_loader); + JS_SetModuleLoaderOpaque(rt, NULL); debugprint("writing file header comment and include...\n"); diff --git a/src/quickjs-modulesys/quickjs-modulesys.c b/src/quickjs-modulesys/quickjs-modulesys.c index f8ff4ea08..021b54b35 100644 --- a/src/quickjs-modulesys/quickjs-modulesys.c +++ b/src/quickjs-modulesys/quickjs-modulesys.c @@ -37,9 +37,9 @@ void QJMS_InitState(JSRuntime *rt) state = js_malloc_rt(rt, sizeof(state)); state->main_module = main_module; - JS_SetModuleLoaderFunc(rt, (JSModuleNormalizeFunc *) QJMS_NormalizeModuleName, - (JSModuleLoaderFunc *) QJMS_ModuleLoader, - (void *) state); + JS_SetModuleNormalizeFunc(rt, (JSModuleNormalizeFunc *) QJMS_NormalizeModuleName); + JS_SetModuleLoaderFunc(rt, (JSModuleLoaderFunc *) QJMS_ModuleLoader); + JS_SetModuleLoaderOpaque(rt, (void *) state); } void QJMS_FreeState(JSRuntime *rt) diff --git a/src/quickjs/quickjs.c b/src/quickjs/quickjs.c index 761ef34e4..e1066e5fd 100644 --- a/src/quickjs/quickjs.c +++ b/src/quickjs/quickjs.c @@ -27070,23 +27070,20 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name, } void JS_SetModuleLoaderFunc(JSRuntime *rt, - JSModuleNormalizeFunc *module_normalize, - JSModuleLoaderFunc *module_loader, void *opaque) + JSModuleLoaderFunc *module_loader) { - rt->module_normalize_func = module_normalize; rt->module_loader_func = module_loader; - rt->module_loader_opaque = opaque; } -void JS_SetContextOpaqueValue(JSContext *ctx, JSValue value) +JSModuleLoaderFunc *JS_GetModuleLoaderFunc(JSRuntime *rt) { - ctx->user_opaque_val = value; + return rt->module_loader_func; } -/* NOTE: you must free it! */ -JSValue JS_GetContextOpaqueValue(JSContext *ctx) +void JS_SetModuleNormalizeFunc(JSRuntime *rt, + JSModuleNormalizeFunc *module_normalize) { - return JS_DupValue(ctx, ctx->user_opaque_val); + rt->module_normalize_func = module_normalize; } JSModuleNormalizeFunc *JS_GetModuleNormalizeFunc(JSRuntime *rt) @@ -27094,9 +27091,9 @@ JSModuleNormalizeFunc *JS_GetModuleNormalizeFunc(JSRuntime *rt) return rt->module_normalize_func; } -JSModuleLoaderFunc *JS_GetModuleLoaderFunc(JSRuntime *rt) +void JS_SetModuleLoaderOpaque(JSRuntime *rt, void *opaque) { - return rt->module_loader_func; + rt->module_loader_opaque = opaque; } void *JS_GetModuleLoaderOpaque(JSRuntime *rt) @@ -27104,6 +27101,17 @@ void *JS_GetModuleLoaderOpaque(JSRuntime *rt) return rt->module_loader_opaque; } +void JS_SetContextOpaqueValue(JSContext *ctx, JSValue value) +{ + ctx->user_opaque_val = value; +} + +/* NOTE: you must free it! */ +JSValue JS_GetContextOpaqueValue(JSContext *ctx) +{ + return JS_DupValue(ctx, ctx->user_opaque_val); +} + /* default module filename normalizer */ static char *js_default_module_normalize_name(JSContext *ctx, const char *base_name, diff --git a/src/quickjs/quickjs.h b/src/quickjs/quickjs.h index 633499f9b..17c59813d 100644 --- a/src/quickjs/quickjs.h +++ b/src/quickjs/quickjs.h @@ -977,18 +977,20 @@ typedef char *JSModuleNormalizeFunc(JSContext *ctx, typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx, const char *module_name, void *opaque); -/* module_normalize = NULL is allowed and invokes the default module - filename normalizer */ void JS_SetModuleLoaderFunc(JSRuntime *rt, - JSModuleNormalizeFunc *module_normalize, - JSModuleLoaderFunc *module_loader, void *opaque); - + JSModuleLoaderFunc *module_loader); /* return the value set by JS_SetModuleLoaderFunc. could be NULL. */ -JSModuleNormalizeFunc *JS_GetModuleNormalizeFunc(JSRuntime *rt); -/* return the value set by JS_SetModuleLoaderFunc. could be NULL but only if - JS_SetModuleLoaderFunc was never called. */ JSModuleLoaderFunc *JS_GetModuleLoaderFunc(JSRuntime *rt); -/* return the value set by JS_SetModuleLoaderFunc. could be NULL. */ + +/* module_normalize = NULL is allowed and invokes the default module + filename normalizer */ +void JS_SetModuleNormalizeFunc(JSRuntime *rt, + JSModuleNormalizeFunc *module_normalize); +/* return the value set by JS_SetModuleNormalizeFunc. could be NULL. */ +JSModuleNormalizeFunc *JS_GetModuleNormalizeFunc(JSRuntime *rt); + +void JS_SetModuleLoaderOpaque(JSRuntime *rt, void *opaque); +/* return the value set by JS_SetModuleLoaderOpaque. could be NULL. */ void *JS_GetModuleLoaderOpaque(JSRuntime *rt); void JS_SetContextOpaqueValue(JSContext *ctx, JSValue value); diff --git a/src/run-test262/run-test262.c b/src/run-test262/run-test262.c index 58936c13b..97fd35171 100644 --- a/src/run-test262/run-test262.c +++ b/src/run-test262/run-test262.c @@ -1522,7 +1522,9 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip, JS_SetCanBlock(rt, can_block); /* loader for ES6 modules */ - JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, NULL); + JS_SetModuleNormalizeFunc(rt, NULL); + JS_SetModuleLoaderFunc(rt, js_module_loader_test); + JS_SetModuleLoaderOpaque(rt, NULL); add_helpers(ctx); @@ -1819,7 +1821,9 @@ int run_test262_harness_test(const char *filename, BOOL is_module) JS_SetCanBlock(rt, can_block); /* loader for ES6 modules */ - JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, NULL); + JS_SetModuleNormalizeFunc(rt, NULL); + JS_SetModuleLoaderFunc(rt, js_module_loader_test); + JS_SetModuleLoaderOpaque(rt, NULL); add_helpers(ctx);