mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibJS/Bytecode: Support private class fields
This is accomplished with two new instructions: - GetPrivateById - PutPrivateById Looks like 1616 new passes on test262. :^)
This commit is contained in:
parent
467ea86179
commit
e5c7d8407b
5 changed files with 93 additions and 0 deletions
|
@ -512,6 +512,16 @@ ThrowCompletionOr<void> GetById::execute_impl(Bytecode::Interpreter& interpreter
|
|||
return {};
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> GetPrivateById::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
auto const& name = interpreter.current_executable().get_identifier(m_property);
|
||||
auto base_value = interpreter.accumulator();
|
||||
auto private_reference = make_private_reference(vm, base_value, name);
|
||||
interpreter.accumulator() = TRY(private_reference.get_value(vm));
|
||||
return {};
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> PutById::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
@ -522,6 +532,17 @@ ThrowCompletionOr<void> PutById::execute_impl(Bytecode::Interpreter& interpreter
|
|||
return put_by_property_key(vm, object, value, name, m_kind);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> PutPrivateById::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
// NOTE: Get the value from the accumulator before side effects have a chance to overwrite it.
|
||||
auto value = interpreter.accumulator();
|
||||
auto object = TRY(interpreter.reg(m_base).to_object(vm));
|
||||
auto name = interpreter.current_executable().get_identifier(m_property);
|
||||
auto private_reference = make_private_reference(vm, object, name);
|
||||
return private_reference.put_value(vm, value);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> DeleteById::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
@ -1252,11 +1273,27 @@ DeprecatedString PutById::to_deprecated_string_impl(Bytecode::Executable const&
|
|||
return DeprecatedString::formatted("PutById kind:{} base:{}, property:{} ({})", kind, m_base, m_property, executable.identifier_table->get(m_property));
|
||||
}
|
||||
|
||||
DeprecatedString PutPrivateById::to_deprecated_string_impl(Bytecode::Executable const& executable) const
|
||||
{
|
||||
auto kind = m_kind == PropertyKind::Getter
|
||||
? "getter"
|
||||
: m_kind == PropertyKind::Setter
|
||||
? "setter"
|
||||
: "property";
|
||||
|
||||
return DeprecatedString::formatted("PutPrivateById kind:{} base:{}, property:{} ({})", kind, m_base, m_property, executable.identifier_table->get(m_property));
|
||||
}
|
||||
|
||||
DeprecatedString GetById::to_deprecated_string_impl(Bytecode::Executable const& executable) const
|
||||
{
|
||||
return DeprecatedString::formatted("GetById {} ({})", m_property, executable.identifier_table->get(m_property));
|
||||
}
|
||||
|
||||
DeprecatedString GetPrivateById::to_deprecated_string_impl(Bytecode::Executable const& executable) const
|
||||
{
|
||||
return DeprecatedString::formatted("GetPrivateById {} ({})", m_property, executable.identifier_table->get(m_property));
|
||||
}
|
||||
|
||||
DeprecatedString DeleteById::to_deprecated_string_impl(Bytecode::Executable const& executable) const
|
||||
{
|
||||
return DeprecatedString::formatted("DeleteById {} ({})", m_property, executable.identifier_table->get(m_property));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue