Skip to content

Commit 7ded62c

Browse files
committedFeb 12, 2024
Align module export API with upstream
Partially reverts 6868fb9 but the same behavior can be implemented in userland by getting the module ns and querying its properties. Ref: bellard/quickjs@c6cc6a9 Fixes: #259
1 parent 359a118 commit 7ded62c

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed
 

‎quickjs.c

+5-38
Original file line numberDiff line numberDiff line change
@@ -25839,13 +25839,11 @@ static int exported_names_cmp(const void *p1, const void *p2, void *opaque)
2583925839
return ret;
2584025840
}
2584125841

25842-
static JSValue js_get_module_ns(JSContext *ctx, JSModuleDef *m);
25843-
2584425842
static JSValue js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom,
2584525843
void *opaque)
2584625844
{
2584725845
JSModuleDef *m = opaque;
25848-
return js_get_module_ns(ctx, m);
25846+
return JS_GetModuleNamespace(ctx, m);
2584925847
}
2585025848

2585125849
static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
@@ -25951,7 +25949,7 @@ static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
2595125949
return JS_EXCEPTION;
2595225950
}
2595325951

25954-
static JSValue js_get_module_ns(JSContext *ctx, JSModuleDef *m)
25952+
JSValue JS_GetModuleNamespace(JSContext *ctx, JSModuleDef *m)
2595525953
{
2595625954
if (JS_IsUndefined(m->module_ns)) {
2595725955
JSValue val;
@@ -26185,7 +26183,7 @@ static int js_link_module(JSContext *ctx, JSModuleDef *m)
2618526183
if (mi->import_name == JS_ATOM__star_) {
2618626184
JSValue val;
2618726185
/* name space import */
26188-
val = js_get_module_ns(ctx, m1);
26186+
val = JS_GetModuleNamespace(ctx, m1);
2618926187
if (JS_IsException(val))
2619026188
goto fail;
2619126189
set_value(ctx, &var_refs[mi->var_idx]->value, val);
@@ -26209,7 +26207,7 @@ static int js_link_module(JSContext *ctx, JSModuleDef *m)
2620926207
JSModuleDef *m2;
2621026208
/* name space import from */
2621126209
m2 = res_m->req_module_entries[res_me->u.req_module_idx].module;
26212-
val = js_get_module_ns(ctx, m2);
26210+
val = JS_GetModuleNamespace(ctx, m2);
2621326211
if (JS_IsException(val))
2621426212
goto fail;
2621526213
var_ref = js_create_module_var(ctx, TRUE);
@@ -26396,7 +26394,7 @@ static JSValue js_dynamic_import_job(JSContext *ctx,
2639626394
goto exception;
2639726395

2639826396
/* return the module namespace */
26399-
ns = js_get_module_ns(ctx, m);
26397+
ns = JS_GetModuleNamespace(ctx, m);
2640026398
if (JS_IsException(ns))
2640126399
goto exception;
2640226400

@@ -34396,37 +34394,6 @@ int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
3439634394
return 0;
3439734395
}
3439834396

34399-
JSValue JS_GetModuleExport(JSContext *ctx, const JSModuleDef *m, const char *export_name) {
34400-
JSExportEntry *me;
34401-
JSAtom name;
34402-
name = JS_NewAtom(ctx, export_name);
34403-
if (name == JS_ATOM_NULL)
34404-
goto fail;
34405-
me = find_export_entry(ctx, m, name);
34406-
JS_FreeAtom(ctx, name);
34407-
if (!me)
34408-
goto fail;
34409-
return JS_DupValue(ctx, me->u.local.var_ref->value);
34410-
fail:
34411-
return JS_UNDEFINED;
34412-
}
34413-
34414-
int JS_CountModuleExport(JSContext *ctx, const JSModuleDef *m) {
34415-
return m->export_entries_count;
34416-
}
34417-
34418-
JSAtom JS_GetModuleExportName(JSContext *ctx, const JSModuleDef *m, int idx) {
34419-
if (idx >= m->export_entries_count || idx < 0)
34420-
return JS_ATOM_NULL;
34421-
return JS_DupAtom(ctx, m->export_entries[idx].export_name);
34422-
}
34423-
34424-
JSValue JS_GetModuleExportValue(JSContext *ctx, const JSModuleDef *m, int idx) {
34425-
if (idx >= m->export_entries_count || idx < 0)
34426-
return JS_UNDEFINED;
34427-
return JS_DupValue(ctx, m->export_entries[idx].u.local.var_ref->value);
34428-
}
34429-
3443034397
/* Note: 'func_obj' is not necessarily a constructor */
3443134398
static void JS_SetConstructor2(JSContext *ctx,
3443234399
JSValue func_obj,

‎quickjs.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ JS_EXTERN void JS_SetModuleLoaderFunc(JSRuntime *rt,
792792
/* return the import.meta object of a module */
793793
JS_EXTERN JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m);
794794
JS_EXTERN JSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m);
795+
JSValue JS_GetModuleNamespace(JSContext *ctx, JSModuleDef *m);
795796

796797
/* JS Job support */
797798

@@ -966,11 +967,6 @@ JS_EXTERN int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *exp
966967
JSValue val);
967968
JS_EXTERN int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
968969
const JSCFunctionListEntry *tab, int len);
969-
/* can only be called after the module is initialized */
970-
JS_EXTERN JSValue JS_GetModuleExport(JSContext *ctx, const JSModuleDef *m, const char *export_name);
971-
JS_EXTERN int JS_CountModuleExport(JSContext *ctx, const JSModuleDef *m);
972-
JS_EXTERN JSAtom JS_GetModuleExportName(JSContext *ctx, const JSModuleDef *m, int idx);
973-
JS_EXTERN JSValue JS_GetModuleExportValue(JSContext *ctx, const JSModuleDef *m, int idx);
974970

975971
/* Promise */
976972

0 commit comments

Comments
 (0)