[oden-js] Fix various bugs in module loader
This commit is contained in:
parent
db8a5f8eed
commit
9e685bc569
2 changed files with 15 additions and 7 deletions
|
|
@ -9,7 +9,7 @@ pub enum ModuleSource<'a> {
|
|||
}
|
||||
|
||||
pub trait ModuleLoader {
|
||||
fn load(&mut self, context: &ContextRef, name: &str) -> Result<ModuleSource>;
|
||||
fn load(&self, context: &ContextRef, name: &str) -> Result<ModuleSource>;
|
||||
}
|
||||
|
||||
pub struct DefaultModuleLoader {}
|
||||
|
|
@ -21,7 +21,7 @@ impl DefaultModuleLoader {
|
|||
}
|
||||
|
||||
impl ModuleLoader for DefaultModuleLoader {
|
||||
fn load(&mut self, _context: &ContextRef, name: &str) -> Result<ModuleSource> {
|
||||
fn load(&self, _context: &ContextRef, name: &str) -> Result<ModuleSource> {
|
||||
// Attempt to open the file.
|
||||
let path = Path::new(name);
|
||||
match std::fs::read_to_string(path) {
|
||||
|
|
@ -34,7 +34,7 @@ impl ModuleLoader for DefaultModuleLoader {
|
|||
pub(crate) fn load_module(
|
||||
context: &ContextRef,
|
||||
name: &str,
|
||||
loader: &mut Box<dyn ModuleLoader>,
|
||||
loader: &Box<dyn ModuleLoader>,
|
||||
) -> *mut sys::JSModuleDef {
|
||||
match loader.load(context, name) {
|
||||
Ok(ModuleSource::Native(native)) => native.module,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue