Skip to content

Commit 04fc7e0

Browse files
test(javascript): let the runtime decide how deep the corpus may nest
acorn records `~Not enough stack space` for its deeply nested case, and the comparison allowed for the two parsers reaching that depth a few frames apart. It did not allow for a runtime reaching it on neither side: under Bun both parse the case, so the recorded expectation goes unmet and the verdicts differ from acorn's on V8. Stack depth is the runtime's answer rather than the parser's, so a verdict or a recorded expectation naming it is left alone on either side.
1 parent 74f50d7 commit 04fc7e0

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎test/unitCases/WebpackParser.unittest.js‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,9 +2570,17 @@ const MODES = [
25702570
["as commonjs", { sourceType: "commonjs" }]
25712571
];
25722572

2573-
// Both parsers give up on input nested deeper than the stack takes, at the
2574-
// depth their own frames allow — the same verdict, reached a few frames apart.
2575-
const STACK_LIMIT = "Not enough stack space to parse input";
2573+
// How deep input may nest before a parser gives up is the runtime's answer,
2574+
// not the parser's — JavaScriptCore reaches the depth acorn recorded on
2575+
// neither side. The phrase is what a thrown message and that record share.
2576+
const STACK_LIMIT = "Not enough stack space";
2577+
2578+
/**
2579+
* @param {string=} verdict a parse verdict, or acorn's recorded expectation
2580+
* @returns {boolean} whether it is a parser running out of stack
2581+
*/
2582+
const isStackDepth = (verdict) =>
2583+
verdict !== undefined && verdict.includes(STACK_LIMIT);
25762584

25772585
/**
25782586
* Whether this host's own `RegExp` built every pattern in a tree, and there was
@@ -2714,10 +2722,9 @@ const compareCase = (testCase, parse, engineValidates, mode, trees, verdicts) =>
27142722
}
27152723

27162724
if (ourVerdict !== theirVerdict) {
2717-
const bothRanOut =
2718-
ourVerdict.startsWith(STACK_LIMIT) && theirVerdict.startsWith(STACK_LIMIT);
27192725
if (
2720-
bothRanOut ||
2726+
isStackDepth(ourVerdict) ||
2727+
isStackDepth(theirVerdict) ||
27212728
(engineValidates && isEngineValidated(ours, theirVerdict))
27222729
) {
27232730
return;
@@ -2752,6 +2759,7 @@ const compareCase = (testCase, parse, engineValidates, mode, trees, verdicts) =>
27522759
* @returns {boolean} whether the case passes acorn's own assertion
27532760
*/
27542761
const meetsExpectation = (testCase, verdict) => {
2762+
if (isStackDepth(testCase.error) || isStackDepth(verdict)) return true;
27552763
if (testCase.error === undefined) return verdict === "parsed";
27562764
return testCase.error.startsWith("~")
27572765
? verdict.includes(testCase.error.slice(1))

0 commit comments

Comments
 (0)