diff --git a/jstz_cli/src/repl.rs b/jstz_cli/src/repl.rs index ca371fb1b..e56049fc1 100644 --- a/jstz_cli/src/repl.rs +++ b/jstz_cli/src/repl.rs @@ -104,38 +104,31 @@ pub fn exec(self_address: Option) -> Result<()> { fn evaluate(input: &str, rt: &mut Runtime, hrt: &mut (impl HostRuntime + 'static)) { let rt_output = runtime::with_host_runtime(hrt, || -> JsResult { let value = rt.eval(Source::from_bytes(input))?; - - jstz_core::future::block_on(rt.run_event_loop()); - - Ok(value) + jstz_core::future::block_on(async { + rt.run_event_loop().await; + rt.resolve_value(&value).await + }) }); - jstz_core::future::block_on(async move { - match rt_output { - Ok(mut res) => { - if res.is_promise() { - if let Ok(promise_result) = rt.resolve_value(&res).await { - res = promise_result; - } - } - if !res.is_undefined() { - println!( - "{}", - res.to_string(&mut rt.context()) - .unwrap() - .to_std_string_escaped() - ); - if let Err(err) = - rt.global_object() - .set(js_string!("_"), res, false, rt.context()) - { - println!("Couldn't set '_' property: {err}"); - } - } + match rt_output { + Ok(res) => { + if !res.is_undefined() { + println!( + "{}", + res.to_string(&mut rt.context()) + .unwrap() + .to_std_string_escaped() + ); } - Err(e) => { - eprintln!("Uncaught {e}") + if let Err(err) = + rt.global_object() + .set(js_string!("_"), res, false, rt.context()) + { + println!("Couldn't set '_' property: {err}"); } } - }); + Err(e) => { + eprintln!("Uncaught {e}") + } + } }