Fix REPL timeout with return statements by wrapping user code in function

- User code with return statement was exiting the async IIFE early
- Completion callbacks and window.complete() were never reached
- Now wrap user code in userCodeFunc to capture return value
- Return statement returns from userCodeFunc, not outer IIFE
- Completion callbacks and window.complete() always execute
- Return value is logged to console output
- Fixes 30-second timeout when using return statements in REPL
This commit is contained in:
Mario Zechner 2025-10-09 20:43:39 +02:00
parent fdd4e24246
commit 9a3f01fcb8

View file

@ -328,7 +328,17 @@ export class SandboxIframe extends LitElement {
<script type="module">
(async () => {
try {
${userCode}
// Wrap user code in async function to capture return value
const userCodeFunc = async () => {
${userCode}
};
const returnValue = await userCodeFunc();
// Log return value if present
if (returnValue !== undefined) {
console.log('Return value:', returnValue);
}
// Call completion callbacks before complete()
if (window.__completionCallbacks && window.__completionCallbacks.length > 0) {