Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dprint-plugin-json = "0.20.0"
indexmap = "2.9.0"
image = "0.25.6"
libsui = "0.10.0"
nova_vm = { git = "https://github.com/trynova/nova", rev = "7d1da0bd906ab7b8409878b41bd611f172789ce9", features = [
nova_vm = { git = "https://github.com/trynova/nova", rev = "662b0b3d865e62edc7e83229cf0194fe2c981a35", features = [
"typescript"
] }
nu-ansi-term = "0.50.1"
Expand Down
57 changes: 51 additions & 6 deletions core/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ use nova_vm::{
builtins::promise_objects::promise_abstract_operations::promise_capability_records::PromiseCapability,
execution::{
Agent, JsResult,
agent::{GcAgent, HostHooks, Job, Options, RealmRoot},
agent::{ExceptionType, GcAgent, HostHooks, Job, Options, RealmRoot},
},
scripts_and_modules::script::{parse_script, script_evaluation},
types::{self, Object, Value},
scripts_and_modules::{
module::module_semantics::{
cyclic_module_records::GraphLoadingStateRecord,
finish_loading_imported_module,
source_text_module_records::{SourceTextModule, parse_module},
},
script::{HostDefined, parse_script, script_evaluation},
},
types::{Object, String as JsString, Value},
},
engine::context::{Bindable, GcScope},
engine::context::{Bindable, GcScope, NoGcScope},
};

use crate::{
Expand Down Expand Up @@ -64,6 +71,44 @@ impl<UserMacroTask: 'static> HostHooks for RuntimeHostHooks<UserMacroTask> {
fn get_host_data(&self) -> &dyn Any {
&self.host_data
}

fn load_imported_module<'gc>(
&self,
agent: &mut Agent,
referrer: SourceTextModule<'gc>,
module_request: &str,
host_defined: Option<HostDefined>,
payload: &mut GraphLoadingStateRecord<'gc>,
gc: NoGcScope<'gc, '_>,
) {
let file = match std::fs::read_to_string(module_request) {
Ok(file) => file,
Err(err) => {
let result = Err(agent.throw_exception(ExceptionType::Error, err.to_string(), gc));
finish_loading_imported_module(
agent,
referrer,
module_request,
payload,
result,
gc,
);
return;
}
};
let source_text = JsString::from_string(agent, file, gc);
let result = parse_module(
agent,
source_text,
referrer.realm(agent),
host_defined.clone(),
gc,
)
.map_err(|err| {
agent.throw_exception(ExceptionType::Error, err.first().unwrap().to_string(), gc)
});
finish_loading_imported_module(agent, referrer, module_request, payload, result, gc);
}
}

pub type EventLoopHandler<UserMacroTask> = fn(
Expand Down Expand Up @@ -206,7 +251,7 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
self.agent.run_in_realm(&self.realm_root, |agent, mut gc| {
for builtin in &self.config.builtins {
let realm = agent.current_realm(gc.nogc());
let source_text = types::String::from_str(agent, builtin, gc.nogc());
let source_text = JsString::from_str(agent, builtin, gc.nogc());
let script = match parse_script(
agent,
source_text,
Expand Down Expand Up @@ -253,7 +298,7 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
continue;
}
result = self.agent.run_in_realm(&self.realm_root, |agent, mut gc| {
let source_text = types::String::from_string(agent, file_content, gc.nogc());
let source_text = JsString::from_string(agent, file_content, gc.nogc());
let realm = agent.current_realm(gc.nogc());

let script = match parse_script(
Expand Down
1 change: 1 addition & 0 deletions examples/export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const tryAndromeda = true;
3 changes: 3 additions & 0 deletions examples/import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { tryAndromeda } from './export.ts'

console.log(tryAndromeda)
Loading