Closed richarddd closed 1 year ago
Solved it by using a wrapper around all my loaders and then setting input meta from there.
struct RawLoaderContainer<T: Loader>(T);
unsafe impl<T: Loader> RawLoader for RawLoaderContainer<T> {
unsafe fn raw_load<'js>(&mut self, ctx: Ctx<'js>, name: &str) -> Result<Module<'js>> {
let res = self.0.load(ctx, name)?.unsafe_declare(ctx)?;
set_import_meta(res, name)?;
Ok(res)
}
}
let loader = RawLoaderContainer((ModuleLoader::default(),BuiltinLoader::default()))
Since loaders now have to return
Result<ModuleData>
there is no longer a way to set input meta object since we never have access to the Module object before it's evaluated.I can work around this by implementing
RawLoader
but that requires all my loaders to implement RawLoader, and i can't use the default ones without creating wrappers for them.A solution to this could be to have an optional
fn on_load(ctx,module) -> Result<()>
for theLoader
trait