Files
reverse-engineering-anything/src/wasm/WabtComment.ts
T
morlutoandCursor Agent 317bf3fe23 fix: report provider admission failures as typed codes (#8066)
* fix: report provider admission failures as typed codes

* fix(evm): keep limiter path on admission diagnostics

* fix: assert WABT and CBOR admission codes

* fix: keep admission details on returned failures

* fix(evm): detect repeated CBOR keys in the decoder

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-10-30 06:48:01 +08:00

31 lines
1.0 KiB
TypeScript

import { WabtAdmissionError } from "./WabtAdmissionError.js";
/** Skip a WAT comment without interpreting its punctuation as forms or strings. */
export const watCommentEnd = (
text: string,
start: number,
): number | undefined => {
if (text.startsWith(";;", start)) {
// WAT admits LF, CR, and CRLF as newlines; neither CR nor LF is
// comment content, even when a producer uses CR-only output.
for (let index = start + 2; index < text.length; index++) {
if (text[index] === "\n") return index + 1;
if (text[index] === "\r")
return index + (text[index + 1] === "\n" ? 2 : 1);
}
return text.length;
}
if (!text.startsWith("(;", start)) return undefined;
let depth = 1;
for (let index = start + 2; index < text.length - 1; index++) {
if (text.startsWith("(;", index)) {
depth++;
index++;
} else if (text.startsWith(";)", index)) {
if (--depth === 0) return index + 2;
index++;
}
}
throw new WabtAdmissionError("incomplete_comment");
};