1
Fork 0
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:
Stephan Unverwerth 2020-04-03 19:11:31 +02:00 committed by Andreas Kling
parent a2b0cc8f08
commit 520311eb8b
2 changed files with 28 additions and 4 deletions

View 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);
}