mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 03:57:15 +02:00
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:
Notes:
github-actions[bot]
2026-02-06 11:19:25 +00:00
Author: https://github.com/dosisod Commit: https://github.com/LadybirdBrowser/ladybird/commit/ac8cc6d24be Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7451
@@ -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 {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user