Skip to content

Align module export API with upstream #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 5 additions & 38 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25839,13 +25839,11 @@ static int exported_names_cmp(const void *p1, const void *p2, void *opaque)
return ret;
}

static JSValue js_get_module_ns(JSContext *ctx, JSModuleDef *m);

static JSValue js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom,
void *opaque)
{
JSModuleDef *m = opaque;
return js_get_module_ns(ctx, m);
return JS_GetModuleNamespace(ctx, m);
}

static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
Expand Down Expand Up @@ -25951,7 +25949,7 @@ static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
return JS_EXCEPTION;
}

static JSValue js_get_module_ns(JSContext *ctx, JSModuleDef *m)
JSValue JS_GetModuleNamespace(JSContext *ctx, JSModuleDef *m)
{
if (JS_IsUndefined(m->module_ns)) {
JSValue val;
Expand Down Expand Up @@ -26185,7 +26183,7 @@ static int js_link_module(JSContext *ctx, JSModuleDef *m)
if (mi->import_name == JS_ATOM__star_) {
JSValue val;
/* name space import */
val = js_get_module_ns(ctx, m1);
val = JS_GetModuleNamespace(ctx, m1);
if (JS_IsException(val))
goto fail;
set_value(ctx, &var_refs[mi->var_idx]->value, val);
Expand All @@ -26209,7 +26207,7 @@ static int js_link_module(JSContext *ctx, JSModuleDef *m)
JSModuleDef *m2;
/* name space import from */
m2 = res_m->req_module_entries[res_me->u.req_module_idx].module;
val = js_get_module_ns(ctx, m2);
val = JS_GetModuleNamespace(ctx, m2);
if (JS_IsException(val))
goto fail;
var_ref = js_create_module_var(ctx, TRUE);
Expand Down Expand Up @@ -26396,7 +26394,7 @@ static JSValue js_dynamic_import_job(JSContext *ctx,
goto exception;

/* return the module namespace */
ns = js_get_module_ns(ctx, m);
ns = JS_GetModuleNamespace(ctx, m);
if (JS_IsException(ns))
goto exception;

Expand Down Expand Up @@ -34396,37 +34394,6 @@ int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
return 0;
}

JSValue JS_GetModuleExport(JSContext *ctx, const JSModuleDef *m, const char *export_name) {
JSExportEntry *me;
JSAtom name;
name = JS_NewAtom(ctx, export_name);
if (name == JS_ATOM_NULL)
goto fail;
me = find_export_entry(ctx, m, name);
JS_FreeAtom(ctx, name);
if (!me)
goto fail;
return JS_DupValue(ctx, me->u.local.var_ref->value);
fail:
return JS_UNDEFINED;
}

int JS_CountModuleExport(JSContext *ctx, const JSModuleDef *m) {
return m->export_entries_count;
}

JSAtom JS_GetModuleExportName(JSContext *ctx, const JSModuleDef *m, int idx) {
if (idx >= m->export_entries_count || idx < 0)
return JS_ATOM_NULL;
return JS_DupAtom(ctx, m->export_entries[idx].export_name);
}

JSValue JS_GetModuleExportValue(JSContext *ctx, const JSModuleDef *m, int idx) {
if (idx >= m->export_entries_count || idx < 0)
return JS_UNDEFINED;
return JS_DupValue(ctx, m->export_entries[idx].u.local.var_ref->value);
}

/* Note: 'func_obj' is not necessarily a constructor */
static void JS_SetConstructor2(JSContext *ctx,
JSValue func_obj,
Expand Down
6 changes: 1 addition & 5 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ JS_EXTERN void JS_SetModuleLoaderFunc(JSRuntime *rt,
/* return the import.meta object of a module */
JS_EXTERN JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m);
JS_EXTERN JSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m);
JSValue JS_GetModuleNamespace(JSContext *ctx, JSModuleDef *m);

/* JS Job support */

Expand Down Expand Up @@ -966,11 +967,6 @@ JS_EXTERN int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *exp
JSValue val);
JS_EXTERN int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
const JSCFunctionListEntry *tab, int len);
/* can only be called after the module is initialized */
JS_EXTERN JSValue JS_GetModuleExport(JSContext *ctx, const JSModuleDef *m, const char *export_name);
JS_EXTERN int JS_CountModuleExport(JSContext *ctx, const JSModuleDef *m);
JS_EXTERN JSAtom JS_GetModuleExportName(JSContext *ctx, const JSModuleDef *m, int idx);
JS_EXTERN JSValue JS_GetModuleExportValue(JSContext *ctx, const JSModuleDef *m, int idx);

/* Promise */

Expand Down