Skip to content

Commit cdfe44b

Browse files
committed
clean up
1 parent abd51f0 commit cdfe44b

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

cli/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This Source Code Form is subject to the terms of the Mozilla Public
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4-
use andromeda_core::{Runtime, RuntimeConfig, RuntimeData};
4+
use andromeda_core::{HostData, Runtime, RuntimeConfig};
55
use andromeda_runtime::{
66
recommended_builtins, recommended_eventloop_handler, recommended_extensions,
77
};
@@ -50,6 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5050
paths,
5151
} => {
5252
let (macro_task_tx, macro_task_rx) = std::sync::mpsc::channel();
53+
let host_data = HostData::new(macro_task_tx);
5354
let runtime = Runtime::new(
5455
RuntimeConfig {
5556
no_strict,
@@ -58,11 +59,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5859
extensions: recommended_extensions(),
5960
builtins: recommended_builtins(),
6061
eventloop_handler: recommended_eventloop_handler,
61-
},
62-
RuntimeData {
63-
macro_task_tx,
6462
macro_task_rx,
6563
},
64+
host_data,
6665
);
6766
let mut runtime_output = runtime.run();
6867

core/src/runtime.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use std::{
33
borrow::BorrowMut,
44
cell::RefCell,
55
collections::VecDeque,
6-
sync::{
7-
atomic::Ordering,
8-
mpsc::{Receiver, Sender},
9-
},
6+
sync::{atomic::Ordering, mpsc::Receiver},
107
};
118

129
use nova_vm::{
@@ -82,12 +79,7 @@ pub struct RuntimeConfig<UserMacroTask: 'static> {
8279
pub builtins: Vec<&'static str>,
8380
/// User event loop handler.
8481
pub eventloop_handler: EventLoopHandler<UserMacroTask>,
85-
}
86-
87-
pub struct RuntimeData<UserMacroTask: 'static> {
88-
/// Macro tasks sender.
89-
pub macro_task_tx: Sender<MacroTask<UserMacroTask>>,
90-
/// Macro tasks receiver.
82+
/// Macro tasks eventloop receiver.
9183
pub macro_task_rx: Receiver<MacroTask<UserMacroTask>>,
9284
}
9385

@@ -96,13 +88,14 @@ pub struct Runtime<UserMacroTask: 'static> {
9688
pub agent: GcAgent,
9789
pub realm_root: RealmRoot,
9890
pub host_hooks: &'static RuntimeHostHooks<UserMacroTask>,
99-
pub macro_task_rx: Receiver<MacroTask<UserMacroTask>>,
10091
}
10192

10293
impl<UserMacroTask> Runtime<UserMacroTask> {
10394
/// Create a new [Runtime] given a [RuntimeConfig]. Use [Runtime::run] to run it.
104-
pub fn new(mut config: RuntimeConfig<UserMacroTask>, data: RuntimeData<UserMacroTask>) -> Self {
105-
let host_data = HostData::new(data.macro_task_tx);
95+
pub fn new(
96+
mut config: RuntimeConfig<UserMacroTask>,
97+
host_data: HostData<UserMacroTask>,
98+
) -> Self {
10699
let host_hooks = RuntimeHostHooks::new(host_data);
107100

108101
let host_hooks: &RuntimeHostHooks<UserMacroTask> = &*Box::leak(Box::new(host_hooks));
@@ -135,7 +128,6 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
135128
agent,
136129
realm_root,
137130
host_hooks,
138-
macro_task_rx: data.macro_task_rx,
139131
}
140132
}
141133

@@ -214,7 +206,7 @@ impl<UserMacroTask> Runtime<UserMacroTask> {
214206

215207
// Listen for pending macro tasks and resolve one by one
216208
pub fn handle_macro_task(&mut self) {
217-
match self.macro_task_rx.recv() {
209+
match self.config.macro_task_rx.recv() {
218210
Ok(MacroTask::ResolvePromise(root_value)) => {
219211
self.agent.run_in_realm(&self.realm_root, |agent, gc| {
220212
let value = root_value.take(agent);

0 commit comments

Comments
 (0)