Skip to content

Conversation

@Enjoywater
Copy link
Collaborator

📌 요약

  • 함수 실행값 및 단순 연산 출력

📝 작업 내용

  • runJS 처럼 동작하게 함수 return도 출력하도록 수정

🔍 스크린샷

before

스크린샷 2025-10-31 09 58 38

after

2025-10-31.10.22.30.mov

💡 참고 사항

@Enjoywater Enjoywater self-assigned this Oct 31, 2025
@Enjoywater Enjoywater added the enhancement New feature or request label Oct 31, 2025
@Enjoywater Enjoywater requested a review from ohah October 31, 2025 01:27
@ohah ohah requested a review from Copilot October 31, 2025 04:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the JavaScript code execution functionality by automatically capturing and displaying the result of the last expression in user-submitted code. It also removes a Korean comment and eliminates unused result handling code.

  • Wraps user code in an IIFE that uses eval() to capture and automatically log the last expression's result
  • Escapes backticks and backslashes in user code to prevent injection issues when embedding in template literals
  • Removes unused result variable and related comment
Comments suppressed due to low confidence (1)

crates/deno-runtime/src/lib.rs:1

  • Using eval() introduces security risks and can execute arbitrary code. Since the user code is already being executed via execute_script, wrapping it in eval() is redundant and dangerous. Consider using a different approach such as wrapping the code in an expression statement or using the return value from execute_script directly.
use anyhow::Result;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}}
}})();
"#,
code.replace('`', r"\`").replace('\\', r"\\")
Copy link

Copilot AI Oct 31, 2025

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 to code.replace('\\', r\"\\\\").replace('', r"`")` to escape backslashes first.

Suggested change
code.replace('`', r"\`").replace('\\', r"\\")
code.replace('\\', r"\\").replace('`', r"\`")

Copilot uses AI. Check for mistakes.
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"\\")
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states 'eval 실패 시 원본 코드를 그대로 실행' (when eval fails, execute original code as-is), but the code throws the error instead of falling back to executing the original code. Either update the comment to reflect the actual behavior ('eval 실패 시 에러를 전파' - propagate error when eval fails) or implement the fallback logic described in the comment.

Suggested change
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"\\")

Copilot uses AI. Check for mistakes.
@Enjoywater
Copy link
Collaborator Author

정확한 에러라인을 찾을 수 없어서 close

@Enjoywater Enjoywater closed this Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants