LibJS: Constant fold LogicalExpression

Logical expressions like `true || false` are now constant folded. This
also allows for dead code elimination if we know the right-hand side of
the expression will never be evaluated (such as `false && f()` or
`true || f()`).

In the test suites, the values are now being constant folded at compile
time. To ensure that the actual evaluation logic is being called
properly, I had to duplicate the tests and call them via a function so
the compiler would not optimize the evaluation logic away.

This also demotes `NaN` and `Infinity` identifiers to `nan` and
`inf` double literals, which will further help with const folding.
This commit is contained in:
dosisod
2026-01-11 12:36:23 -08:00
committed by Andreas Kling
parent 5a8d71fb02
commit ac8cc6d24b
Notes: github-actions[bot] 2026-02-06 11:19:25 +00:00
7 changed files with 241 additions and 3 deletions

View File

@@ -1754,6 +1754,14 @@ CodeGenerationErrorOr<Optional<ScopedOperand>> Generator::maybe_generate_builtin
return add_constant(js_undefined());
}
if (constant_name == "NaN"sv) {
return add_constant(js_nan());
}
if (constant_name == "Infinity"sv) {
return add_constant(js_infinity());
}
if (!m_builtin_abstract_operations_enabled)
return OptionalNone {};