test fix function body extraction in web check

This commit is contained in:
Codex
2026-05-25 04:50:38 +00:00
parent da296e8aa8
commit bfa0f02688
+19 -3
View File
@@ -1340,10 +1340,26 @@ function compactLayoutFailure(failure) {
}
function functionBody(source, functionName) {
const match = source.match(new RegExp(`function\\s+${escapeRegExp(functionName)}\\s*\\([^)]*\\)\\s*\\{`, "u"));
if (!match) return "";
const match = source.match(new RegExp(`(?:async\\s+)?function\\s+${escapeRegExp(functionName)}\\s*\\(`, "u"));
if (!match || typeof match.index !== "number") return "";
let signatureIndex = match.index + match[0].length - 1;
let signatureDepth = 0;
let bodyStart = -1;
for (let index = signatureIndex; index < source.length; index += 1) {
const char = source[index];
if (char === "(") signatureDepth += 1;
if (char === ")") {
signatureDepth -= 1;
continue;
}
if (signatureDepth === 0 && char === "{") {
bodyStart = index;
break;
}
}
if (bodyStart === -1) return "";
let depth = 0;
for (let index = match.index + match[0].length - 1; index < source.length; index += 1) {
for (let index = bodyStart; index < source.length; index += 1) {
const char = source[index];
if (char === "{") depth += 1;
if (char === "}") {