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

LibJS: Parse ArrayExpression and start implementing Array objects

Note that property lookup is not functional yet.
This commit is contained in:
Andreas Kling 2020-03-20 20:29:57 +01:00
parent 0891f860f7
commit a82f64d3d6
9 changed files with 176 additions and 0 deletions

View file

@ -29,6 +29,7 @@
#include <AK/StringBuilder.h>
#include <LibJS/AST.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/ScriptFunction.h>
#include <LibJS/Runtime/Value.h>
@ -682,4 +683,21 @@ Value NullLiteral::execute(Interpreter&) const
return js_null();
}
void ArrayExpression::dump(int indent) const
{
ASTNode::dump(indent);
for (auto& element : m_elements) {
element.dump(indent + 1);
}
}
Value ArrayExpression::execute(Interpreter& interpreter) const
{
auto* array = interpreter.heap().allocate<Array>();
for (auto& element : m_elements) {
array->append(element.execute(interpreter));
}
return array;
}
}