From 6e29256ee914ecf9984547d3551cd7a5e8084834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kr=C3=BChlmann?= Date: Thu, 8 Jan 2026 13:32:30 +0100 Subject: [PATCH] Update placeholder and validation --- .../resources/static/js/broadcastRuntime.js | 0 .../resources/static/js/broadcastWorkers.js | 2 + src/main/resources/static/js/customAssets.js | 40 ++++++++++++++++--- src/main/resources/templates/admin.html | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/static/js/broadcastRuntime.js create mode 100644 src/main/resources/static/js/broadcastWorkers.js diff --git a/src/main/resources/static/js/broadcastRuntime.js b/src/main/resources/static/js/broadcastRuntime.js new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/static/js/broadcastWorkers.js b/src/main/resources/static/js/broadcastWorkers.js new file mode 100644 index 0000000..0b915f3 --- /dev/null +++ b/src/main/resources/static/js/broadcastWorkers.js @@ -0,0 +1,2 @@ +function spawnUserJavaScriptWorker(jsSource, data) { +} diff --git a/src/main/resources/static/js/customAssets.js b/src/main/resources/static/js/customAssets.js index 45d52e2..3b70d9d 100644 --- a/src/main/resources/static/js/customAssets.js +++ b/src/main/resources/static/js/customAssets.js @@ -43,12 +43,42 @@ function getUserJavaScriptSourceError(src) { return { title: "Syntax Error", details: e.message }; } - const functionNames = ast.body.filter((node) => node.type === "FunctionDeclaration").map((node) => node.id.name); - if (!functionNames.includes("init")) { - return { title: "Missing function: init", details: "Your code must include a function named 'init'." }; + let hasInit = false; + let hasTick = false; + + for (const node of ast.body) { + if (node.type !== "ExpressionStatement") continue; + + const expr = node.expression; + if (expr.type !== "AssignmentExpression") continue; + + const left = expr.left; + const right = expr.right; + + if ( + left.type === "MemberExpression" && + left.object.type === "Identifier" && + left.object.name === "exports" && + left.property.type === "Identifier" && + (right.type === "FunctionExpression" || right.type === "ArrowFunctionExpression") + ) { + if (left.property.name === "init") hasInit = true; + if (left.property.name === "tick") hasTick = true; + } } - if (!functionNames.includes("tick")) { - return { title: "Missing function: tick", details: "Your code must include a function named 'tick'." }; + + if (!hasInit) { + return { + title: "Missing function: init", + details: "You must assign a function to exports.init", + }; + } + + if (!hasTick) { + return { + title: "Missing function: tick", + details: "You must assign a function to exports.tick", + }; } return undefined; diff --git a/src/main/resources/templates/admin.html b/src/main/resources/templates/admin.html index 4bc8ba5..a10757a 100644 --- a/src/main/resources/templates/admin.html +++ b/src/main/resources/templates/admin.html @@ -392,7 +392,7 @@