mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:08:11 +00:00
LibJS: Support object rest elements in the bytecode interpreter
This commit is contained in:
parent
57b9a228ab
commit
25baefdd1e
4 changed files with 107 additions and 3 deletions
|
@ -6,6 +6,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/HashTable.h>
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
#include <LibJS/Bytecode/Op.h>
|
||||
|
@ -168,6 +169,36 @@ void NewObject::execute_impl(Bytecode::Interpreter& interpreter) const
|
|||
interpreter.accumulator() = Object::create(interpreter.global_object(), interpreter.global_object().object_prototype());
|
||||
}
|
||||
|
||||
void CopyObjectExcludingProperties::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto* from_object = interpreter.reg(m_from_object).to_object(interpreter.global_object());
|
||||
if (interpreter.vm().exception())
|
||||
return;
|
||||
|
||||
auto* to_object = Object::create(interpreter.global_object(), interpreter.global_object().object_prototype());
|
||||
|
||||
HashTable<Value, ValueTraits> excluded_names;
|
||||
for (size_t i = 0; i < m_excluded_names_count; ++i) {
|
||||
excluded_names.set(interpreter.reg(m_excluded_names[i]));
|
||||
if (interpreter.vm().exception())
|
||||
return;
|
||||
}
|
||||
|
||||
auto own_keys = from_object->get_own_properties(Object::PropertyKind::Key, true);
|
||||
|
||||
for (auto& key : own_keys) {
|
||||
if (!excluded_names.contains(key)) {
|
||||
auto property_name = PropertyName(key.to_property_key(interpreter.global_object()));
|
||||
auto property_value = from_object->get(property_name);
|
||||
if (interpreter.vm().exception())
|
||||
return;
|
||||
to_object->define_property(property_name, property_value);
|
||||
}
|
||||
}
|
||||
|
||||
interpreter.accumulator() = to_object;
|
||||
}
|
||||
|
||||
void ConcatString::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
interpreter.reg(m_lhs) = add(interpreter.global_object(), interpreter.reg(m_lhs), interpreter.accumulator());
|
||||
|
@ -467,6 +498,22 @@ String NewObject::to_string_impl(Bytecode::Executable const&) const
|
|||
return "NewObject";
|
||||
}
|
||||
|
||||
String CopyObjectExcludingProperties::to_string_impl(const Bytecode::Executable&) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.appendff("CopyObjectExcludingProperties from:{}", m_from_object);
|
||||
if (m_excluded_names_count != 0) {
|
||||
builder.append(" excluding:[");
|
||||
for (size_t i = 0; i < m_excluded_names_count; ++i) {
|
||||
builder.appendff("{}", m_excluded_names[i]);
|
||||
if (i != m_excluded_names_count - 1)
|
||||
builder.append(',');
|
||||
}
|
||||
builder.append(']');
|
||||
}
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
String ConcatString::to_string_impl(Bytecode::Executable const&) const
|
||||
{
|
||||
return String::formatted("ConcatString {}", m_lhs);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue