[quickjs-devel] Push imported variable names to globalThis automatically

  • From: Dimitris Karnikis <dkarnikis@xxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Sun, 24 Oct 2021 10:21:02 +0300

Hello devs,

I would like to automatically push the imported variable names from a
module to globalThis.
In particular, let's assume the following sample:

import {math} from "./math.js";

print(math) // will print my function source code
print(globalThis[math]) // will print undefined, how can I auto-assign math
to globalThis

I know I could just do: globalThis[math] = math
However, I need to automate this process when importing a library during
the import in C.

My end goal is to perform some transformations/hooks to the library when it
is imported (that's why I am trying to fetch the imported name). I have
already managed to remove the const property from the math variable when
importing the library (via C), so any changes to the interpreter itself are
also acceptable (and preferred).

Thank you,
Dimitris

Other related posts:

  • » [quickjs-devel] Push imported variable names to globalThis automatically - Dimitris Karnikis