mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 00:57:43 +00:00
LibJS: Basic bytecode support for computed member expressions
Expressions like foo[1 + 2] now work, and you can assign to them as well! :^)
This commit is contained in:
parent
b47246ec70
commit
9ee5029bc5
4 changed files with 75 additions and 3 deletions
|
@ -291,6 +291,26 @@ void Yield::execute(Bytecode::Interpreter& interpreter) const
|
|||
interpreter.do_return(object);
|
||||
}
|
||||
|
||||
void GetByValue::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
if (auto* object = interpreter.reg(m_base).to_object(interpreter.global_object())) {
|
||||
auto property_key = interpreter.accumulator().to_property_key(interpreter.global_object());
|
||||
if (interpreter.vm().exception())
|
||||
return;
|
||||
interpreter.accumulator() = object->get(property_key);
|
||||
}
|
||||
}
|
||||
|
||||
void PutByValue::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
if (auto* object = interpreter.reg(m_base).to_object(interpreter.global_object())) {
|
||||
auto property_key = interpreter.reg(m_property).to_property_key(interpreter.global_object());
|
||||
if (interpreter.vm().exception())
|
||||
return;
|
||||
object->put(property_key, interpreter.accumulator());
|
||||
}
|
||||
}
|
||||
|
||||
String Load::to_string(Bytecode::Executable const&) const
|
||||
{
|
||||
return String::formatted("Load {}", m_src);
|
||||
|
@ -463,4 +483,14 @@ String Yield::to_string(Bytecode::Executable const&) const
|
|||
return String::formatted("Yield return");
|
||||
}
|
||||
|
||||
String GetByValue::to_string(const Bytecode::Executable&) const
|
||||
{
|
||||
return String::formatted("GetByValue base:{}", m_base);
|
||||
}
|
||||
|
||||
String PutByValue::to_string(const Bytecode::Executable&) const
|
||||
{
|
||||
return String::formatted("PutByValue base:{}, property:{}", m_base, m_property);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue