-
Notifications
You must be signed in to change notification settings - Fork 0
함수의 return값도 결과로 노출하도록 수정 제안 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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"\\") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+154
to
+165
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"\\") | |
| const code_output = eval(`{code}`); | |
| if (code_output !== undefined) {{ | |
| Deno.core.ops.op_console_log(String(code_output)); | |
| }} | |
| return code_output; | |
| }} catch (e) {{ | |
| // eval 실패 시 원본 코드를 그대로 실행 | |
| try { | |
| const fallback_output = (function() {{ {} }})(); | |
| if (fallback_output !== undefined) {{ | |
| Deno.core.ops.op_console_log(String(fallback_output)); | |
| }} | |
| return fallback_output; | |
| } catch (fallbackError) {{ | |
| throw fallbackError; | |
| }} | |
| const fallback_output = (function() {{ {code} }})(); | |
| if (fallback_output !== undefined) {{ | |
| Deno.core.ops.op_console_log(String(fallback_output)); | |
| }} | |
| return fallback_output; | |
| }} catch (fallbackError) {{ | |
| throw fallbackError; | |
| }} | |
| }} | |
| }})(); | |
| "#, | |
| code = code.replace('`', r"\`").replace('\\', r"\\") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The escaping order is incorrect and will cause double-escaping issues. Backslashes must be escaped before backticks to prevent already-escaped sequences from being corrupted. For example, the input
\\would become\\\\(correct), but then backticks in that result would be incorrectly escaped. Change tocode.replace('\\', r\"\\\\").replace('', r"`")` to escape backslashes first.