mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:58:12 +00:00
LibJS: Implement basic support for the "delete" operator
It turns out "delete" is actually a unary op :) This patch implements deletion of object properties, it doesn't yet work for casually deleting properties from the global object. When deleting a property from an object, we switch that object to having a unique shape, no longer sharing shapes with others. Once an object has a unique shape, it no longer needs to care about shape transitions.
This commit is contained in:
parent
1617be1e6f
commit
f897c41092
9 changed files with 190 additions and 8 deletions
|
@ -378,6 +378,21 @@ Value LogicalExpression::execute(Interpreter& interpreter) const
|
|||
|
||||
Value UnaryExpression::execute(Interpreter& interpreter) const
|
||||
{
|
||||
if (m_op == UnaryOp::Delete) {
|
||||
if (!m_lhs->is_member_expression())
|
||||
return Value(true);
|
||||
auto object_value = static_cast<const MemberExpression&>(*m_lhs).object().execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
auto* object = object_value.to_object(interpreter.heap());
|
||||
if (!object)
|
||||
return {};
|
||||
auto property_name = static_cast<const MemberExpression&>(*m_lhs).computed_property_name(interpreter);
|
||||
if (!property_name.is_valid())
|
||||
return {};
|
||||
return object->delete_property(property_name);
|
||||
}
|
||||
|
||||
auto lhs_result = m_lhs->execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
@ -416,6 +431,8 @@ Value UnaryExpression::execute(Interpreter& interpreter) const
|
|||
}
|
||||
case UnaryOp::Void:
|
||||
return js_undefined();
|
||||
case UnaryOp::Delete:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
ASSERT_NOT_REACHED();
|
||||
|
@ -575,6 +592,9 @@ void UnaryExpression::dump(int indent) const
|
|||
case UnaryOp::Void:
|
||||
op_string = "void ";
|
||||
break;
|
||||
case UnaryOp::Delete:
|
||||
op_string = "delete ";
|
||||
break;
|
||||
}
|
||||
|
||||
print_indent(indent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue