From 45aeffb0ee0e1e7d90e6f456006505f040fd8e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=9D=A5=EC=88=98=20=5BFrontend=5D?= Date: Fri, 31 Oct 2025 10:17:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20run=20js=20=EC=B2=98=EB=9F=BC=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=EA=B0=92=EC=9D=84=20=EB=85=B8=EC=B6=9C?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/deno-runtime/src/lib.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/deno-runtime/src/lib.rs b/crates/deno-runtime/src/lib.rs index 8167c33..90341b6 100644 --- a/crates/deno-runtime/src/lib.rs +++ b/crates/deno-runtime/src/lib.rs @@ -93,7 +93,6 @@ fn op_custom_print(#[string] message: String, is_err: bool) -> Result<(), AnyErr Ok(()) } -/// 커스텀 확장 정의 extension!( executejs_runtime, ops = [op_console_log, op_alert, op_custom_print], @@ -146,16 +145,33 @@ impl DenoExecutor { return Err(anyhow::anyhow!("Bootstrap 실행 실패: {}", e)); } + // 사용자 코드를 래핑하여 마지막 표현식의 결과를 자동으로 출력 + // eval을 사용하여 마지막 표현식의 결과를 캡처하고 출력 + let wrapped_code = format!( + r#" + (function() {{ + try {{ + const code_output = eval(`{}`); + if (code_output !== undefined) {{ + Deno.core.ops.op_console_log(String(code_output)); + }} + return code_output; + }} catch (e) {{ + // eval 실패 시 원본 코드를 그대로 실행 + throw e; + }} + }})(); + "#, + code.replace('`', r"\`").replace('\\', r"\\") + ); + // 코드 실행 - let result = js_runtime.execute_script("[executejs:user_code]", code)?; + let _result = js_runtime.execute_script("[executejs:user_code]", wrapped_code)?; // 이벤트 루프 실행 (Promise 처리) - 블로킹 방식으로 변경 let rt = tokio::runtime::Handle::current(); rt.block_on(async { js_runtime.run_event_loop(Default::default()).await })?; - // 결과 처리 - let _ = result; - // 출력 버퍼에서 결과 가져오기 let output = output_buffer.lock().unwrap(); let result_text = output.get_output(); From d3628e2e16d3df3743f0b7f0396c54ac436a2c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=9D=A5=EC=88=98=20=5BFrontend=5D?= Date: Fri, 31 Oct 2025 10:30:42 +0900 Subject: [PATCH 2/2] chore: typo --- crates/deno-runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/deno-runtime/src/lib.rs b/crates/deno-runtime/src/lib.rs index 90341b6..8736a4a 100644 --- a/crates/deno-runtime/src/lib.rs +++ b/crates/deno-runtime/src/lib.rs @@ -166,7 +166,7 @@ impl DenoExecutor { ); // 코드 실행 - let _result = js_runtime.execute_script("[executejs:user_code]", wrapped_code)?; + let result = js_runtime.execute_script("[executejs:user_code]", wrapped_code)?; // 이벤트 루프 실행 (Promise 처리) - 블로킹 방식으로 변경 let rt = tokio::runtime::Handle::current();