1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +00:00

LibJS: Implement the "instanceof" operator

This operator walks the prototype chain of the RHS value and looks for
a "prototype" property with the same value as the prototype of the LHS.

This is pretty cool. :^)
This commit is contained in:
Andreas Kling 2020-03-28 16:56:54 +01:00
parent 37fe16a99c
commit a3d92b1210
6 changed files with 41 additions and 1 deletions

View file

@ -241,6 +241,8 @@ Value BinaryExpression::execute(Interpreter& interpreter) const
return left_shift(lhs_result, rhs_result);
case BinaryOp::RightShift:
return right_shift(lhs_result, rhs_result);
case BinaryOp::InstanceOf:
return instance_of(lhs_result, rhs_result);
}
ASSERT_NOT_REACHED();
@ -368,6 +370,9 @@ void BinaryExpression::dump(int indent) const
case BinaryOp::RightShift:
op_string = ">>";
break;
case BinaryOp::InstanceOf:
op_string = "instanceof";
break;
}
print_indent(indent);