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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user