[oden-js-sys] Add functions to get more information of modules
Adopt https://github.com/bellard/quickjs/pull/35
This commit is contained in:
parent
156b6d6691
commit
0c8367d29f
2 changed files with 37 additions and 1 deletions
|
|
@ -27125,7 +27125,7 @@ static int add_req_module_entry(JSContext *ctx, JSModuleDef *m,
|
|||
return i;
|
||||
}
|
||||
|
||||
static JSExportEntry *find_export_entry(JSContext *ctx, JSModuleDef *m,
|
||||
static JSExportEntry *find_export_entry(JSContext *ctx, const JSModuleDef *m,
|
||||
JSAtom export_name)
|
||||
{
|
||||
JSExportEntry *me;
|
||||
|
|
@ -27241,6 +27241,37 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
|
|||
return -1;
|
||||
}
|
||||
|
||||
JSValueConst 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);
|
||||
}
|
||||
|
||||
JSValueConst 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);
|
||||
}
|
||||
|
||||
void JS_SetModuleLoaderFunc(JSRuntime *rt,
|
||||
JSModuleNormalizeFunc *module_normalize,
|
||||
JSModuleLoaderFunc *module_loader, void *opaque)
|
||||
|
|
|
|||
|
|
@ -1038,6 +1038,11 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
|
|||
JSValue val);
|
||||
int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
|
||||
const JSCFunctionListEntry *tab, int len);
|
||||
/* can only be called after the module is initialized */
|
||||
JSValueConst JS_GetModuleExport(JSContext *ctx, const JSModuleDef *m, const char *export_name);
|
||||
int JS_CountModuleExport(JSContext *ctx, const JSModuleDef *m);
|
||||
JSAtom JS_GetModuleExportName(JSContext *ctx, const JSModuleDef *m, int idx);
|
||||
JSValueConst JS_GetModuleExportValue(JSContext *ctx, const JSModuleDef *m, int idx);
|
||||
|
||||
#undef js_unlikely
|
||||
#undef js_force_inline
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue