2021-06-03 08:46:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
2021-06-07 20:13:37 +00:00
|
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
2021-06-09 16:18:56 +00:00
|
|
|
* Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org>
|
2021-06-03 08:46:30 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-09-09 14:47:42 +00:00
|
|
|
#include <AK/StdLibExtras.h>
|
2021-06-08 05:59:25 +00:00
|
|
|
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
2021-10-24 13:34:30 +00:00
|
|
|
#include <LibJS/Bytecode/IdentifierTable.h>
|
2021-06-03 08:46:30 +00:00
|
|
|
#include <LibJS/Bytecode/Instruction.h>
|
2021-06-04 10:07:38 +00:00
|
|
|
#include <LibJS/Bytecode/Label.h>
|
2021-06-03 08:46:30 +00:00
|
|
|
#include <LibJS/Bytecode/Register.h>
|
2021-06-09 08:02:01 +00:00
|
|
|
#include <LibJS/Bytecode/StringTable.h>
|
2021-06-03 08:46:30 +00:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2021-07-01 10:24:46 +00:00
|
|
|
#include <LibJS/Runtime/Environment.h>
|
2021-10-24 13:36:24 +00:00
|
|
|
#include <LibJS/Runtime/EnvironmentCoordinate.h>
|
2021-06-03 08:46:30 +00:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
2022-02-12 08:48:23 +00:00
|
|
|
#include <LibJS/Runtime/ValueTraits.h>
|
2021-06-03 08:46:30 +00:00
|
|
|
|
|
|
|
namespace JS::Bytecode::Op {
|
|
|
|
|
|
|
|
class Load final : public Instruction {
|
|
|
|
public:
|
2021-06-12 09:22:46 +00:00
|
|
|
explicit Load(Register src)
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::Load)
|
2021-06-08 03:58:36 +00:00
|
|
|
, m_src(src)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-08 03:58:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_src;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LoadImmediate final : public Instruction {
|
|
|
|
public:
|
2021-06-12 09:22:46 +00:00
|
|
|
explicit LoadImmediate(Value value)
|
2021-06-08 03:58:36 +00:00
|
|
|
: Instruction(Type::LoadImmediate)
|
2021-06-03 08:46:30 +00:00
|
|
|
, m_value(value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-03 08:46:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Value m_value;
|
|
|
|
};
|
|
|
|
|
2021-06-08 03:58:36 +00:00
|
|
|
class Store final : public Instruction {
|
2021-06-07 20:05:09 +00:00
|
|
|
public:
|
2021-06-12 09:22:46 +00:00
|
|
|
explicit Store(Register dst)
|
2021-06-08 03:58:36 +00:00
|
|
|
: Instruction(Type::Store)
|
2021-06-07 20:05:09 +00:00
|
|
|
, m_dst(dst)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-07 20:05:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_dst;
|
|
|
|
};
|
|
|
|
|
2021-06-07 21:08:35 +00:00
|
|
|
#define JS_ENUMERATE_COMMON_BINARY_OPS(O) \
|
|
|
|
O(Add, add) \
|
|
|
|
O(Sub, sub) \
|
|
|
|
O(Mul, mul) \
|
|
|
|
O(Div, div) \
|
|
|
|
O(Exp, exp) \
|
|
|
|
O(Mod, mod) \
|
|
|
|
O(In, in) \
|
|
|
|
O(InstanceOf, instance_of) \
|
|
|
|
O(GreaterThan, greater_than) \
|
|
|
|
O(GreaterThanEquals, greater_than_equals) \
|
|
|
|
O(LessThan, less_than) \
|
|
|
|
O(LessThanEquals, less_than_equals) \
|
2021-09-23 22:06:10 +00:00
|
|
|
O(LooselyInequals, abstract_inequals) \
|
|
|
|
O(LooselyEquals, abstract_equals) \
|
|
|
|
O(StrictlyInequals, typed_inequals) \
|
|
|
|
O(StrictlyEquals, typed_equals) \
|
2021-06-07 21:08:35 +00:00
|
|
|
O(BitwiseAnd, bitwise_and) \
|
|
|
|
O(BitwiseOr, bitwise_or) \
|
|
|
|
O(BitwiseXor, bitwise_xor) \
|
|
|
|
O(LeftShift, left_shift) \
|
|
|
|
O(RightShift, right_shift) \
|
|
|
|
O(UnsignedRightShift, unsigned_right_shift)
|
|
|
|
|
2021-06-13 16:10:20 +00:00
|
|
|
#define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
|
|
|
|
class OpTitleCase final : public Instruction { \
|
|
|
|
public: \
|
|
|
|
explicit OpTitleCase(Register lhs_reg) \
|
|
|
|
: Instruction(Type::OpTitleCase) \
|
|
|
|
, m_lhs_reg(lhs_reg) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
\
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
|
2021-06-13 16:10:20 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const; \
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { } \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
Register m_lhs_reg; \
|
2021-06-07 21:08:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_ENUMERATE_COMMON_BINARY_OPS(JS_DECLARE_COMMON_BINARY_OP)
|
|
|
|
#undef JS_DECLARE_COMMON_BINARY_OP
|
|
|
|
|
|
|
|
#define JS_ENUMERATE_COMMON_UNARY_OPS(O) \
|
|
|
|
O(BitwiseNot, bitwise_not) \
|
|
|
|
O(Not, not_) \
|
|
|
|
O(UnaryPlus, unary_plus) \
|
|
|
|
O(UnaryMinus, unary_minus) \
|
|
|
|
O(Typeof, typeof_)
|
|
|
|
|
2021-06-13 16:10:20 +00:00
|
|
|
#define JS_DECLARE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
|
|
|
|
class OpTitleCase final : public Instruction { \
|
|
|
|
public: \
|
|
|
|
OpTitleCase() \
|
|
|
|
: Instruction(Type::OpTitleCase) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
\
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
|
2021-06-13 16:10:20 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const; \
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { } \
|
2021-06-07 21:08:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_ENUMERATE_COMMON_UNARY_OPS(JS_DECLARE_COMMON_UNARY_OP)
|
|
|
|
#undef JS_DECLARE_COMMON_UNARY_OP
|
2021-06-07 18:53:47 +00:00
|
|
|
|
2021-06-03 16:26:32 +00:00
|
|
|
class NewString final : public Instruction {
|
|
|
|
public:
|
2021-06-12 09:22:46 +00:00
|
|
|
explicit NewString(StringTableIndex string)
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::NewString)
|
2021-06-12 09:22:46 +00:00
|
|
|
, m_string(string)
|
2021-06-03 16:26:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-03 16:26:32 +00:00
|
|
|
|
|
|
|
private:
|
2021-06-09 08:02:01 +00:00
|
|
|
StringTableIndex m_string;
|
2021-06-03 16:26:32 +00:00
|
|
|
};
|
|
|
|
|
2021-06-04 18:30:23 +00:00
|
|
|
class NewObject final : public Instruction {
|
|
|
|
public:
|
2021-06-08 03:58:36 +00:00
|
|
|
NewObject()
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::NewObject)
|
2021-06-04 18:30:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-04 18:30:23 +00:00
|
|
|
};
|
|
|
|
|
2021-06-20 00:17:40 +00:00
|
|
|
class NewRegExp final : public Instruction {
|
|
|
|
public:
|
|
|
|
NewRegExp(StringTableIndex source_index, StringTableIndex flags_index)
|
|
|
|
: Instruction(Type::NewRegExp)
|
|
|
|
, m_source_index(source_index)
|
|
|
|
, m_flags_index(flags_index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-20 00:17:40 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
StringTableIndex m_source_index;
|
|
|
|
StringTableIndex m_flags_index;
|
|
|
|
};
|
|
|
|
|
2021-06-13 22:30:32 +00:00
|
|
|
// NOTE: This instruction is variable-width depending on the number of excluded names
|
|
|
|
class CopyObjectExcludingProperties final : public Instruction {
|
|
|
|
public:
|
|
|
|
CopyObjectExcludingProperties(Register from_object, Vector<Register> const& excluded_names)
|
|
|
|
: Instruction(Type::CopyObjectExcludingProperties)
|
|
|
|
, m_from_object(from_object)
|
|
|
|
, m_excluded_names_count(excluded_names.size())
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_excluded_names_count; i++)
|
|
|
|
m_excluded_names[i] = excluded_names[i];
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-13 22:30:32 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
size_t length_impl() const { return sizeof(*this) + sizeof(Register) * m_excluded_names_count; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_from_object;
|
|
|
|
size_t m_excluded_names_count { 0 };
|
|
|
|
Register m_excluded_names[];
|
|
|
|
};
|
|
|
|
|
2021-06-08 05:59:25 +00:00
|
|
|
class NewBigInt final : public Instruction {
|
|
|
|
public:
|
2021-06-08 03:58:36 +00:00
|
|
|
explicit NewBigInt(Crypto::SignedBigInteger bigint)
|
2021-06-08 05:59:25 +00:00
|
|
|
: Instruction(Type::NewBigInt)
|
|
|
|
, m_bigint(move(bigint))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-08 05:59:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Crypto::SignedBigInteger m_bigint;
|
|
|
|
};
|
|
|
|
|
2021-06-08 21:06:52 +00:00
|
|
|
// NOTE: This instruction is variable-width depending on the number of elements!
|
|
|
|
class NewArray final : public Instruction {
|
|
|
|
public:
|
2021-06-13 21:06:26 +00:00
|
|
|
NewArray()
|
|
|
|
: Instruction(Type::NewArray)
|
|
|
|
, m_element_count(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:48:42 +00:00
|
|
|
explicit NewArray(AK::Array<Register, 2> const& elements_range)
|
2021-06-08 21:06:52 +00:00
|
|
|
: Instruction(Type::NewArray)
|
2022-03-14 14:48:42 +00:00
|
|
|
, m_element_count(elements_range[1].index() - elements_range[0].index() + 1)
|
2021-06-08 21:06:52 +00:00
|
|
|
{
|
2022-03-14 14:48:42 +00:00
|
|
|
m_elements[0] = elements_range[0];
|
|
|
|
m_elements[1] = elements_range[1];
|
2021-06-08 21:06:52 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-08 21:06:52 +00:00
|
|
|
|
2021-06-13 16:10:20 +00:00
|
|
|
size_t length_impl() const
|
|
|
|
{
|
2022-03-14 14:48:42 +00:00
|
|
|
return sizeof(*this) + sizeof(Register) * (m_element_count == 0 ? 0 : 2);
|
2021-06-13 16:10:20 +00:00
|
|
|
}
|
2021-06-12 03:49:09 +00:00
|
|
|
|
2021-06-08 21:06:52 +00:00
|
|
|
private:
|
|
|
|
size_t m_element_count { 0 };
|
|
|
|
Register m_elements[];
|
|
|
|
};
|
|
|
|
|
2022-09-09 13:23:02 +00:00
|
|
|
class Append final : public Instruction {
|
|
|
|
public:
|
|
|
|
Append(Register lhs, bool is_spread)
|
|
|
|
: Instruction(Type::Append)
|
|
|
|
, m_lhs(lhs)
|
|
|
|
, m_is_spread(is_spread)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_lhs;
|
|
|
|
bool m_is_spread = false;
|
|
|
|
};
|
|
|
|
|
2021-06-13 21:06:26 +00:00
|
|
|
class IteratorToArray final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorToArray()
|
|
|
|
: Instruction(Type::IteratorToArray)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-13 21:06:26 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
2021-06-08 03:58:36 +00:00
|
|
|
class ConcatString final : public Instruction {
|
|
|
|
public:
|
2021-06-12 09:22:46 +00:00
|
|
|
explicit ConcatString(Register lhs)
|
2021-06-08 03:58:36 +00:00
|
|
|
: Instruction(Type::ConcatString)
|
|
|
|
, m_lhs(lhs)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-08 03:58:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_lhs;
|
|
|
|
};
|
|
|
|
|
2022-02-12 16:18:45 +00:00
|
|
|
enum class EnvironmentMode {
|
|
|
|
Lexical,
|
|
|
|
Var,
|
|
|
|
};
|
|
|
|
|
|
|
|
class CreateEnvironment final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit CreateEnvironment(EnvironmentMode mode)
|
|
|
|
: Instruction(Type::CreateEnvironment)
|
|
|
|
, m_mode(mode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
EnvironmentMode m_mode { EnvironmentMode::Lexical };
|
|
|
|
};
|
|
|
|
|
2022-03-13 12:31:18 +00:00
|
|
|
class EnterObjectEnvironment final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit EnterObjectEnvironment()
|
|
|
|
: Instruction(Type::EnterObjectEnvironment)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
2022-02-12 16:18:45 +00:00
|
|
|
class CreateVariable final : public Instruction {
|
|
|
|
public:
|
2022-07-17 18:06:44 +00:00
|
|
|
explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false)
|
2022-02-12 16:18:45 +00:00
|
|
|
: Instruction(Type::CreateVariable)
|
|
|
|
, m_identifier(identifier)
|
|
|
|
, m_mode(mode)
|
|
|
|
, m_is_immutable(is_immutable)
|
2022-07-17 18:06:44 +00:00
|
|
|
, m_is_global(is_global)
|
2022-02-12 16:18:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_identifier;
|
|
|
|
EnvironmentMode m_mode;
|
2022-07-17 18:06:44 +00:00
|
|
|
bool m_is_immutable : 4 { false };
|
|
|
|
bool m_is_global : 4 { false };
|
2022-02-12 16:18:45 +00:00
|
|
|
};
|
|
|
|
|
2021-06-03 16:26:32 +00:00
|
|
|
class SetVariable final : public Instruction {
|
|
|
|
public:
|
2022-02-12 16:18:45 +00:00
|
|
|
enum class InitializationMode {
|
|
|
|
Initialize,
|
|
|
|
Set,
|
|
|
|
InitializeOrSet,
|
|
|
|
};
|
|
|
|
explicit SetVariable(IdentifierTableIndex identifier, InitializationMode initialization_mode = InitializationMode::Set, EnvironmentMode mode = EnvironmentMode::Lexical)
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::SetVariable)
|
2021-06-12 09:22:46 +00:00
|
|
|
, m_identifier(identifier)
|
2022-02-12 16:18:45 +00:00
|
|
|
, m_mode(mode)
|
|
|
|
, m_initialization_mode(initialization_mode)
|
2021-06-03 16:26:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-03 16:26:32 +00:00
|
|
|
|
|
|
|
private:
|
2021-10-24 13:34:30 +00:00
|
|
|
IdentifierTableIndex m_identifier;
|
2022-02-12 16:18:45 +00:00
|
|
|
EnvironmentMode m_mode;
|
|
|
|
InitializationMode m_initialization_mode { InitializationMode::Set };
|
2021-06-03 16:26:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GetVariable final : public Instruction {
|
|
|
|
public:
|
2021-10-24 13:34:30 +00:00
|
|
|
explicit GetVariable(IdentifierTableIndex identifier)
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::GetVariable)
|
2021-06-12 09:22:46 +00:00
|
|
|
, m_identifier(identifier)
|
2021-06-03 16:26:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-03 16:26:32 +00:00
|
|
|
|
|
|
|
private:
|
2021-10-24 13:34:30 +00:00
|
|
|
IdentifierTableIndex m_identifier;
|
2021-10-24 13:36:24 +00:00
|
|
|
|
|
|
|
Optional<EnvironmentCoordinate> mutable m_cached_environment_coordinate;
|
2021-06-03 16:26:32 +00:00
|
|
|
};
|
|
|
|
|
2022-03-27 18:50:09 +00:00
|
|
|
class DeleteVariable final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit DeleteVariable(IdentifierTableIndex identifier)
|
|
|
|
: Instruction(Type::DeleteVariable)
|
|
|
|
, m_identifier(identifier)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_identifier;
|
|
|
|
};
|
|
|
|
|
2021-06-04 19:03:53 +00:00
|
|
|
class GetById final : public Instruction {
|
|
|
|
public:
|
2021-10-24 13:34:30 +00:00
|
|
|
explicit GetById(IdentifierTableIndex property)
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::GetById)
|
2021-06-12 09:22:46 +00:00
|
|
|
, m_property(property)
|
2021-06-04 19:03:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-04 19:03:53 +00:00
|
|
|
|
|
|
|
private:
|
2021-10-24 13:34:30 +00:00
|
|
|
IdentifierTableIndex m_property;
|
2021-06-04 19:03:53 +00:00
|
|
|
};
|
|
|
|
|
2022-03-30 20:29:58 +00:00
|
|
|
enum class PropertyKind {
|
|
|
|
Getter,
|
|
|
|
Setter,
|
|
|
|
KeyValue,
|
|
|
|
Spread,
|
|
|
|
ProtoSetter,
|
|
|
|
};
|
|
|
|
|
2021-06-04 18:47:07 +00:00
|
|
|
class PutById final : public Instruction {
|
|
|
|
public:
|
2022-03-30 20:29:58 +00:00
|
|
|
explicit PutById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::PutById)
|
|
|
|
, m_base(base)
|
2021-06-12 09:22:46 +00:00
|
|
|
, m_property(property)
|
2022-03-30 20:29:58 +00:00
|
|
|
, m_kind(kind)
|
2021-06-04 18:47:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-04 18:47:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
2021-10-24 13:34:30 +00:00
|
|
|
IdentifierTableIndex m_property;
|
2022-03-30 20:29:58 +00:00
|
|
|
PropertyKind m_kind;
|
2021-06-04 18:47:07 +00:00
|
|
|
};
|
|
|
|
|
2022-03-27 18:50:09 +00:00
|
|
|
class DeleteById final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit DeleteById(IdentifierTableIndex property)
|
|
|
|
: Instruction(Type::DeleteById)
|
|
|
|
, m_property(property)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
};
|
|
|
|
|
2021-06-10 22:35:25 +00:00
|
|
|
class GetByValue final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit GetByValue(Register base)
|
|
|
|
: Instruction(Type::GetByValue)
|
|
|
|
, m_base(base)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-10 22:35:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PutByValue final : public Instruction {
|
|
|
|
public:
|
2022-03-30 20:29:58 +00:00
|
|
|
PutByValue(Register base, Register property, PropertyKind kind = PropertyKind::KeyValue)
|
2021-06-10 22:35:25 +00:00
|
|
|
: Instruction(Type::PutByValue)
|
|
|
|
, m_base(base)
|
|
|
|
, m_property(property)
|
2022-03-30 20:29:58 +00:00
|
|
|
, m_kind(kind)
|
2021-06-10 22:35:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-10 22:35:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
Register m_property;
|
2022-03-30 20:29:58 +00:00
|
|
|
PropertyKind m_kind;
|
2021-06-10 22:35:25 +00:00
|
|
|
};
|
|
|
|
|
2022-03-27 18:50:09 +00:00
|
|
|
class DeleteByValue final : public Instruction {
|
|
|
|
public:
|
|
|
|
DeleteByValue(Register base)
|
|
|
|
: Instruction(Type::DeleteByValue)
|
|
|
|
, m_base(base)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
};
|
|
|
|
|
2021-06-08 09:28:27 +00:00
|
|
|
class Jump : public Instruction {
|
2021-06-04 10:07:38 +00:00
|
|
|
public:
|
2021-06-09 02:19:58 +00:00
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
explicit Jump(Type type, Optional<Label> taken_target = {}, Optional<Label> nontaken_target = {})
|
2021-06-08 09:28:27 +00:00
|
|
|
: Instruction(type)
|
2021-06-09 02:19:58 +00:00
|
|
|
, m_true_target(move(taken_target))
|
|
|
|
, m_false_target(move(nontaken_target))
|
2021-06-08 09:28:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-09 02:19:58 +00:00
|
|
|
explicit Jump(Optional<Label> taken_target = {}, Optional<Label> nontaken_target = {})
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::Jump)
|
2021-06-09 02:19:58 +00:00
|
|
|
, m_true_target(move(taken_target))
|
|
|
|
, m_false_target(move(nontaken_target))
|
2021-06-04 10:07:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-09 02:19:58 +00:00
|
|
|
void set_targets(Optional<Label> true_target, Optional<Label> false_target)
|
2021-06-04 10:07:38 +00:00
|
|
|
{
|
2021-06-09 02:19:58 +00:00
|
|
|
m_true_target = move(true_target);
|
|
|
|
m_false_target = move(false_target);
|
2021-06-04 10:07:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&);
|
|
|
|
|
|
|
|
auto& true_target() const { return m_true_target; }
|
|
|
|
auto& false_target() const { return m_false_target; }
|
2021-06-09 02:19:58 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Optional<Label> m_true_target;
|
|
|
|
Optional<Label> m_false_target;
|
2021-06-04 10:07:38 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 02:19:58 +00:00
|
|
|
class JumpConditional final : public Jump {
|
2021-06-04 10:20:44 +00:00
|
|
|
public:
|
2021-06-09 02:19:58 +00:00
|
|
|
explicit JumpConditional(Optional<Label> true_target = {}, Optional<Label> false_target = {})
|
|
|
|
: Jump(Type::JumpConditional, move(true_target), move(false_target))
|
2021-06-04 10:20:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-04 10:20:44 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 02:19:58 +00:00
|
|
|
class JumpNullish final : public Jump {
|
2021-06-08 00:18:47 +00:00
|
|
|
public:
|
2021-06-09 02:19:58 +00:00
|
|
|
explicit JumpNullish(Optional<Label> true_target = {}, Optional<Label> false_target = {})
|
|
|
|
: Jump(Type::JumpNullish, move(true_target), move(false_target))
|
2021-06-08 00:18:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-08 00:18:47 +00:00
|
|
|
};
|
|
|
|
|
2021-06-13 19:24:40 +00:00
|
|
|
class JumpUndefined final : public Jump {
|
|
|
|
public:
|
|
|
|
explicit JumpUndefined(Optional<Label> true_target = {}, Optional<Label> false_target = {})
|
|
|
|
: Jump(Type::JumpUndefined, move(true_target), move(false_target))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-13 19:24:40 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
};
|
|
|
|
|
2021-06-07 13:12:43 +00:00
|
|
|
// NOTE: This instruction is variable-width depending on the number of arguments!
|
2021-06-05 13:15:30 +00:00
|
|
|
class Call final : public Instruction {
|
|
|
|
public:
|
2021-06-10 21:01:49 +00:00
|
|
|
enum class CallType {
|
|
|
|
Call,
|
|
|
|
Construct,
|
|
|
|
};
|
|
|
|
|
2022-09-07 21:39:43 +00:00
|
|
|
Call(CallType type, Register callee, Register this_value)
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::Call)
|
2021-06-05 13:15:30 +00:00
|
|
|
, m_callee(callee)
|
|
|
|
, m_this_value(this_value)
|
2021-06-10 21:01:49 +00:00
|
|
|
, m_type(type)
|
2021-06-05 13:15:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-07 13:12:43 +00:00
|
|
|
|
2021-06-05 13:15:30 +00:00
|
|
|
private:
|
|
|
|
Register m_callee;
|
|
|
|
Register m_this_value;
|
2021-06-10 21:01:49 +00:00
|
|
|
CallType m_type;
|
2021-06-05 13:15:30 +00:00
|
|
|
};
|
|
|
|
|
2022-08-30 16:03:02 +00:00
|
|
|
// NOTE: This instruction is variable-width depending on the number of arguments!
|
|
|
|
class SuperCall : public Instruction {
|
|
|
|
public:
|
2022-09-07 21:39:43 +00:00
|
|
|
explicit SuperCall(bool is_synthetic)
|
2022-08-30 16:03:02 +00:00
|
|
|
: Instruction(Type::SuperCall)
|
|
|
|
, m_is_synthetic(is_synthetic)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_is_synthetic;
|
|
|
|
};
|
|
|
|
|
2021-06-30 18:42:13 +00:00
|
|
|
class NewClass final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit NewClass(ClassExpression const& class_expression)
|
|
|
|
: Instruction(Type::NewClass)
|
|
|
|
, m_class_expression(class_expression)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-30 18:42:13 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ClassExpression const& m_class_expression;
|
|
|
|
};
|
|
|
|
|
2021-06-09 22:49:23 +00:00
|
|
|
class NewFunction final : public Instruction {
|
2021-06-05 13:14:09 +00:00
|
|
|
public:
|
2021-06-09 22:49:23 +00:00
|
|
|
explicit NewFunction(FunctionNode const& function_node)
|
|
|
|
: Instruction(Type::NewFunction)
|
|
|
|
, m_function_node(function_node)
|
2021-06-05 13:14:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-05 13:14:09 +00:00
|
|
|
|
|
|
|
private:
|
2021-06-09 22:49:23 +00:00
|
|
|
FunctionNode const& m_function_node;
|
2021-06-05 13:14:09 +00:00
|
|
|
};
|
|
|
|
|
2021-06-05 13:53:36 +00:00
|
|
|
class Return final : public Instruction {
|
|
|
|
public:
|
2021-06-09 02:19:58 +00:00
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
2021-06-08 03:58:36 +00:00
|
|
|
Return()
|
2021-06-07 13:12:43 +00:00
|
|
|
: Instruction(Type::Return)
|
2021-06-05 13:53:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-05 13:53:36 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 09:40:38 +00:00
|
|
|
class Increment final : public Instruction {
|
|
|
|
public:
|
|
|
|
Increment()
|
|
|
|
: Instruction(Type::Increment)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-09 09:40:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Decrement final : public Instruction {
|
|
|
|
public:
|
|
|
|
Decrement()
|
|
|
|
: Instruction(Type::Decrement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-09 09:40:38 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 16:18:56 +00:00
|
|
|
class Throw final : public Instruction {
|
|
|
|
public:
|
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
Throw()
|
|
|
|
: Instruction(Type::Throw)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-09 16:18:56 +00:00
|
|
|
};
|
|
|
|
|
2021-06-10 13:04:38 +00:00
|
|
|
class EnterUnwindContext final : public Instruction {
|
|
|
|
public:
|
2021-06-13 16:09:40 +00:00
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
EnterUnwindContext(Label entry_point, Optional<Label> handler_target, Optional<Label> finalizer_target)
|
2021-06-10 13:04:38 +00:00
|
|
|
: Instruction(Type::EnterUnwindContext)
|
2021-06-13 16:09:40 +00:00
|
|
|
, m_entry_point(move(entry_point))
|
2021-06-12 09:22:46 +00:00
|
|
|
, m_handler_target(move(handler_target))
|
|
|
|
, m_finalizer_target(move(finalizer_target))
|
2021-06-10 13:04:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&);
|
|
|
|
|
|
|
|
auto& entry_point() const { return m_entry_point; }
|
|
|
|
auto& handler_target() const { return m_handler_target; }
|
|
|
|
auto& finalizer_target() const { return m_finalizer_target; }
|
2021-06-10 13:04:38 +00:00
|
|
|
|
|
|
|
private:
|
2021-06-13 16:09:40 +00:00
|
|
|
Label m_entry_point;
|
2021-06-10 13:04:38 +00:00
|
|
|
Optional<Label> m_handler_target;
|
|
|
|
Optional<Label> m_finalizer_target;
|
|
|
|
};
|
|
|
|
|
2022-02-12 16:18:45 +00:00
|
|
|
class LeaveEnvironment final : public Instruction {
|
|
|
|
public:
|
|
|
|
LeaveEnvironment(EnvironmentMode mode)
|
|
|
|
: Instruction(Type::LeaveEnvironment)
|
|
|
|
, m_mode(mode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
EnvironmentMode m_mode { EnvironmentMode::Lexical };
|
|
|
|
};
|
|
|
|
|
2021-06-10 13:04:38 +00:00
|
|
|
class LeaveUnwindContext final : public Instruction {
|
|
|
|
public:
|
|
|
|
LeaveUnwindContext()
|
|
|
|
: Instruction(Type::LeaveUnwindContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-10 13:04:38 +00:00
|
|
|
};
|
|
|
|
|
2021-11-10 18:52:26 +00:00
|
|
|
class FinishUnwind final : public Instruction {
|
|
|
|
public:
|
|
|
|
FinishUnwind(Label next)
|
|
|
|
: Instruction(Type::FinishUnwind)
|
|
|
|
, m_next_target(move(next))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-11-10 18:52:26 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Label m_next_target;
|
|
|
|
};
|
|
|
|
|
2021-06-10 13:04:38 +00:00
|
|
|
class ContinuePendingUnwind final : public Instruction {
|
|
|
|
public:
|
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
2021-06-12 09:22:46 +00:00
|
|
|
explicit ContinuePendingUnwind(Label resume_target)
|
2021-06-10 13:04:38 +00:00
|
|
|
: Instruction(Type::ContinuePendingUnwind)
|
|
|
|
, m_resume_target(resume_target)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&);
|
|
|
|
|
|
|
|
auto& resume_target() const { return m_resume_target; }
|
2021-06-10 13:04:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Label m_resume_target;
|
|
|
|
};
|
2021-06-10 20:12:21 +00:00
|
|
|
|
2021-06-10 21:08:30 +00:00
|
|
|
class Yield final : public Instruction {
|
|
|
|
public:
|
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
explicit Yield(Label continuation_label)
|
|
|
|
: Instruction(Type::Yield)
|
|
|
|
, m_continuation_label(continuation_label)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit Yield(std::nullptr_t)
|
|
|
|
: Instruction(Type::Yield)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&);
|
|
|
|
|
|
|
|
auto& continuation() const { return m_continuation_label; }
|
2021-06-10 21:08:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Optional<Label> m_continuation_label;
|
|
|
|
};
|
|
|
|
|
2021-07-01 10:24:46 +00:00
|
|
|
class PushDeclarativeEnvironment final : public Instruction {
|
2021-06-10 20:12:21 +00:00
|
|
|
public:
|
2021-07-01 10:24:46 +00:00
|
|
|
explicit PushDeclarativeEnvironment(HashMap<u32, Variable> variables)
|
|
|
|
: Instruction(Type::PushDeclarativeEnvironment)
|
2021-06-10 20:12:21 +00:00
|
|
|
, m_variables(move(variables))
|
|
|
|
{
|
|
|
|
}
|
2021-06-13 20:40:48 +00:00
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-15 13:38:12 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 16:10:20 +00:00
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
2021-06-10 20:12:21 +00:00
|
|
|
|
2021-06-10 21:08:30 +00:00
|
|
|
private:
|
2021-06-10 20:12:21 +00:00
|
|
|
HashMap<u32, Variable> m_variables;
|
|
|
|
};
|
2021-06-14 07:37:35 +00:00
|
|
|
|
2021-06-13 20:40:48 +00:00
|
|
|
class GetIterator final : public Instruction {
|
|
|
|
public:
|
|
|
|
GetIterator()
|
|
|
|
: Instruction(Type::GetIterator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-13 20:40:48 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
2022-03-18 16:48:19 +00:00
|
|
|
class GetObjectPropertyIterator final : public Instruction {
|
|
|
|
public:
|
|
|
|
GetObjectPropertyIterator()
|
|
|
|
: Instruction(Type::GetObjectPropertyIterator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
2021-06-13 20:40:48 +00:00
|
|
|
class IteratorNext final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorNext()
|
|
|
|
: Instruction(Type::IteratorNext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-13 20:40:48 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
class IteratorResultDone final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorResultDone()
|
|
|
|
: Instruction(Type::IteratorResultDone)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-13 20:40:48 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
class IteratorResultValue final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorResultValue()
|
|
|
|
: Instruction(Type::IteratorResultValue)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-06-13 20:40:48 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
2021-10-24 12:43:00 +00:00
|
|
|
class ResolveThisBinding final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit ResolveThisBinding()
|
|
|
|
: Instruction(Type::ResolveThisBinding)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2021-10-24 12:43:00 +00:00
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
2022-03-19 19:40:21 +00:00
|
|
|
class GetNewTarget final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit GetNewTarget()
|
|
|
|
: Instruction(Type::GetNewTarget)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
};
|
|
|
|
|
2022-06-11 22:12:22 +00:00
|
|
|
class TypeofVariable final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit TypeofVariable(IdentifierTableIndex identifier)
|
|
|
|
: Instruction(Type::TypeofVariable)
|
|
|
|
, m_identifier(identifier)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
String to_string_impl(Bytecode::Executable const&) const;
|
|
|
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_identifier;
|
|
|
|
};
|
|
|
|
|
2021-06-03 08:46:30 +00:00
|
|
|
}
|
2021-06-09 07:19:34 +00:00
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
2022-02-07 13:36:45 +00:00
|
|
|
ALWAYS_INLINE ThrowCompletionOr<void> Instruction::execute(Bytecode::Interpreter& interpreter) const
|
2021-06-09 07:19:34 +00:00
|
|
|
{
|
|
|
|
#define __BYTECODE_OP(op) \
|
|
|
|
case Instruction::Type::op: \
|
2021-06-15 13:38:12 +00:00
|
|
|
return static_cast<Bytecode::Op::op const&>(*this).execute_impl(interpreter);
|
2021-06-09 07:19:34 +00:00
|
|
|
|
|
|
|
switch (type()) {
|
|
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef __BYTECODE_OP
|
|
|
|
}
|
|
|
|
|
2021-06-13 16:10:20 +00:00
|
|
|
ALWAYS_INLINE void Instruction::replace_references(BasicBlock const& from, BasicBlock const& to)
|
|
|
|
{
|
|
|
|
#define __BYTECODE_OP(op) \
|
|
|
|
case Instruction::Type::op: \
|
|
|
|
return static_cast<Bytecode::Op::op&>(*this).replace_references_impl(from, to);
|
|
|
|
|
|
|
|
switch (type()) {
|
|
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef __BYTECODE_OP
|
|
|
|
}
|
|
|
|
|
2021-06-09 07:23:38 +00:00
|
|
|
ALWAYS_INLINE size_t Instruction::length() const
|
|
|
|
{
|
2022-08-30 16:03:02 +00:00
|
|
|
if (type() == Type::NewArray)
|
2022-09-09 14:47:42 +00:00
|
|
|
return round_up_to_power_of_two(static_cast<Op::NewArray const&>(*this).length_impl(), alignof(void*));
|
2022-08-30 16:03:02 +00:00
|
|
|
if (type() == Type::CopyObjectExcludingProperties)
|
2022-09-09 14:47:42 +00:00
|
|
|
return round_up_to_power_of_two(static_cast<Op::CopyObjectExcludingProperties const&>(*this).length_impl(), alignof(void*));
|
2021-06-09 07:23:38 +00:00
|
|
|
|
|
|
|
#define __BYTECODE_OP(op) \
|
|
|
|
case Type::op: \
|
|
|
|
return sizeof(Op::op);
|
|
|
|
|
|
|
|
switch (type()) {
|
|
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
#undef __BYTECODE_OP
|
|
|
|
}
|
|
|
|
|
2021-06-13 16:10:20 +00:00
|
|
|
ALWAYS_INLINE bool Instruction::is_terminator() const
|
|
|
|
{
|
|
|
|
#define __BYTECODE_OP(op) \
|
|
|
|
case Type::op: \
|
|
|
|
return Op::op::IsTerminator;
|
|
|
|
|
|
|
|
switch (type()) {
|
|
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
#undef __BYTECODE_OP
|
|
|
|
}
|
|
|
|
|
2021-06-09 07:19:34 +00:00
|
|
|
}
|