diff options
author | Linus Groh <mail@linusgroh.de> | 2022-12-10 00:10:43 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-10 11:23:23 +0000 |
commit | abf1ba89cdfeb05cb5bba0dde31007235cc82b96 (patch) | |
tree | a1f4bc4468a597539e52bef31efc4800bacb9fe5 /Userland/Libraries/LibJS | |
parent | 625ad4192f07a01a98825cefa451396229123cfd (diff) | |
download | serenity-abf1ba89cdfeb05cb5bba0dde31007235cc82b96.zip |
LibJS: Add spec comments to same_value_non_numeric()
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Value.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 9bf97cdd92..062e2ad59e 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -2150,15 +2150,31 @@ bool same_value_zero(Value lhs, Value rhs) return same_value_non_numeric(lhs, rhs); } -// 7.2.12 SameValueNonNumeric ( x, y ), https://tc39.es/ecma262/#sec-samevaluenonnumeric +// 7.2.12 SameValueNonNumber ( x, y ), https://tc39.es/ecma262/#sec-samevaluenonnumeric +// FIXME: Rename this to same_value_non_number() bool same_value_non_numeric(Value lhs, Value rhs) { - VERIFY(!lhs.is_number() && !lhs.is_bigint()); + // 1. Assert: Type(x) is the same as Type(y). VERIFY(same_type_for_equality(lhs, rhs)); + VERIFY(!lhs.is_number()); - if (lhs.is_string()) + // FIXME: 2. If x is a BigInt, then + // a. Return BigInt::equal(x, y). + + // 5. If x is a String, then + if (lhs.is_string()) { + // a. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return true; otherwise, return false. return lhs.as_string().deprecated_string() == rhs.as_string().deprecated_string(); + } + // 3. If x is undefined, return true. + // 4. If x is null, return true. + // 6. If x is a Boolean, then + // a. If x and y are both true or both false, return true; otherwise, return false. + // 7. If x is a Symbol, then + // a. If x and y are both the same Symbol value, return true; otherwise, return false. + // 8. If x and y are the same Object value, return true. Otherwise, return false. + // NOTE: All the options above will have the exact same bit representation in Value, so we can directly compare the bits. return lhs.m_value.encoded == rhs.m_value.encoded; } |