diff --git a/src/cli/javascript/runtime.rs b/src/cli/javascript/runtime.rs index b3cdb492b2..e568a060b8 100644 --- a/src/cli/javascript/runtime.rs +++ b/src/cli/javascript/runtime.rs @@ -31,12 +31,14 @@ fn setup_builtins(ctx: &Ctx<'_>) -> rquickjs::Result<()> { Ok(()) } -impl LocalRuntime { - fn try_new(script: blueprint::Script) -> anyhow::Result { +impl TryFrom for LocalRuntime { + type Error = anyhow::Error; + + fn try_from(script: blueprint::Script) -> Result { let source = script.source; let js_runtime = rquickjs::Runtime::new()?; let context = Context::full(&js_runtime)?; - context.with(|ctx| { + let _: () = context.with(|ctx| { setup_builtins(&ctx)?; ctx.eval(source) })?; @@ -126,7 +128,7 @@ fn init_rt(script: blueprint::Script) -> anyhow::Result<()> { // exit if failed to initialize LOCAL_RUNTIME.with(move |cell| { if cell.borrow().get().is_none() { - LocalRuntime::try_new(script).and_then(|runtime| { + LocalRuntime::try_from(script).and_then(|runtime| { cell.borrow().set(runtime).map_err(|_| { anyhow::anyhow!("trying to reinitialize an already initialized QuickJS runtime") })