diff options
author | Linus Groh <mail@linusgroh.de> | 2022-12-10 00:05:02 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-10 11:23:23 +0000 |
commit | 9d3d4a760f85f9b71cdd47864a019c02c2f3621d (patch) | |
tree | 9411780b9efab6db165be78ebf4ed1e2e05a93ea | |
parent | 3a8c704d19de25c1e3021ee327f078df540e638b (diff) | |
download | serenity-9d3d4a760f85f9b71cdd47864a019c02c2f3621d.zip |
LibJS: Add spec comments to bitwise_and()
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Value.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 37b6a045f5..b1b3b2b15f 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -1305,17 +1305,35 @@ ThrowCompletionOr<Value> less_than_equals(VM& vm, Value lhs, Value rhs) } // 13.12 Binary Bitwise Operators, https://tc39.es/ecma262/#sec-binary-bitwise-operators +// BitwiseANDExpression : BitwiseANDExpression & EqualityExpression ThrowCompletionOr<Value> bitwise_and(VM& vm, Value lhs, Value rhs) { + // 13.15.3 ApplyStringOrNumericBinaryOperator ( lval, opText, rval ), https://tc39.es/ecma262/#sec-applystringornumericbinaryoperator + // 1-2, 6. N/A. + + // 3. Let lnum be ? ToNumeric(lval). auto lhs_numeric = TRY(lhs.to_numeric(vm)); + + // 4. Let rnum be ? ToNumeric(rval). auto rhs_numeric = TRY(rhs.to_numeric(vm)); + + // 7. Let operation be the abstract operation associated with opText and Type(lnum) in the following table: + // [...] + // 8. Return operation(lnum, rnum). if (both_number(lhs_numeric, rhs_numeric)) { + // 6.1.6.1.17 Number::bitwiseAND ( x, y ), https://tc39.es/ecma262/#sec-numeric-types-number-bitwiseAND + // 1. Return NumberBitwiseOp(&, x, y). if (!lhs_numeric.is_finite_number() || !rhs_numeric.is_finite_number()) return Value(0); return Value(TRY(lhs_numeric.to_i32(vm)) & TRY(rhs_numeric.to_i32(vm))); } - if (both_bigint(lhs_numeric, rhs_numeric)) + if (both_bigint(lhs_numeric, rhs_numeric)) { + // 6.1.6.2.18 BigInt::bitwiseAND ( x, y ), https://tc39.es/ecma262/#sec-numeric-types-bigint-bitwiseAND + // 1. Return BigIntBitwiseOp(&, x, y). return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().bitwise_and(rhs_numeric.as_bigint().big_integer())); + } + + // 5. If Type(lnum) is different from Type(rnum), throw a TypeError exception. return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "bitwise AND"); } |