mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Correctness fixes for bitwise_or, address FIXME's in test.
This commit is contained in:
parent
3e8cf79efa
commit
41bfff1abe
Notes:
sideshowbarker
2024-07-19 07:54:39 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/41bfff1abe9 Pull-request: https://github.com/SerenityOS/serenity/pull/1634
2 changed files with 20 additions and 8 deletions
|
@ -186,6 +186,18 @@ Value bitwise_and(Value lhs, Value rhs)
|
|||
|
||||
Value bitwise_or(Value lhs, Value rhs)
|
||||
{
|
||||
bool lhs_invalid = lhs.is_undefined() || lhs.is_null() || lhs.is_nan() || lhs.is_infinity();
|
||||
bool rhs_invalid = rhs.is_undefined() || rhs.is_null() || rhs.is_nan() || rhs.is_infinity();
|
||||
|
||||
if (lhs_invalid && rhs_invalid)
|
||||
return Value(0);
|
||||
|
||||
if (lhs_invalid || rhs_invalid)
|
||||
return lhs_invalid ? rhs.to_number() : lhs.to_number();
|
||||
|
||||
if (!rhs.is_number() && !lhs.is_number())
|
||||
return Value(0);
|
||||
|
||||
return Value((i32)lhs.to_number().as_double() | (i32)rhs.to_number().as_double());
|
||||
}
|
||||
|
||||
|
|
|
@ -48,14 +48,14 @@ try {
|
|||
assert(("42" | 6) === 46);
|
||||
assert((x | y) === 7);
|
||||
assert((x | [[[[12]]]]) === 15);
|
||||
// FIXME: These should all return 0
|
||||
// assert((undefined | y) === 7);
|
||||
// assert(("a" | "b") === 0);
|
||||
// assert((null | null) === 0);
|
||||
// assert((undefined | undefined) === 0);
|
||||
// assert((NaN | NaN) === 0);
|
||||
// assert((Infinity | Infinity) === 0);
|
||||
// assert((-Infinity | Infinity) === 0);
|
||||
assert((undefined | y) === 7);
|
||||
assert(("a" | "b") === 0);
|
||||
assert((null | null) === 0);
|
||||
assert((undefined | undefined) === 0);
|
||||
assert((NaN | NaN) === 0);
|
||||
assert((NaN | 6) === 6);
|
||||
assert((Infinity | Infinity) === 0);
|
||||
assert((-Infinity | Infinity) === 0);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue