1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 10:45:09 +00:00

LibJS: Make all the JS::Value binary op helpers take GlobalObject&

We don't need the Interpreter& for anything here, the GlobalObject is
enough for getting to the VM and possibly throwing exceptions.
This commit is contained in:
Andreas Kling 2020-09-27 19:52:47 +02:00
parent 30ca9acd9c
commit 1df18c58f5
3 changed files with 175 additions and 175 deletions

View file

@ -471,15 +471,15 @@ Value BinaryExpression::execute(Interpreter& interpreter, GlobalObject& global_o
switch (m_op) { switch (m_op) {
case BinaryOp::Addition: case BinaryOp::Addition:
return add(interpreter, lhs_result, rhs_result); return add(global_object, lhs_result, rhs_result);
case BinaryOp::Subtraction: case BinaryOp::Subtraction:
return sub(interpreter, lhs_result, rhs_result); return sub(global_object, lhs_result, rhs_result);
case BinaryOp::Multiplication: case BinaryOp::Multiplication:
return mul(interpreter, lhs_result, rhs_result); return mul(global_object, lhs_result, rhs_result);
case BinaryOp::Division: case BinaryOp::Division:
return div(interpreter, lhs_result, rhs_result); return div(global_object, lhs_result, rhs_result);
case BinaryOp::Modulo: case BinaryOp::Modulo:
return mod(interpreter, lhs_result, rhs_result); return mod(global_object, lhs_result, rhs_result);
case BinaryOp::Exponentiation: case BinaryOp::Exponentiation:
return exp(global_object, lhs_result, rhs_result); return exp(global_object, lhs_result, rhs_result);
case BinaryOp::TypedEquals: case BinaryOp::TypedEquals:
@ -487,31 +487,31 @@ Value BinaryExpression::execute(Interpreter& interpreter, GlobalObject& global_o
case BinaryOp::TypedInequals: case BinaryOp::TypedInequals:
return Value(!strict_eq(lhs_result, rhs_result)); return Value(!strict_eq(lhs_result, rhs_result));
case BinaryOp::AbstractEquals: case BinaryOp::AbstractEquals:
return Value(abstract_eq(interpreter, lhs_result, rhs_result)); return Value(abstract_eq(global_object, lhs_result, rhs_result));
case BinaryOp::AbstractInequals: case BinaryOp::AbstractInequals:
return Value(!abstract_eq(interpreter, lhs_result, rhs_result)); return Value(!abstract_eq(global_object, lhs_result, rhs_result));
case BinaryOp::GreaterThan: case BinaryOp::GreaterThan:
return greater_than(interpreter, lhs_result, rhs_result); return greater_than(global_object, lhs_result, rhs_result);
case BinaryOp::GreaterThanEquals: case BinaryOp::GreaterThanEquals:
return greater_than_equals(interpreter, lhs_result, rhs_result); return greater_than_equals(global_object, lhs_result, rhs_result);
case BinaryOp::LessThan: case BinaryOp::LessThan:
return less_than(interpreter, lhs_result, rhs_result); return less_than(global_object, lhs_result, rhs_result);
case BinaryOp::LessThanEquals: case BinaryOp::LessThanEquals:
return less_than_equals(interpreter, lhs_result, rhs_result); return less_than_equals(global_object, lhs_result, rhs_result);
case BinaryOp::BitwiseAnd: case BinaryOp::BitwiseAnd:
return bitwise_and(interpreter, lhs_result, rhs_result); return bitwise_and(global_object, lhs_result, rhs_result);
case BinaryOp::BitwiseOr: case BinaryOp::BitwiseOr:
return bitwise_or(interpreter, lhs_result, rhs_result); return bitwise_or(global_object, lhs_result, rhs_result);
case BinaryOp::BitwiseXor: case BinaryOp::BitwiseXor:
return bitwise_xor(interpreter, lhs_result, rhs_result); return bitwise_xor(global_object, lhs_result, rhs_result);
case BinaryOp::LeftShift: case BinaryOp::LeftShift:
return left_shift(interpreter, lhs_result, rhs_result); return left_shift(global_object, lhs_result, rhs_result);
case BinaryOp::RightShift: case BinaryOp::RightShift:
return right_shift(interpreter, lhs_result, rhs_result); return right_shift(global_object, lhs_result, rhs_result);
case BinaryOp::UnsignedRightShift: case BinaryOp::UnsignedRightShift:
return unsigned_right_shift(interpreter, lhs_result, rhs_result); return unsigned_right_shift(global_object, lhs_result, rhs_result);
case BinaryOp::In: case BinaryOp::In:
return in(interpreter, lhs_result, rhs_result); return in(global_object, lhs_result, rhs_result);
case BinaryOp::InstanceOf: case BinaryOp::InstanceOf:
return instance_of(global_object, lhs_result, rhs_result); return instance_of(global_object, lhs_result, rhs_result);
} }
@ -616,13 +616,13 @@ Value UnaryExpression::execute(Interpreter& interpreter, GlobalObject& global_ob
switch (m_op) { switch (m_op) {
case UnaryOp::BitwiseNot: case UnaryOp::BitwiseNot:
return bitwise_not(interpreter, lhs_result); return bitwise_not(global_object, lhs_result);
case UnaryOp::Not: case UnaryOp::Not:
return Value(!lhs_result.to_boolean()); return Value(!lhs_result.to_boolean());
case UnaryOp::Plus: case UnaryOp::Plus:
return unary_plus(interpreter, lhs_result); return unary_plus(global_object, lhs_result);
case UnaryOp::Minus: case UnaryOp::Minus:
return unary_minus(interpreter, lhs_result); return unary_minus(global_object, lhs_result);
case UnaryOp::Typeof: case UnaryOp::Typeof:
switch (lhs_result.type()) { switch (lhs_result.type()) {
case Value::Type::Empty: case Value::Type::Empty:
@ -1205,31 +1205,31 @@ Value AssignmentExpression::execute(Interpreter& interpreter, GlobalObject& glob
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = add(interpreter, lhs_result, rhs_result); rhs_result = add(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::SubtractionAssignment: case AssignmentOp::SubtractionAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = sub(interpreter, lhs_result, rhs_result); rhs_result = sub(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::MultiplicationAssignment: case AssignmentOp::MultiplicationAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = mul(interpreter, lhs_result, rhs_result); rhs_result = mul(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::DivisionAssignment: case AssignmentOp::DivisionAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = div(interpreter, lhs_result, rhs_result); rhs_result = div(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::ModuloAssignment: case AssignmentOp::ModuloAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = mod(interpreter, lhs_result, rhs_result); rhs_result = mod(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::ExponentiationAssignment: case AssignmentOp::ExponentiationAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
@ -1241,37 +1241,37 @@ Value AssignmentExpression::execute(Interpreter& interpreter, GlobalObject& glob
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = bitwise_and(interpreter, lhs_result, rhs_result); rhs_result = bitwise_and(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::BitwiseOrAssignment: case AssignmentOp::BitwiseOrAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = bitwise_or(interpreter, lhs_result, rhs_result); rhs_result = bitwise_or(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::BitwiseXorAssignment: case AssignmentOp::BitwiseXorAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = bitwise_xor(interpreter, lhs_result, rhs_result); rhs_result = bitwise_xor(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::LeftShiftAssignment: case AssignmentOp::LeftShiftAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = left_shift(interpreter, lhs_result, rhs_result); rhs_result = left_shift(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::RightShiftAssignment: case AssignmentOp::RightShiftAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = right_shift(interpreter, lhs_result, rhs_result); rhs_result = right_shift(global_object, lhs_result, rhs_result);
break; break;
case AssignmentOp::UnsignedRightShiftAssignment: case AssignmentOp::UnsignedRightShiftAssignment:
lhs_result = m_lhs->execute(interpreter, global_object); lhs_result = m_lhs->execute(interpreter, global_object);
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
rhs_result = unsigned_right_shift(interpreter, lhs_result, rhs_result); rhs_result = unsigned_right_shift(global_object, lhs_result, rhs_result);
break; break;
} }
if (interpreter.exception()) if (interpreter.exception())

View file

@ -371,45 +371,45 @@ size_t Value::to_size_t(GlobalObject& global_object) const
return number.as_size_t(); return number.as_size_t();
} }
Value greater_than(Interpreter& interpreter, Value lhs, Value rhs) Value greater_than(GlobalObject& global_object, Value lhs, Value rhs)
{ {
TriState relation = abstract_relation(interpreter, false, lhs, rhs); TriState relation = abstract_relation(global_object, false, lhs, rhs);
if (relation == TriState::Unknown) if (relation == TriState::Unknown)
return Value(false); return Value(false);
return Value(relation == TriState::True); return Value(relation == TriState::True);
} }
Value greater_than_equals(Interpreter& interpreter, Value lhs, Value rhs) Value greater_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
{ {
TriState relation = abstract_relation(interpreter, true, lhs, rhs); TriState relation = abstract_relation(global_object, true, lhs, rhs);
if (relation == TriState::Unknown || relation == TriState::True) if (relation == TriState::Unknown || relation == TriState::True)
return Value(false); return Value(false);
return Value(true); return Value(true);
} }
Value less_than(Interpreter& interpreter, Value lhs, Value rhs) Value less_than(GlobalObject& global_object, Value lhs, Value rhs)
{ {
TriState relation = abstract_relation(interpreter, true, lhs, rhs); TriState relation = abstract_relation(global_object, true, lhs, rhs);
if (relation == TriState::Unknown) if (relation == TriState::Unknown)
return Value(false); return Value(false);
return Value(relation == TriState::True); return Value(relation == TriState::True);
} }
Value less_than_equals(Interpreter& interpreter, Value lhs, Value rhs) Value less_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
{ {
TriState relation = abstract_relation(interpreter, false, lhs, rhs); TriState relation = abstract_relation(global_object, false, lhs, rhs);
if (relation == TriState::Unknown || relation == TriState::True) if (relation == TriState::Unknown || relation == TriState::True)
return Value(false); return Value(false);
return Value(true); return Value(true);
} }
Value bitwise_and(Interpreter& interpreter, Value lhs, Value rhs) Value bitwise_and(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) { if (both_number(lhs_numeric, rhs_numeric)) {
if (!lhs_numeric.is_finite_number() || !rhs_numeric.is_finite_number()) if (!lhs_numeric.is_finite_number() || !rhs_numeric.is_finite_number())
@ -417,18 +417,18 @@ Value bitwise_and(Interpreter& interpreter, Value lhs, Value rhs)
return Value((i32)lhs_numeric.as_double() & (i32)rhs_numeric.as_double()); return Value((i32)lhs_numeric.as_double() & (i32)rhs_numeric.as_double());
} }
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
return js_bigint(interpreter, lhs_numeric.as_bigint().big_integer().bitwise_and(rhs_numeric.as_bigint().big_integer())); return js_bigint(global_object.heap(), lhs_numeric.as_bigint().big_integer().bitwise_and(rhs_numeric.as_bigint().big_integer()));
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "bitwise AND"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "bitwise AND");
return {}; return {};
} }
Value bitwise_or(Interpreter& interpreter, Value lhs, Value rhs) Value bitwise_or(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) { if (both_number(lhs_numeric, rhs_numeric)) {
if (!lhs_numeric.is_finite_number() && !rhs_numeric.is_finite_number()) if (!lhs_numeric.is_finite_number() && !rhs_numeric.is_finite_number())
@ -440,18 +440,18 @@ Value bitwise_or(Interpreter& interpreter, Value lhs, Value rhs)
return Value((i32)lhs_numeric.as_double() | (i32)rhs_numeric.as_double()); return Value((i32)lhs_numeric.as_double() | (i32)rhs_numeric.as_double());
} }
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
return js_bigint(interpreter, lhs_numeric.as_bigint().big_integer().bitwise_or(rhs_numeric.as_bigint().big_integer())); return js_bigint(global_object.heap(), lhs_numeric.as_bigint().big_integer().bitwise_or(rhs_numeric.as_bigint().big_integer()));
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "bitwise OR"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "bitwise OR");
return {}; return {};
} }
Value bitwise_xor(Interpreter& interpreter, Value lhs, Value rhs) Value bitwise_xor(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) { if (both_number(lhs_numeric, rhs_numeric)) {
if (!lhs_numeric.is_finite_number() && !rhs_numeric.is_finite_number()) if (!lhs_numeric.is_finite_number() && !rhs_numeric.is_finite_number())
@ -463,33 +463,33 @@ Value bitwise_xor(Interpreter& interpreter, Value lhs, Value rhs)
return Value((i32)lhs_numeric.as_double() ^ (i32)rhs_numeric.as_double()); return Value((i32)lhs_numeric.as_double() ^ (i32)rhs_numeric.as_double());
} }
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
return js_bigint(interpreter, lhs_numeric.as_bigint().big_integer().bitwise_xor(rhs_numeric.as_bigint().big_integer())); return js_bigint(global_object.heap(), lhs_numeric.as_bigint().big_integer().bitwise_xor(rhs_numeric.as_bigint().big_integer()));
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "bitwise XOR"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "bitwise XOR");
return {}; return {};
} }
Value bitwise_not(Interpreter& interpreter, Value lhs) Value bitwise_not(GlobalObject& global_object, Value lhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (lhs_numeric.is_number()) if (lhs_numeric.is_number())
return Value(~(i32)lhs_numeric.as_double()); return Value(~(i32)lhs_numeric.as_double());
auto big_integer_bitwise_not = lhs_numeric.as_bigint().big_integer(); auto big_integer_bitwise_not = lhs_numeric.as_bigint().big_integer();
big_integer_bitwise_not = big_integer_bitwise_not.plus(Crypto::SignedBigInteger { 1 }); big_integer_bitwise_not = big_integer_bitwise_not.plus(Crypto::SignedBigInteger { 1 });
big_integer_bitwise_not.negate(); big_integer_bitwise_not.negate();
return js_bigint(interpreter, big_integer_bitwise_not); return js_bigint(global_object.heap(), big_integer_bitwise_not);
} }
Value unary_plus(Interpreter& interpreter, Value lhs) Value unary_plus(GlobalObject& global_object, Value lhs)
{ {
return lhs.to_number(interpreter.global_object()); return lhs.to_number(global_object.global_object());
} }
Value unary_minus(Interpreter& interpreter, Value lhs) Value unary_minus(GlobalObject& global_object, Value lhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (lhs_numeric.is_number()) { if (lhs_numeric.is_number()) {
if (lhs_numeric.is_nan()) if (lhs_numeric.is_nan())
@ -497,19 +497,19 @@ Value unary_minus(Interpreter& interpreter, Value lhs)
return Value(-lhs_numeric.as_double()); return Value(-lhs_numeric.as_double());
} }
if (lhs_numeric.as_bigint().big_integer() == BIGINT_ZERO) if (lhs_numeric.as_bigint().big_integer() == BIGINT_ZERO)
return js_bigint(interpreter, BIGINT_ZERO); return js_bigint(global_object.heap(), BIGINT_ZERO);
auto big_integer_negated = lhs_numeric.as_bigint().big_integer(); auto big_integer_negated = lhs_numeric.as_bigint().big_integer();
big_integer_negated.negate(); big_integer_negated.negate();
return js_bigint(interpreter, big_integer_negated); return js_bigint(global_object.heap(), big_integer_negated);
} }
Value left_shift(Interpreter& interpreter, Value lhs, Value rhs) Value left_shift(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) { if (both_number(lhs_numeric, rhs_numeric)) {
if (!lhs_numeric.is_finite_number()) if (!lhs_numeric.is_finite_number())
@ -520,17 +520,17 @@ Value left_shift(Interpreter& interpreter, Value lhs, Value rhs)
} }
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
TODO(); TODO();
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "left-shift"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "left-shift");
return {}; return {};
} }
Value right_shift(Interpreter& interpreter, Value lhs, Value rhs) Value right_shift(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) { if (both_number(lhs_numeric, rhs_numeric)) {
if (!lhs_numeric.is_finite_number()) if (!lhs_numeric.is_finite_number())
@ -541,17 +541,17 @@ Value right_shift(Interpreter& interpreter, Value lhs, Value rhs)
} }
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
TODO(); TODO();
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "right-shift"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "right-shift");
return {}; return {};
} }
Value unsigned_right_shift(Interpreter& interpreter, Value lhs, Value rhs) Value unsigned_right_shift(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) { if (both_number(lhs_numeric, rhs_numeric)) {
if (!lhs_numeric.is_finite_number()) if (!lhs_numeric.is_finite_number())
@ -560,101 +560,101 @@ Value unsigned_right_shift(Interpreter& interpreter, Value lhs, Value rhs)
return lhs_numeric; return lhs_numeric;
return Value((unsigned)lhs_numeric.as_double() >> (i32)rhs_numeric.as_double()); return Value((unsigned)lhs_numeric.as_double() >> (i32)rhs_numeric.as_double());
} }
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperator, "unsigned right-shift"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperator, "unsigned right-shift");
return {}; return {};
} }
Value add(Interpreter& interpreter, Value lhs, Value rhs) Value add(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_primitive = lhs.to_primitive(); auto lhs_primitive = lhs.to_primitive();
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_primitive = rhs.to_primitive(); auto rhs_primitive = rhs.to_primitive();
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (lhs_primitive.is_string() || rhs_primitive.is_string()) { if (lhs_primitive.is_string() || rhs_primitive.is_string()) {
auto lhs_string = lhs_primitive.to_string(interpreter.global_object()); auto lhs_string = lhs_primitive.to_string(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_string = rhs_primitive.to_string(interpreter.global_object()); auto rhs_string = rhs_primitive.to_string(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
StringBuilder builder(lhs_string.length() + rhs_string.length()); StringBuilder builder(lhs_string.length() + rhs_string.length());
builder.append(lhs_string); builder.append(lhs_string);
builder.append(rhs_string); builder.append(rhs_string);
return js_string(interpreter, builder.to_string()); return js_string(global_object.heap(), builder.to_string());
} }
auto lhs_numeric = lhs_primitive.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs_primitive.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs_primitive.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs_primitive.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) if (both_number(lhs_numeric, rhs_numeric))
return Value(lhs_numeric.as_double() + rhs_numeric.as_double()); return Value(lhs_numeric.as_double() + rhs_numeric.as_double());
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
return js_bigint(interpreter, lhs_numeric.as_bigint().big_integer().plus(rhs_numeric.as_bigint().big_integer())); return js_bigint(global_object.heap(), lhs_numeric.as_bigint().big_integer().plus(rhs_numeric.as_bigint().big_integer()));
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "addition"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "addition");
return {}; return {};
} }
Value sub(Interpreter& interpreter, Value lhs, Value rhs) Value sub(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) if (both_number(lhs_numeric, rhs_numeric))
return Value(lhs_numeric.as_double() - rhs_numeric.as_double()); return Value(lhs_numeric.as_double() - rhs_numeric.as_double());
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
return js_bigint(interpreter, lhs_numeric.as_bigint().big_integer().minus(rhs_numeric.as_bigint().big_integer())); return js_bigint(global_object.heap(), lhs_numeric.as_bigint().big_integer().minus(rhs_numeric.as_bigint().big_integer()));
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "subtraction"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "subtraction");
return {}; return {};
} }
Value mul(Interpreter& interpreter, Value lhs, Value rhs) Value mul(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) if (both_number(lhs_numeric, rhs_numeric))
return Value(lhs_numeric.as_double() * rhs_numeric.as_double()); return Value(lhs_numeric.as_double() * rhs_numeric.as_double());
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
return js_bigint(interpreter, lhs_numeric.as_bigint().big_integer().multiplied_by(rhs_numeric.as_bigint().big_integer())); return js_bigint(global_object.heap(), lhs_numeric.as_bigint().big_integer().multiplied_by(rhs_numeric.as_bigint().big_integer()));
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "multiplication"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "multiplication");
return {}; return {};
} }
Value div(Interpreter& interpreter, Value lhs, Value rhs) Value div(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) if (both_number(lhs_numeric, rhs_numeric))
return Value(lhs_numeric.as_double() / rhs_numeric.as_double()); return Value(lhs_numeric.as_double() / rhs_numeric.as_double());
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
return js_bigint(interpreter, lhs_numeric.as_bigint().big_integer().divided_by(rhs_numeric.as_bigint().big_integer()).quotient); return js_bigint(global_object.heap(), lhs_numeric.as_bigint().big_integer().divided_by(rhs_numeric.as_bigint().big_integer()).quotient);
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "division"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "division");
return {}; return {};
} }
Value mod(Interpreter& interpreter, Value lhs, Value rhs) Value mod(GlobalObject& global_object, Value lhs, Value rhs)
{ {
auto lhs_numeric = lhs.to_numeric(interpreter.global_object()); auto lhs_numeric = lhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto rhs_numeric = rhs.to_numeric(interpreter.global_object()); auto rhs_numeric = rhs.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (both_number(lhs_numeric, rhs_numeric)) { if (both_number(lhs_numeric, rhs_numeric)) {
if (lhs_numeric.is_nan() || rhs_numeric.is_nan()) if (lhs_numeric.is_nan() || rhs_numeric.is_nan())
@ -665,8 +665,8 @@ Value mod(Interpreter& interpreter, Value lhs, Value rhs)
return Value(index - trunc * period); return Value(index - trunc * period);
} }
if (both_bigint(lhs_numeric, rhs_numeric)) if (both_bigint(lhs_numeric, rhs_numeric))
return js_bigint(interpreter, lhs_numeric.as_bigint().big_integer().divided_by(rhs_numeric.as_bigint().big_integer()).remainder); return js_bigint(global_object.heap(), lhs_numeric.as_bigint().big_integer().divided_by(rhs_numeric.as_bigint().big_integer()).remainder);
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::BigIntBadOperatorOtherType, "modulo"); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::BigIntBadOperatorOtherType, "modulo");
return {}; return {};
} }
@ -687,14 +687,14 @@ Value exp(GlobalObject& global_object, Value lhs, Value rhs)
return {}; return {};
} }
Value in(Interpreter& interpreter, Value lhs, Value rhs) Value in(GlobalObject& global_object, Value lhs, Value rhs)
{ {
if (!rhs.is_object()) { if (!rhs.is_object()) {
interpreter.vm().throw_exception<TypeError>(interpreter.global_object(), ErrorType::InOperatorWithObject); global_object.vm().throw_exception<TypeError>(global_object.global_object(), ErrorType::InOperatorWithObject);
return {}; return {};
} }
auto lhs_string = lhs.to_string(interpreter.global_object()); auto lhs_string = lhs.to_string(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
return Value(rhs.as_object().has_property(lhs_string)); return Value(rhs.as_object().has_property(lhs_string));
} }
@ -847,7 +847,7 @@ bool strict_eq(Value lhs, Value rhs)
return same_value_non_numeric(lhs, rhs); return same_value_non_numeric(lhs, rhs);
} }
bool abstract_eq(Interpreter& interpreter, Value lhs, Value rhs) bool abstract_eq(GlobalObject& global_object, Value lhs, Value rhs)
{ {
if (lhs.type() == rhs.type()) if (lhs.type() == rhs.type())
return strict_eq(lhs, rhs); return strict_eq(lhs, rhs);
@ -856,32 +856,32 @@ bool abstract_eq(Interpreter& interpreter, Value lhs, Value rhs)
return true; return true;
if (lhs.is_number() && rhs.is_string()) if (lhs.is_number() && rhs.is_string())
return abstract_eq(interpreter, lhs, rhs.to_number(interpreter.global_object())); return abstract_eq(global_object, lhs, rhs.to_number(global_object.global_object()));
if (lhs.is_string() && rhs.is_number()) if (lhs.is_string() && rhs.is_number())
return abstract_eq(interpreter, lhs.to_number(interpreter.global_object()), rhs); return abstract_eq(global_object, lhs.to_number(global_object.global_object()), rhs);
if (lhs.is_bigint() && rhs.is_string()) { if (lhs.is_bigint() && rhs.is_string()) {
auto& rhs_string = rhs.as_string().string(); auto& rhs_string = rhs.as_string().string();
if (!is_valid_bigint_value(rhs_string)) if (!is_valid_bigint_value(rhs_string))
return false; return false;
return abstract_eq(interpreter, lhs, js_bigint(interpreter, Crypto::SignedBigInteger::from_base10(rhs_string))); return abstract_eq(global_object, lhs, js_bigint(global_object.heap(), Crypto::SignedBigInteger::from_base10(rhs_string)));
} }
if (lhs.is_string() && rhs.is_bigint()) if (lhs.is_string() && rhs.is_bigint())
return abstract_eq(interpreter, rhs, lhs); return abstract_eq(global_object, rhs, lhs);
if (lhs.is_boolean()) if (lhs.is_boolean())
return abstract_eq(interpreter, lhs.to_number(interpreter.global_object()), rhs); return abstract_eq(global_object, lhs.to_number(global_object.global_object()), rhs);
if (rhs.is_boolean()) if (rhs.is_boolean())
return abstract_eq(interpreter, lhs, rhs.to_number(interpreter.global_object())); return abstract_eq(global_object, lhs, rhs.to_number(global_object.global_object()));
if ((lhs.is_string() || lhs.is_number() || lhs.is_bigint() || lhs.is_symbol()) && rhs.is_object()) if ((lhs.is_string() || lhs.is_number() || lhs.is_bigint() || lhs.is_symbol()) && rhs.is_object())
return abstract_eq(interpreter, lhs, rhs.to_primitive()); return abstract_eq(global_object, lhs, rhs.to_primitive());
if (lhs.is_object() && (rhs.is_string() || rhs.is_number() || lhs.is_bigint() || rhs.is_symbol())) if (lhs.is_object() && (rhs.is_string() || rhs.is_number() || lhs.is_bigint() || rhs.is_symbol()))
return abstract_eq(interpreter, lhs.to_primitive(), rhs); return abstract_eq(global_object, lhs.to_primitive(), rhs);
if ((lhs.is_bigint() && rhs.is_number()) || (lhs.is_number() && rhs.is_bigint())) { if ((lhs.is_bigint() && rhs.is_number()) || (lhs.is_number() && rhs.is_bigint())) {
if (lhs.is_nan() || lhs.is_infinity() || rhs.is_nan() || rhs.is_infinity()) if (lhs.is_nan() || lhs.is_infinity() || rhs.is_nan() || rhs.is_infinity())
@ -897,24 +897,24 @@ bool abstract_eq(Interpreter& interpreter, Value lhs, Value rhs)
return false; return false;
} }
TriState abstract_relation(Interpreter& interpreter, bool left_first, Value lhs, Value rhs) TriState abstract_relation(GlobalObject& global_object, bool left_first, Value lhs, Value rhs)
{ {
Value x_primitive; Value x_primitive;
Value y_primitive; Value y_primitive;
if (left_first) { if (left_first) {
x_primitive = lhs.to_primitive(Value::PreferredType::Number); x_primitive = lhs.to_primitive(Value::PreferredType::Number);
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
y_primitive = rhs.to_primitive(Value::PreferredType::Number); y_primitive = rhs.to_primitive(Value::PreferredType::Number);
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
} else { } else {
y_primitive = lhs.to_primitive(Value::PreferredType::Number); y_primitive = lhs.to_primitive(Value::PreferredType::Number);
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
x_primitive = rhs.to_primitive(Value::PreferredType::Number); x_primitive = rhs.to_primitive(Value::PreferredType::Number);
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
} }
@ -963,11 +963,11 @@ TriState abstract_relation(Interpreter& interpreter, bool left_first, Value lhs,
return TriState::False; return TriState::False;
} }
auto x_numeric = x_primitive.to_numeric(interpreter.global_object()); auto x_numeric = x_primitive.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
auto y_numeric = y_primitive.to_numeric(interpreter.global_object()); auto y_numeric = y_primitive.to_numeric(global_object.global_object());
if (interpreter.exception()) if (global_object.vm().exception())
return {}; return {};
if (x_numeric.is_nan() || y_numeric.is_nan()) if (x_numeric.is_nan() || y_numeric.is_nan())

View file

@ -302,35 +302,35 @@ inline Value js_negative_infinity()
return Value(-INFINITY); return Value(-INFINITY);
} }
Value greater_than(Interpreter&, Value lhs, Value rhs); Value greater_than(GlobalObject&, Value lhs, Value rhs);
Value greater_than_equals(Interpreter&, Value lhs, Value rhs); Value greater_than_equals(GlobalObject&, Value lhs, Value rhs);
Value less_than(Interpreter&, Value lhs, Value rhs); Value less_than(GlobalObject&, Value lhs, Value rhs);
Value less_than_equals(Interpreter&, Value lhs, Value rhs); Value less_than_equals(GlobalObject&, Value lhs, Value rhs);
Value bitwise_and(Interpreter&, Value lhs, Value rhs); Value bitwise_and(GlobalObject&, Value lhs, Value rhs);
Value bitwise_or(Interpreter&, Value lhs, Value rhs); Value bitwise_or(GlobalObject&, Value lhs, Value rhs);
Value bitwise_xor(Interpreter&, Value lhs, Value rhs); Value bitwise_xor(GlobalObject&, Value lhs, Value rhs);
Value bitwise_not(Interpreter&, Value); Value bitwise_not(GlobalObject&, Value);
Value unary_plus(Interpreter&, Value); Value unary_plus(GlobalObject&, Value);
Value unary_minus(Interpreter&, Value); Value unary_minus(GlobalObject&, Value);
Value left_shift(Interpreter&, Value lhs, Value rhs); Value left_shift(GlobalObject&, Value lhs, Value rhs);
Value right_shift(Interpreter&, Value lhs, Value rhs); Value right_shift(GlobalObject&, Value lhs, Value rhs);
Value unsigned_right_shift(Interpreter&, Value lhs, Value rhs); Value unsigned_right_shift(GlobalObject&, Value lhs, Value rhs);
Value add(Interpreter&, Value lhs, Value rhs); Value add(GlobalObject&, Value lhs, Value rhs);
Value sub(Interpreter&, Value lhs, Value rhs); Value sub(GlobalObject&, Value lhs, Value rhs);
Value mul(Interpreter&, Value lhs, Value rhs); Value mul(GlobalObject&, Value lhs, Value rhs);
Value div(Interpreter&, Value lhs, Value rhs); Value div(GlobalObject&, Value lhs, Value rhs);
Value mod(Interpreter&, Value lhs, Value rhs); Value mod(GlobalObject&, Value lhs, Value rhs);
Value exp(GlobalObject&, Value lhs, Value rhs); Value exp(GlobalObject&, Value lhs, Value rhs);
Value in(Interpreter&, Value lhs, Value rhs); Value in(GlobalObject&, Value lhs, Value rhs);
Value instance_of(GlobalObject&, Value lhs, Value rhs); Value instance_of(GlobalObject&, Value lhs, Value rhs);
Value ordinary_has_instance(GlobalObject&, Value lhs, Value rhs); Value ordinary_has_instance(GlobalObject&, Value lhs, Value rhs);
bool abstract_eq(Interpreter&, Value lhs, Value rhs); bool abstract_eq(GlobalObject&, Value lhs, Value rhs);
bool strict_eq(Value lhs, Value rhs); bool strict_eq(Value lhs, Value rhs);
bool same_value(Value lhs, Value rhs); bool same_value(Value lhs, Value rhs);
bool same_value_zero(Value lhs, Value rhs); bool same_value_zero(Value lhs, Value rhs);
bool same_value_non_numeric(Value lhs, Value rhs); bool same_value_non_numeric(Value lhs, Value rhs);
TriState abstract_relation(Interpreter&, bool left_first, Value lhs, Value rhs); TriState abstract_relation(GlobalObject&, bool left_first, Value lhs, Value rhs);
size_t length_of_array_like(GlobalObject&, Value); size_t length_of_array_like(GlobalObject&, Value);
const LogStream& operator<<(const LogStream&, const Value&); const LogStream& operator<<(const LogStream&, const Value&);