Files
reverse-engineering-anything/scripts/verify/completed-abort-guard.mjs
T
gensokyo-devandgensokyo-dev a80dc68318 refactor(verify): exclude negated .ok checks from the abort-reclassification guard
The completed-abort-reclassification pattern matched any `.ok && …aborted`,
including `!outcome.ok && signal?.aborted`, which attaches a secondary
cancellation to an already failed primary and reclassifies nothing. Move
the pattern to completed-abort-guard.mjs, where the receiver chain
(member, optional, private, element and call segments) must start the
check, and cover positive and negated forms in tests.
DesktopApplicationState and FridaInstrumentationService leave the
baseline.

Fixes #11920

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-11-21 19:07:31 +01:00

19 lines
1.1 KiB
JavaScript

// Counts completed results reclassified by a hand-read abort signal:
// `<receiver>.ok && isAborted(…)` or `<receiver>.ok && …signal.aborted`.
// The receiver chain must start the check, so a negated `!outcome.ok && …`,
// which attaches a secondary cancellation to a failed primary, is not
// counted. Receivers may use member, optional, private, element and call
// segments, or start with one parenthesized expression, and each part may
// carry a TypeScript non-null assertion (`result!.ok`). Parentheses may nest
// one level, as in `(await settle()).ok`; element brackets cannot nest.
const parenthesized = String.raw`\((?:[^()]|\([^()]*\))*\)`;
const segment = String.raw`(?:(?:\??\.#?[A-Za-z_$][\w$]*|(?:\?\.)?\[[^[\]]*\]|(?:\?\.)?${parenthesized})!?)`;
const completedAbortReclassification = new RegExp(
String.raw`(?<![\w$#.?\])]|!\s*)(?:[A-Za-z_$][\w$]*|${parenthesized})!?${segment}*\??\.ok\s*&&\s*(?:isAborted\(|[\w.?]*signal\??\.aborted)`,
"gu",
);
/** @param {string} content */
export const completedAbortReclassificationCount = (content) =>
content.match(completedAbortReclassification)?.length ?? 0;