DelSkayn / rquickjs

High level bindings to the quickjs javascript engine
MIT License
504 stars 63 forks source link

Async Resolver/Loader #125

Open stevefan1999-personal opened 1 year ago

stevefan1999-personal commented 1 year ago

This would greatly help implementing import(), the dynamic import which QuickJS should support well

DelSkayn commented 1 year ago

QuickJS does indeed support dynamic imports, but it doesn't support returning a promise from the functions which resolve and load the module. The library its loader function is as follows:

typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx, const char *module_name, void *opaque);

It needs to immediately return a module after it is called so it is not possible to use async loading. The same is true for resolving. Under the hood, QuickJS does indeed generate a promise when evaluating a dynamic import but loads modules with blocking IO. I currently don't see a good way to implement this feature with out significant patches to QuickJS.