summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-12-10 00:04:46 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-10 11:23:23 +0000
commit3a8c704d19de25c1e3021ee327f078df540e638b (patch)
tree27b0a7efc27db83f61afa32a9db0182f174a67af /Userland/Libraries/LibJS/Runtime
parente53c8ae593d5dc95ae7e9684559985ec763bb545 (diff)
downloadserenity-3a8c704d19de25c1e3021ee327f078df540e638b.zip
LibJS: Add spec comments to less_than_equals()
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index 50de732bd9..37b6a045f5 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -1282,13 +1282,24 @@ ThrowCompletionOr<Value> less_than(VM& vm, Value lhs, Value rhs)
}
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
+// RelationalExpression : RelationalExpression <= ShiftExpression
ThrowCompletionOr<Value> less_than_equals(VM& vm, Value lhs, Value rhs)
{
+ // 1. Let lref be ? Evaluation of RelationalExpression.
+ // 2. Let lval be ? GetValue(lref).
+ // 3. Let rref be ? Evaluation of ShiftExpression.
+ // 4. Let rval be ? GetValue(rref).
+ // NOTE: This is handled in the AST or Bytecode interpreter.
+
+ // OPTIMIZATION: If both values are i32, we can do a direct comparison without calling into IsLessThan.
if (lhs.is_int32() && rhs.is_int32())
return lhs.as_i32() <= rhs.as_i32();
- TriState relation = TRY(is_less_than(vm, lhs, rhs, false));
- if (relation == TriState::Unknown || relation == TriState::True)
+ // 5. Let r be ? IsLessThan(rval, lval, false).
+ auto relation = TRY(is_less_than(vm, lhs, rhs, false));
+
+ // 6. If r is true or undefined, return false. Otherwise, return true.
+ if (relation == TriState::True || relation == TriState::Unknown)
return Value(false);
return Value(true);
}