[quickjs-devel] Patch: Add some informations to get more informations from compiled modules

  • From: Geequ lim <geequlim@xxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Sun, 8 Dec 2019 14:59:52 +0800

Add funtions to get more informations of modules

int JS_GetModuleExportEntriesCount(JSModuleDef *m);
JSValue JS_GetModuleExportEntry(JSContext *ctx, JSModuleDef *m, int idx);
JSAtom JS_GetModuleExportEntryName(JSContext *ctx, JSModuleDef *m, int idx);

And add a function to check is a function object is a CFunction

JS_BOOL JS_IsPureCFunction(JSContext *ctx, JSValue val);

Thanks,
Geequlim
--- quickjs-2019-10-27/quickjs.h
+++ quickjs-2019-10-27/quickjs.h
@@ -912,6 +912,12 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, 
const char *export_name,
 int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
                            const JSCFunctionListEntry *tab, int len);
 
+int JS_GetModuleExportEntriesCount(JSModuleDef *m);
+JSValue JS_GetModuleExportEntry(JSContext *ctx, JSModuleDef *m, int idx);
+JSAtom JS_GetModuleExportEntryName(JSContext *ctx, JSModuleDef *m, int idx);
+
+JS_BOOL JS_IsPureCFunction(JSContext *ctx, JSValue val);
+
 #undef js_unlikely
 #undef js_force_inline

--- quickjs-2019-10-27/quickjs.c
+++ quickjs-2019-10-27/quickjs.c
@@ -33435,6 +33435,34 @@ int JS_SetModuleExportList(JSContext *ctx, JSModuleDef 
*m,
     return 0;
 }
 
+int JS_GetModuleExportEntriesCount(JSModuleDef *m)
+{
+    return m->export_entries_count;
+}
+
+JSValue JS_GetModuleExportEntry(JSContext *ctx, 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);
+}
+
+JSAtom JS_GetModuleExportEntryName(JSContext *ctx, 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);
+}
+
+JS_BOOL JS_IsPureCFunction(JSContext *ctx, JSValue val)
+{
+    JSObject *p;
+    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
+        return FALSE;
+    p = JS_VALUE_GET_OBJ(val);
+    return p->class_id == JS_CLASS_C_FUNCTION;
+}
+
 /* Note: 'func_obj' is not necessarily a constructor */
 static void JS_SetConstructor2(JSContext *ctx,
                                JSValueConst func_obj,

Other related posts:

  • » [quickjs-devel] Patch: Add some informations to get more informations from compiled modules - Geequ lim