Skip to content

Commit

Permalink
node: return export property for cached modules
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Jan 17, 2024
1 parent a51af38 commit 50ffedf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/dash_node_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Object for RequireFunction {
};

if let Some(module) = self.state.ongoing_requires.borrow().get(&canonicalized_path) {
return Ok(module.clone().into());
return module.get_property(scope, exports.into());
}

let source = match std::fs::read_to_string(&canonicalized_path) {
Expand Down
12 changes: 10 additions & 2 deletions crates/dash_vm/src/value/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ impl Object for Undefined {
sc: &mut LocalScope,
key: PropertyKey,
) -> Result<Option<PropertyValue>, Unrooted> {
throw!(sc, TypeError, "Cannot read property {:?} of undefined", key)
let key = match key {
PropertyKey::String(s) => s.res(sc).to_owned(),
PropertyKey::Symbol(s) => sc.interner.resolve(s.sym()).to_owned(),
};
throw!(sc, TypeError, "Cannot read property {} of undefined", key)
}

fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, _value: PropertyValue) -> Result<(), Value> {
Expand Down Expand Up @@ -258,7 +262,11 @@ impl Object for Null {
sc: &mut LocalScope,
key: PropertyKey,
) -> Result<Option<PropertyValue>, Unrooted> {
throw!(sc, TypeError, "Cannot read property {:?} of null", key)
let key = match key {
PropertyKey::String(s) => s.res(sc).to_owned(),
PropertyKey::Symbol(s) => sc.interner.resolve(s.sym()).to_owned(),
};
throw!(sc, TypeError, "Cannot read property {} of null", key)
}

fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, _value: PropertyValue) -> Result<(), Value> {
Expand Down

0 comments on commit 50ffedf

Please sign in to comment.