2021-06-03 11:46:30 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
2021-06-07 23:13:37 +03:00
|
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
2021-06-09 19:18:56 +03:00
|
|
|
* Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org>
|
2021-06-03 11:46:30 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2021-06-05 16:14:09 +03:00
|
|
|
#include <LibJS/AST.h>
|
2021-06-03 11:46:30 +03:00
|
|
|
#include <LibJS/Bytecode/Interpreter.h>
|
|
|
|
#include <LibJS/Bytecode/Op.h>
|
2021-06-09 00:06:52 +03:00
|
|
|
#include <LibJS/Runtime/Array.h>
|
2021-06-08 08:59:25 +03:00
|
|
|
#include <LibJS/Runtime/BigInt.h>
|
2021-06-03 19:26:32 +03:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2021-06-10 23:12:21 +03:00
|
|
|
#include <LibJS/Runtime/LexicalEnvironment.h>
|
|
|
|
#include <LibJS/Runtime/ScopeObject.h>
|
2021-06-05 16:14:09 +03:00
|
|
|
#include <LibJS/Runtime/ScriptFunction.h>
|
2021-06-03 11:46:30 +03:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
|
2021-06-07 16:12:43 +03:00
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
2021-06-09 11:02:01 +03:00
|
|
|
String Instruction::to_string(Bytecode::Executable const& executable) const
|
2021-06-07 16:12:43 +03:00
|
|
|
{
|
|
|
|
#define __BYTECODE_OP(op) \
|
|
|
|
case Instruction::Type::op: \
|
2021-06-15 16:38:12 +03:00
|
|
|
return static_cast<Bytecode::Op::op const&>(*this).to_string_impl(executable);
|
2021-06-07 16:12:43 +03:00
|
|
|
|
|
|
|
switch (type()) {
|
|
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef __BYTECODE_OP
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-03 11:46:30 +03:00
|
|
|
namespace JS::Bytecode::Op {
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Load::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-03 11:46:30 +03:00
|
|
|
{
|
2021-06-08 06:58:36 +03:00
|
|
|
interpreter.accumulator() = interpreter.reg(m_src);
|
2021-06-03 11:46:30 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void LoadImmediate::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-07 23:05:09 +03:00
|
|
|
{
|
2021-06-08 06:58:36 +03:00
|
|
|
interpreter.accumulator() = m_value;
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Store::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-08 06:58:36 +03:00
|
|
|
{
|
|
|
|
interpreter.reg(m_dst) = interpreter.accumulator();
|
2021-06-07 23:05:09 +03:00
|
|
|
}
|
|
|
|
|
2021-06-08 00:08:35 +03:00
|
|
|
static Value abstract_inequals(GlobalObject& global_object, Value src1, Value src2)
|
2021-06-03 11:46:30 +03:00
|
|
|
{
|
2021-06-08 00:08:35 +03:00
|
|
|
return Value(!abstract_eq(global_object, src1, src2));
|
2021-06-03 11:46:30 +03:00
|
|
|
}
|
|
|
|
|
2021-06-08 00:08:35 +03:00
|
|
|
static Value abstract_equals(GlobalObject& global_object, Value src1, Value src2)
|
2021-06-03 19:32:33 +03:00
|
|
|
{
|
2021-06-08 00:08:35 +03:00
|
|
|
return Value(abstract_eq(global_object, src1, src2));
|
2021-06-03 19:32:33 +03:00
|
|
|
}
|
|
|
|
|
2021-06-08 00:08:35 +03:00
|
|
|
static Value typed_inequals(GlobalObject&, Value src1, Value src2)
|
2021-06-07 20:17:20 +03:00
|
|
|
{
|
2021-06-08 00:08:35 +03:00
|
|
|
return Value(!strict_eq(src1, src2));
|
2021-06-07 20:17:20 +03:00
|
|
|
}
|
|
|
|
|
2021-06-08 00:08:35 +03:00
|
|
|
static Value typed_equals(GlobalObject&, Value src1, Value src2)
|
2021-06-07 20:17:20 +03:00
|
|
|
{
|
2021-06-08 00:08:35 +03:00
|
|
|
return Value(strict_eq(src1, src2));
|
2021-06-07 20:17:20 +03:00
|
|
|
}
|
|
|
|
|
2021-06-08 06:58:36 +03:00
|
|
|
#define JS_DEFINE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
|
2021-06-15 16:38:12 +03:00
|
|
|
void OpTitleCase::execute_impl(Bytecode::Interpreter& interpreter) const \
|
2021-06-08 06:58:36 +03:00
|
|
|
{ \
|
|
|
|
auto lhs = interpreter.reg(m_lhs_reg); \
|
|
|
|
auto rhs = interpreter.accumulator(); \
|
|
|
|
interpreter.accumulator() = op_snake_case(interpreter.global_object(), lhs, rhs); \
|
|
|
|
} \
|
2021-06-15 16:38:12 +03:00
|
|
|
String OpTitleCase::to_string_impl(Bytecode::Executable const&) const \
|
2021-06-08 06:58:36 +03:00
|
|
|
{ \
|
2021-06-09 12:06:11 +03:00
|
|
|
return String::formatted(#OpTitleCase " {}", m_lhs_reg); \
|
2021-06-08 00:08:35 +03:00
|
|
|
}
|
2021-06-07 23:13:37 +03:00
|
|
|
|
2021-06-08 00:08:35 +03:00
|
|
|
JS_ENUMERATE_COMMON_BINARY_OPS(JS_DEFINE_COMMON_BINARY_OP)
|
2021-06-07 23:18:19 +03:00
|
|
|
|
2021-06-08 00:08:35 +03:00
|
|
|
static Value not_(GlobalObject&, Value value)
|
2021-06-07 23:13:37 +03:00
|
|
|
{
|
2021-06-08 00:08:35 +03:00
|
|
|
return Value(!value.to_boolean());
|
2021-06-07 23:13:37 +03:00
|
|
|
}
|
|
|
|
|
2021-06-08 00:08:35 +03:00
|
|
|
static Value typeof_(GlobalObject& global_object, Value value)
|
2021-06-07 21:53:47 +03:00
|
|
|
{
|
2021-06-08 00:08:35 +03:00
|
|
|
return js_string(global_object.vm(), value.typeof());
|
2021-06-07 21:53:47 +03:00
|
|
|
}
|
|
|
|
|
2021-06-08 06:58:36 +03:00
|
|
|
#define JS_DEFINE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
|
2021-06-15 16:38:12 +03:00
|
|
|
void OpTitleCase::execute_impl(Bytecode::Interpreter& interpreter) const \
|
2021-06-08 06:58:36 +03:00
|
|
|
{ \
|
|
|
|
interpreter.accumulator() = op_snake_case(interpreter.global_object(), interpreter.accumulator()); \
|
|
|
|
} \
|
2021-06-15 16:38:12 +03:00
|
|
|
String OpTitleCase::to_string_impl(Bytecode::Executable const&) const \
|
2021-06-08 06:58:36 +03:00
|
|
|
{ \
|
|
|
|
return #OpTitleCase; \
|
2021-06-08 00:08:35 +03:00
|
|
|
}
|
2021-06-07 21:53:47 +03:00
|
|
|
|
2021-06-08 00:08:35 +03:00
|
|
|
JS_ENUMERATE_COMMON_UNARY_OPS(JS_DEFINE_COMMON_UNARY_OP)
|
2021-06-07 21:53:47 +03:00
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void NewBigInt::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-08 08:59:25 +03:00
|
|
|
{
|
2021-06-08 06:58:36 +03:00
|
|
|
interpreter.accumulator() = js_bigint(interpreter.vm().heap(), m_bigint);
|
2021-06-08 08:59:25 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void NewArray::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-09 00:06:52 +03:00
|
|
|
{
|
|
|
|
Vector<Value> elements;
|
|
|
|
elements.ensure_capacity(m_element_count);
|
|
|
|
for (size_t i = 0; i < m_element_count; i++)
|
|
|
|
elements.append(interpreter.reg(m_elements[i]));
|
|
|
|
interpreter.accumulator() = Array::create_from(interpreter.global_object(), elements);
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void NewString::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-03 19:26:32 +03:00
|
|
|
{
|
2021-06-09 11:02:01 +03:00
|
|
|
interpreter.accumulator() = js_string(interpreter.vm(), interpreter.current_executable().get_string(m_string));
|
2021-06-03 19:26:32 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void NewObject::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-04 21:30:23 +03:00
|
|
|
{
|
2021-06-16 22:52:30 +03:00
|
|
|
interpreter.accumulator() = Object::create(interpreter.global_object(), interpreter.global_object().object_prototype());
|
2021-06-08 06:58:36 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void ConcatString::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-08 06:58:36 +03:00
|
|
|
{
|
|
|
|
interpreter.reg(m_lhs) = add(interpreter.global_object(), interpreter.reg(m_lhs), interpreter.accumulator());
|
2021-06-04 21:30:23 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void GetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-03 19:26:32 +03:00
|
|
|
{
|
2021-06-09 11:02:01 +03:00
|
|
|
interpreter.accumulator() = interpreter.vm().get_variable(interpreter.current_executable().get_string(m_identifier), interpreter.global_object());
|
2021-06-03 19:26:32 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void SetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-03 19:26:32 +03:00
|
|
|
{
|
2021-06-09 11:02:01 +03:00
|
|
|
interpreter.vm().set_variable(interpreter.current_executable().get_string(m_identifier), interpreter.accumulator(), interpreter.global_object());
|
2021-06-03 19:26:32 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void GetById::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-04 22:03:53 +03:00
|
|
|
{
|
2021-06-08 06:58:36 +03:00
|
|
|
if (auto* object = interpreter.accumulator().to_object(interpreter.global_object()))
|
2021-06-13 18:50:05 +03:00
|
|
|
interpreter.accumulator() = object->get(interpreter.current_executable().get_string(m_property)).value_or(js_undefined());
|
2021-06-04 22:03:53 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void PutById::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-04 21:47:07 +03:00
|
|
|
{
|
|
|
|
if (auto* object = interpreter.reg(m_base).to_object(interpreter.global_object()))
|
2021-06-09 11:02:01 +03:00
|
|
|
object->put(interpreter.current_executable().get_string(m_property), interpreter.accumulator());
|
2021-06-04 21:47:07 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Jump::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-04 13:07:38 +03:00
|
|
|
{
|
2021-06-09 05:19:58 +03:00
|
|
|
interpreter.jump(*m_true_target);
|
2021-06-04 13:07:38 +03:00
|
|
|
}
|
|
|
|
|
2021-06-13 19:10:20 +03:00
|
|
|
void Jump::replace_references_impl(BasicBlock const& from, BasicBlock const& to)
|
|
|
|
{
|
|
|
|
if (m_true_target.has_value() && &m_true_target->block() == &from)
|
|
|
|
m_true_target = Label { to };
|
|
|
|
if (m_false_target.has_value() && &m_false_target->block() == &from)
|
|
|
|
m_false_target = Label { to };
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void JumpConditional::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-04 13:07:38 +03:00
|
|
|
{
|
2021-06-09 05:19:58 +03:00
|
|
|
VERIFY(m_true_target.has_value());
|
|
|
|
VERIFY(m_false_target.has_value());
|
2021-06-08 06:58:36 +03:00
|
|
|
auto result = interpreter.accumulator();
|
2021-06-07 23:53:33 +03:00
|
|
|
if (result.to_boolean())
|
2021-06-09 05:19:58 +03:00
|
|
|
interpreter.jump(m_true_target.value());
|
|
|
|
else
|
|
|
|
interpreter.jump(m_false_target.value());
|
2021-06-04 13:20:44 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void JumpNullish::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-08 03:18:47 +03:00
|
|
|
{
|
2021-06-09 05:19:58 +03:00
|
|
|
VERIFY(m_true_target.has_value());
|
|
|
|
VERIFY(m_false_target.has_value());
|
2021-06-08 06:58:36 +03:00
|
|
|
auto result = interpreter.accumulator();
|
2021-06-09 05:19:58 +03:00
|
|
|
if (result.is_nullish())
|
|
|
|
interpreter.jump(m_true_target.value());
|
|
|
|
else
|
|
|
|
interpreter.jump(m_false_target.value());
|
2021-06-08 03:18:47 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Call::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-05 16:15:30 +03:00
|
|
|
{
|
|
|
|
auto callee = interpreter.reg(m_callee);
|
|
|
|
if (!callee.is_function()) {
|
|
|
|
TODO();
|
|
|
|
}
|
|
|
|
auto& function = callee.as_function();
|
|
|
|
|
|
|
|
auto this_value = interpreter.reg(m_this_value);
|
|
|
|
|
|
|
|
Value return_value;
|
|
|
|
|
2021-06-11 00:01:49 +03:00
|
|
|
if (m_argument_count == 0 && m_type == CallType::Call) {
|
2021-06-05 16:15:30 +03:00
|
|
|
return_value = interpreter.vm().call(function, this_value);
|
|
|
|
} else {
|
|
|
|
MarkedValueList argument_values { interpreter.vm().heap() };
|
2021-06-07 16:12:43 +03:00
|
|
|
for (size_t i = 0; i < m_argument_count; ++i) {
|
|
|
|
argument_values.append(interpreter.reg(m_arguments[i]));
|
2021-06-05 16:15:30 +03:00
|
|
|
}
|
2021-06-11 00:01:49 +03:00
|
|
|
if (m_type == CallType::Call)
|
|
|
|
return_value = interpreter.vm().call(function, this_value, move(argument_values));
|
|
|
|
else
|
2021-06-11 00:17:29 +03:00
|
|
|
return_value = interpreter.vm().construct(function, function, move(argument_values));
|
2021-06-05 16:15:30 +03:00
|
|
|
}
|
|
|
|
|
2021-06-08 06:58:36 +03:00
|
|
|
interpreter.accumulator() = return_value;
|
2021-06-05 16:15:30 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void NewFunction::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-05 16:14:09 +03:00
|
|
|
{
|
|
|
|
auto& vm = interpreter.vm();
|
2021-06-11 02:08:05 +03:00
|
|
|
interpreter.accumulator() = ScriptFunction::create(interpreter.global_object(), m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.current_scope(), m_function_node.kind(), m_function_node.is_strict_mode(), m_function_node.is_arrow_function());
|
2021-06-05 16:14:09 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Return::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-05 16:53:36 +03:00
|
|
|
{
|
2021-06-08 06:58:36 +03:00
|
|
|
interpreter.do_return(interpreter.accumulator().value_or(js_undefined()));
|
2021-06-05 16:53:36 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Increment::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-09 12:40:38 +03:00
|
|
|
{
|
|
|
|
auto old_value = interpreter.accumulator().to_numeric(interpreter.global_object());
|
|
|
|
if (interpreter.vm().exception())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (old_value.is_number())
|
|
|
|
interpreter.accumulator() = Value(old_value.as_double() + 1);
|
|
|
|
else
|
|
|
|
interpreter.accumulator() = js_bigint(interpreter.vm().heap(), old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 }));
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Decrement::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-09 12:40:38 +03:00
|
|
|
{
|
|
|
|
auto old_value = interpreter.accumulator().to_numeric(interpreter.global_object());
|
|
|
|
if (interpreter.vm().exception())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (old_value.is_number())
|
|
|
|
interpreter.accumulator() = Value(old_value.as_double() - 1);
|
|
|
|
else
|
|
|
|
interpreter.accumulator() = js_bigint(interpreter.vm().heap(), old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 }));
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Throw::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-09 19:18:56 +03:00
|
|
|
{
|
|
|
|
interpreter.vm().throw_exception(interpreter.global_object(), interpreter.accumulator());
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void EnterUnwindContext::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-10 16:04:38 +03:00
|
|
|
{
|
|
|
|
interpreter.enter_unwind_context(m_handler_target, m_finalizer_target);
|
2021-06-13 19:09:40 +03:00
|
|
|
interpreter.jump(m_entry_point);
|
2021-06-10 16:04:38 +03:00
|
|
|
}
|
|
|
|
|
2021-06-13 19:10:20 +03:00
|
|
|
void EnterUnwindContext::replace_references_impl(BasicBlock const& from, BasicBlock const& to)
|
|
|
|
{
|
|
|
|
if (&m_entry_point.block() == &from)
|
|
|
|
m_entry_point = Label { to };
|
|
|
|
if (m_handler_target.has_value() && &m_handler_target->block() == &from)
|
|
|
|
m_handler_target = Label { to };
|
|
|
|
if (m_finalizer_target.has_value() && &m_finalizer_target->block() == &from)
|
|
|
|
m_finalizer_target = Label { to };
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void LeaveUnwindContext::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-10 16:04:38 +03:00
|
|
|
{
|
|
|
|
interpreter.leave_unwind_context();
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void ContinuePendingUnwind::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-10 16:04:38 +03:00
|
|
|
{
|
|
|
|
interpreter.continue_pending_unwind(m_resume_target);
|
|
|
|
}
|
|
|
|
|
2021-06-13 19:10:20 +03:00
|
|
|
void ContinuePendingUnwind::replace_references_impl(BasicBlock const& from, BasicBlock const& to)
|
|
|
|
{
|
|
|
|
if (&m_resume_target.block() == &from)
|
|
|
|
m_resume_target = Label { to };
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void PushLexicalEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-10 23:12:21 +03:00
|
|
|
{
|
|
|
|
HashMap<FlyString, Variable> resolved_variables;
|
|
|
|
for (auto& it : m_variables)
|
|
|
|
resolved_variables.set(interpreter.current_executable().get_string(it.key), it.value);
|
|
|
|
auto* block_lexical_environment = interpreter.vm().heap().allocate<LexicalEnvironment>(interpreter.global_object(), move(resolved_variables), interpreter.vm().current_scope());
|
|
|
|
interpreter.vm().call_frame().scope = block_lexical_environment;
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void Yield::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-11 00:08:30 +03:00
|
|
|
{
|
|
|
|
auto yielded_value = interpreter.accumulator().value_or(js_undefined());
|
2021-06-16 22:52:30 +03:00
|
|
|
auto object = JS::Object::create(interpreter.global_object(), nullptr);
|
2021-06-11 00:08:30 +03:00
|
|
|
object->put("result", yielded_value);
|
|
|
|
if (m_continuation_label.has_value())
|
|
|
|
object->put("continuation", Value(static_cast<double>(reinterpret_cast<u64>(&m_continuation_label->block()))));
|
|
|
|
else
|
|
|
|
object->put("continuation", Value(0));
|
|
|
|
interpreter.do_return(object);
|
|
|
|
}
|
|
|
|
|
2021-06-13 19:10:20 +03:00
|
|
|
void Yield::replace_references_impl(BasicBlock const& from, BasicBlock const& to)
|
|
|
|
{
|
|
|
|
if (m_continuation_label.has_value() && &m_continuation_label->block() == &from)
|
|
|
|
m_continuation_label = Label { to };
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void GetByValue::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-11 01:35:25 +03:00
|
|
|
{
|
|
|
|
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;
|
2021-06-13 18:50:05 +03:00
|
|
|
interpreter.accumulator() = object->get(property_key).value_or(js_undefined());
|
2021-06-11 01:35:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void PutByValue::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-11 01:35:25 +03:00
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
void LoadArgument::execute_impl(Bytecode::Interpreter& interpreter) const
|
2021-06-14 10:37:35 +03:00
|
|
|
{
|
|
|
|
interpreter.accumulator() = interpreter.vm().argument(m_index);
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Load::to_string_impl(Bytecode::Executable const&) const
|
2021-06-03 11:46:30 +03:00
|
|
|
{
|
2021-06-09 12:06:11 +03:00
|
|
|
return String::formatted("Load {}", m_src);
|
2021-06-03 11:46:30 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String LoadImmediate::to_string_impl(Bytecode::Executable const&) const
|
2021-06-07 23:05:09 +03:00
|
|
|
{
|
2021-06-09 12:06:11 +03:00
|
|
|
return String::formatted("LoadImmediate {}", m_value);
|
2021-06-08 06:58:36 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Store::to_string_impl(Bytecode::Executable const&) const
|
2021-06-08 06:58:36 +03:00
|
|
|
{
|
2021-06-09 12:06:11 +03:00
|
|
|
return String::formatted("Store {}", m_dst);
|
2021-06-07 23:05:09 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String NewBigInt::to_string_impl(Bytecode::Executable const&) const
|
2021-06-08 08:59:25 +03:00
|
|
|
{
|
2021-06-09 12:06:11 +03:00
|
|
|
return String::formatted("NewBigInt \"{}\"", m_bigint.to_base10());
|
2021-06-08 08:59:25 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String NewArray::to_string_impl(Bytecode::Executable const&) const
|
2021-06-09 00:06:52 +03:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
|
|
|
builder.append("NewArray");
|
|
|
|
if (m_element_count != 0) {
|
2021-06-09 12:06:11 +03:00
|
|
|
builder.append(" [");
|
2021-06-09 00:06:52 +03:00
|
|
|
for (size_t i = 0; i < m_element_count; ++i) {
|
|
|
|
builder.appendff("{}", m_elements[i]);
|
|
|
|
if (i != m_element_count - 1)
|
|
|
|
builder.append(',');
|
|
|
|
}
|
|
|
|
builder.append(']');
|
|
|
|
}
|
|
|
|
return builder.to_string();
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String NewString::to_string_impl(Bytecode::Executable const& executable) const
|
2021-06-03 19:26:32 +03:00
|
|
|
{
|
2021-06-09 11:02:01 +03:00
|
|
|
return String::formatted("NewString {} (\"{}\")", m_string, executable.string_table->get(m_string));
|
2021-06-03 19:26:32 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String NewObject::to_string_impl(Bytecode::Executable const&) const
|
2021-06-04 21:30:23 +03:00
|
|
|
{
|
2021-06-08 06:58:36 +03:00
|
|
|
return "NewObject";
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String ConcatString::to_string_impl(Bytecode::Executable const&) const
|
2021-06-08 06:58:36 +03:00
|
|
|
{
|
2021-06-09 12:06:11 +03:00
|
|
|
return String::formatted("ConcatString {}", m_lhs);
|
2021-06-04 21:30:23 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String GetVariable::to_string_impl(Bytecode::Executable const& executable) const
|
2021-06-03 19:26:32 +03:00
|
|
|
{
|
2021-06-09 11:02:01 +03:00
|
|
|
return String::formatted("GetVariable {} ({})", m_identifier, executable.string_table->get(m_identifier));
|
2021-06-03 19:26:32 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String SetVariable::to_string_impl(Bytecode::Executable const& executable) const
|
2021-06-03 19:26:32 +03:00
|
|
|
{
|
2021-06-09 11:02:01 +03:00
|
|
|
return String::formatted("SetVariable {} ({})", m_identifier, executable.string_table->get(m_identifier));
|
2021-06-03 19:26:32 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String PutById::to_string_impl(Bytecode::Executable const& executable) const
|
2021-06-04 21:47:07 +03:00
|
|
|
{
|
2021-06-09 11:02:01 +03:00
|
|
|
return String::formatted("PutById base:{}, property:{} ({})", m_base, m_property, executable.string_table->get(m_property));
|
2021-06-04 21:47:07 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String GetById::to_string_impl(Bytecode::Executable const& executable) const
|
2021-06-04 22:03:53 +03:00
|
|
|
{
|
2021-06-09 11:02:01 +03:00
|
|
|
return String::formatted("GetById {} ({})", m_property, executable.string_table->get(m_property));
|
2021-06-04 22:03:53 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Jump::to_string_impl(Bytecode::Executable const&) const
|
2021-06-04 13:07:38 +03:00
|
|
|
{
|
2021-06-09 05:19:58 +03:00
|
|
|
if (m_true_target.has_value())
|
|
|
|
return String::formatted("Jump {}", *m_true_target);
|
|
|
|
return String::formatted("Jump <empty>");
|
2021-06-04 13:07:38 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String JumpConditional::to_string_impl(Bytecode::Executable const&) const
|
2021-06-04 13:20:44 +03:00
|
|
|
{
|
2021-06-09 05:19:58 +03:00
|
|
|
auto true_string = m_true_target.has_value() ? String::formatted("{}", *m_true_target) : "<empty>";
|
|
|
|
auto false_string = m_false_target.has_value() ? String::formatted("{}", *m_false_target) : "<empty>";
|
|
|
|
return String::formatted("JumpConditional true:{} false:{}", true_string, false_string);
|
2021-06-04 13:20:44 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String JumpNullish::to_string_impl(Bytecode::Executable const&) const
|
2021-06-08 03:18:47 +03:00
|
|
|
{
|
2021-06-09 05:19:58 +03:00
|
|
|
auto true_string = m_true_target.has_value() ? String::formatted("{}", *m_true_target) : "<empty>";
|
|
|
|
auto false_string = m_false_target.has_value() ? String::formatted("{}", *m_false_target) : "<empty>";
|
|
|
|
return String::formatted("JumpNullish null:{} nonnull:{}", true_string, false_string);
|
2021-06-08 03:18:47 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Call::to_string_impl(Bytecode::Executable const&) const
|
2021-06-05 16:15:30 +03:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
2021-06-08 06:58:36 +03:00
|
|
|
builder.appendff("Call callee:{}, this:{}", m_callee, m_this_value);
|
2021-06-07 16:12:43 +03:00
|
|
|
if (m_argument_count != 0) {
|
2021-06-05 16:15:30 +03:00
|
|
|
builder.append(", arguments:[");
|
2021-06-07 16:12:43 +03:00
|
|
|
for (size_t i = 0; i < m_argument_count; ++i) {
|
2021-06-05 16:15:30 +03:00
|
|
|
builder.appendff("{}", m_arguments[i]);
|
2021-06-07 16:12:43 +03:00
|
|
|
if (i != m_argument_count - 1)
|
2021-06-05 16:15:30 +03:00
|
|
|
builder.append(',');
|
|
|
|
}
|
|
|
|
builder.append(']');
|
|
|
|
}
|
|
|
|
return builder.to_string();
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String NewFunction::to_string_impl(Bytecode::Executable const&) const
|
2021-06-05 16:14:09 +03:00
|
|
|
{
|
2021-06-10 01:49:23 +03:00
|
|
|
return "NewFunction";
|
2021-06-05 16:14:09 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Return::to_string_impl(Bytecode::Executable const&) const
|
2021-06-05 16:53:36 +03:00
|
|
|
{
|
|
|
|
return "Return";
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Increment::to_string_impl(Bytecode::Executable const&) const
|
2021-06-09 12:40:38 +03:00
|
|
|
{
|
|
|
|
return "Increment";
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Decrement::to_string_impl(Bytecode::Executable const&) const
|
2021-06-09 12:40:38 +03:00
|
|
|
{
|
|
|
|
return "Decrement";
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Throw::to_string_impl(Bytecode::Executable const&) const
|
2021-06-09 19:18:56 +03:00
|
|
|
{
|
|
|
|
return "Throw";
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String EnterUnwindContext::to_string_impl(Bytecode::Executable const&) const
|
2021-06-10 16:04:38 +03:00
|
|
|
{
|
|
|
|
auto handler_string = m_handler_target.has_value() ? String::formatted("{}", *m_handler_target) : "<empty>";
|
|
|
|
auto finalizer_string = m_finalizer_target.has_value() ? String::formatted("{}", *m_finalizer_target) : "<empty>";
|
2021-06-13 19:09:40 +03:00
|
|
|
return String::formatted("EnterUnwindContext handler:{} finalizer:{} entry:{}", handler_string, finalizer_string, m_entry_point);
|
2021-06-10 16:04:38 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String LeaveUnwindContext::to_string_impl(Bytecode::Executable const&) const
|
2021-06-10 16:04:38 +03:00
|
|
|
{
|
|
|
|
return "LeaveUnwindContext";
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String ContinuePendingUnwind::to_string_impl(Bytecode::Executable const&) const
|
2021-06-10 16:04:38 +03:00
|
|
|
{
|
|
|
|
return String::formatted("ContinuePendingUnwind resume:{}", m_resume_target);
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String PushLexicalEnvironment::to_string_impl(const Bytecode::Executable& executable) const
|
2021-06-10 23:12:21 +03:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
|
|
|
builder.append("PushLexicalEnvironment");
|
|
|
|
if (!m_variables.is_empty()) {
|
|
|
|
builder.append(" {");
|
|
|
|
Vector<String> names;
|
|
|
|
for (auto& it : m_variables)
|
|
|
|
names.append(executable.get_string(it.key));
|
|
|
|
builder.join(", ", names);
|
|
|
|
builder.append("}");
|
|
|
|
}
|
|
|
|
return builder.to_string();
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String Yield::to_string_impl(Bytecode::Executable const&) const
|
2021-06-11 00:08:30 +03:00
|
|
|
{
|
|
|
|
if (m_continuation_label.has_value())
|
|
|
|
return String::formatted("Yield continuation:@{}", m_continuation_label->block().name());
|
|
|
|
return String::formatted("Yield return");
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String GetByValue::to_string_impl(const Bytecode::Executable&) const
|
2021-06-11 01:35:25 +03:00
|
|
|
{
|
|
|
|
return String::formatted("GetByValue base:{}", m_base);
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String PutByValue::to_string_impl(const Bytecode::Executable&) const
|
2021-06-11 01:35:25 +03:00
|
|
|
{
|
|
|
|
return String::formatted("PutByValue base:{}, property:{}", m_base, m_property);
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:38:12 +03:00
|
|
|
String LoadArgument::to_string_impl(const Bytecode::Executable&) const
|
2021-06-14 10:37:35 +03:00
|
|
|
{
|
|
|
|
return String::formatted("LoadArgument {}", m_index);
|
|
|
|
}
|
|
|
|
|
2021-06-03 11:46:30 +03:00
|
|
|
}
|