mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibJS: Add short circuit logical evaluation
When evaluating logical binop expressions, the rhs must not be evaluated if the lhs leads to the whole expression not being truthy.
This commit is contained in:
parent
a2b0cc8f08
commit
520311eb8b
2 changed files with 28 additions and 4 deletions
15
Libraries/LibJS/Tests/logical-expressions-short-circuit.js
Normal file
15
Libraries/LibJS/Tests/logical-expressions-short-circuit.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
let foo = 1;
|
||||
false && (foo = 2);
|
||||
assert(foo === 1);
|
||||
|
||||
foo = 1;
|
||||
true || (foo = 2);
|
||||
assert(foo === 1);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue