diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-23 13:45:19 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-23 19:38:13 +0200 |
commit | 502d1f5165d623818d04851b1bacf327709b9007 (patch) | |
tree | ae2e392ae49e2a6d20516a4a74e5180f82057772 /Libraries/LibJS/Runtime/Value.cpp | |
parent | f0e7404480d7712d004fcd9ff6908b6df812b54a (diff) | |
download | serenity-502d1f5165d623818d04851b1bacf327709b9007.zip |
LibJS: Implement bitwise right shift operator (>>)
Diffstat (limited to 'Libraries/LibJS/Runtime/Value.cpp')
-rw-r--r-- | Libraries/LibJS/Runtime/Value.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index e3729317c6..5da5c5765f 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -264,7 +264,13 @@ Value left_shift(Interpreter&, Value lhs, Value rhs) Value right_shift(Interpreter&, Value lhs, Value rhs) { - return Value((i32)lhs.to_number().as_double() >> (i32)rhs.to_number().as_double()); + auto lhs_number = lhs.to_number(); + if (!lhs_number.is_finite_number()) + return Value(0); + auto rhs_number = rhs.to_number(); + if (!rhs_number.is_finite_number()) + return lhs_number; + return Value((i32)lhs_number.as_double() >> (i32)rhs_number.as_double()); } Value add(Interpreter& interpreter, Value lhs, Value rhs) |