2021-06-03 10:46:30 +02:00
|
|
|
/*
|
2023-06-24 15:22:16 +02:00
|
|
|
* Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org>
|
2021-06-07 21:13:37 +01:00
|
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
2021-06-09 18:18:56 +02:00
|
|
|
* Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org>
|
2021-06-03 10:46:30 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-09-09 16:47:42 +02:00
|
|
|
#include <AK/StdLibExtras.h>
|
2021-06-08 07:59:25 +02:00
|
|
|
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
2021-10-24 15:34:30 +02:00
|
|
|
#include <LibJS/Bytecode/IdentifierTable.h>
|
2021-06-03 10:46:30 +02:00
|
|
|
#include <LibJS/Bytecode/Instruction.h>
|
2021-06-04 12:07:38 +02:00
|
|
|
#include <LibJS/Bytecode/Label.h>
|
2023-07-13 10:49:07 +02:00
|
|
|
#include <LibJS/Bytecode/RegexTable.h>
|
2021-06-03 10:46:30 +02:00
|
|
|
#include <LibJS/Bytecode/Register.h>
|
2021-06-09 10:02:01 +02:00
|
|
|
#include <LibJS/Bytecode/StringTable.h>
|
2021-06-03 10:46:30 +02:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2021-07-01 12:24:46 +02:00
|
|
|
#include <LibJS/Runtime/Environment.h>
|
2023-07-19 06:54:48 -04:00
|
|
|
#include <LibJS/Runtime/Iterator.h>
|
2021-06-03 10:46:30 +02:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
2022-02-12 00:48:23 -08:00
|
|
|
#include <LibJS/Runtime/ValueTraits.h>
|
2021-06-03 10:46:30 +02:00
|
|
|
|
2023-06-23 14:27:42 +02:00
|
|
|
namespace JS {
|
|
|
|
class FunctionExpression;
|
|
|
|
}
|
|
|
|
|
2021-06-03 10:46:30 +02:00
|
|
|
namespace JS::Bytecode::Op {
|
|
|
|
|
|
|
|
class Load final : public Instruction {
|
|
|
|
public:
|
2021-06-12 11:22:46 +02:00
|
|
|
explicit Load(Register src)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Load, sizeof(*this))
|
2021-06-07 20:58:36 -07:00
|
|
|
, m_src(src)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-07 20:58:36 -07:00
|
|
|
|
2023-09-27 10:31:07 +02:00
|
|
|
Register src() const { return m_src; }
|
|
|
|
|
2021-06-07 20:58:36 -07:00
|
|
|
private:
|
|
|
|
Register m_src;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LoadImmediate final : public Instruction {
|
|
|
|
public:
|
2021-06-12 11:22:46 +02:00
|
|
|
explicit LoadImmediate(Value value)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::LoadImmediate, sizeof(*this))
|
2021-06-03 10:46:30 +02:00
|
|
|
, m_value(value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-03 10:46:30 +02:00
|
|
|
|
2023-09-27 10:31:07 +02:00
|
|
|
Value value() const { return m_value; }
|
|
|
|
|
2021-06-03 10:46:30 +02:00
|
|
|
private:
|
|
|
|
Value m_value;
|
|
|
|
};
|
|
|
|
|
2021-06-07 20:58:36 -07:00
|
|
|
class Store final : public Instruction {
|
2021-06-07 22:05:09 +02:00
|
|
|
public:
|
2021-06-12 11:22:46 +02:00
|
|
|
explicit Store(Register dst)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Store, sizeof(*this))
|
2021-06-07 22:05:09 +02:00
|
|
|
, m_dst(dst)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-07 22:05:09 +02:00
|
|
|
|
2022-10-22 20:21:08 +02:00
|
|
|
Register dst() const { return m_dst; }
|
|
|
|
|
2021-06-07 22:05:09 +02:00
|
|
|
private:
|
|
|
|
Register m_dst;
|
|
|
|
};
|
|
|
|
|
2021-06-07 23:08:35 +02: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-24 00:06:10 +02:00
|
|
|
O(LooselyInequals, abstract_inequals) \
|
|
|
|
O(LooselyEquals, abstract_equals) \
|
|
|
|
O(StrictlyInequals, typed_inequals) \
|
|
|
|
O(StrictlyEquals, typed_equals) \
|
2021-06-07 23:08:35 +02: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)
|
|
|
|
|
2022-12-06 01:12:49 +00:00
|
|
|
#define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
|
|
|
|
class OpTitleCase final : public Instruction { \
|
|
|
|
public: \
|
|
|
|
explicit OpTitleCase(Register lhs_reg) \
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::OpTitleCase, sizeof(*this)) \
|
2022-12-06 01:12:49 +00:00
|
|
|
, m_lhs_reg(lhs_reg) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
|
|
|
|
\
|
2023-10-14 14:37:48 +02:00
|
|
|
Register lhs() const { return m_lhs_reg; } \
|
|
|
|
\
|
2022-12-06 01:12:49 +00:00
|
|
|
private: \
|
|
|
|
Register m_lhs_reg; \
|
2021-06-07 23:08:35 +02: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_)
|
|
|
|
|
2022-12-06 01:12:49 +00:00
|
|
|
#define JS_DECLARE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
|
|
|
|
class OpTitleCase final : public Instruction { \
|
|
|
|
public: \
|
|
|
|
OpTitleCase() \
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::OpTitleCase, sizeof(*this)) \
|
2022-12-06 01:12:49 +00:00
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
|
2021-06-07 23:08:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_ENUMERATE_COMMON_UNARY_OPS(JS_DECLARE_COMMON_UNARY_OP)
|
|
|
|
#undef JS_DECLARE_COMMON_UNARY_OP
|
2021-06-07 19:53:47 +01:00
|
|
|
|
2021-06-03 18:26:32 +02:00
|
|
|
class NewString final : public Instruction {
|
|
|
|
public:
|
2021-06-12 11:22:46 +02:00
|
|
|
explicit NewString(StringTableIndex string)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::NewString, sizeof(*this))
|
2021-06-12 11:22:46 +02:00
|
|
|
, m_string(string)
|
2021-06-03 18:26:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-03 18:26:32 +02:00
|
|
|
|
2023-10-18 12:55:00 +02:00
|
|
|
StringTableIndex index() const { return m_string; }
|
|
|
|
|
2021-06-03 18:26:32 +02:00
|
|
|
private:
|
2021-06-09 10:02:01 +02:00
|
|
|
StringTableIndex m_string;
|
2021-06-03 18:26:32 +02:00
|
|
|
};
|
|
|
|
|
2021-06-04 20:30:23 +02:00
|
|
|
class NewObject final : public Instruction {
|
|
|
|
public:
|
2021-06-07 20:58:36 -07:00
|
|
|
NewObject()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::NewObject, sizeof(*this))
|
2021-06-04 20:30:23 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-04 20:30:23 +02:00
|
|
|
};
|
|
|
|
|
2021-06-19 17:17:40 -07:00
|
|
|
class NewRegExp final : public Instruction {
|
|
|
|
public:
|
2023-07-13 10:49:07 +02:00
|
|
|
NewRegExp(StringTableIndex source_index, StringTableIndex flags_index, RegexTableIndex regex_index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::NewRegExp, sizeof(*this))
|
2021-06-19 17:17:40 -07:00
|
|
|
, m_source_index(source_index)
|
|
|
|
, m_flags_index(flags_index)
|
2023-07-13 10:49:07 +02:00
|
|
|
, m_regex_index(regex_index)
|
2021-06-19 17:17:40 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-19 17:17:40 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
StringTableIndex m_source_index;
|
|
|
|
StringTableIndex m_flags_index;
|
2023-07-13 10:49:07 +02:00
|
|
|
RegexTableIndex m_regex_index;
|
2021-06-19 17:17:40 -07:00
|
|
|
};
|
|
|
|
|
2022-12-09 18:48:57 +00:00
|
|
|
#define JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(O) \
|
|
|
|
O(TypeError)
|
|
|
|
|
|
|
|
#define JS_DECLARE_NEW_BUILTIN_ERROR_OP(ErrorName) \
|
|
|
|
class New##ErrorName final : public Instruction { \
|
|
|
|
public: \
|
|
|
|
explicit New##ErrorName(StringTableIndex error_string) \
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::New##ErrorName, sizeof(*this)) \
|
2022-12-09 18:48:57 +00:00
|
|
|
, m_error_string(error_string) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
StringTableIndex m_error_string; \
|
|
|
|
};
|
|
|
|
|
|
|
|
JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DECLARE_NEW_BUILTIN_ERROR_OP)
|
|
|
|
#undef JS_DECLARE_NEW_BUILTIN_ERROR_OP
|
|
|
|
|
2021-06-13 15:30:32 -07: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)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::CopyObjectExcludingProperties, length_impl(excluded_names.size()))
|
2021-06-13 15:30:32 -07:00
|
|
|
, 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 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 15:30:32 -07:00
|
|
|
|
2023-09-13 21:32:51 +02:00
|
|
|
size_t length_impl(size_t excluded_names_count) const
|
|
|
|
{
|
|
|
|
return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Register) * excluded_names_count);
|
|
|
|
}
|
2021-06-13 15:30:32 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_from_object;
|
|
|
|
size_t m_excluded_names_count { 0 };
|
|
|
|
Register m_excluded_names[];
|
|
|
|
};
|
|
|
|
|
2021-06-08 07:59:25 +02:00
|
|
|
class NewBigInt final : public Instruction {
|
|
|
|
public:
|
2021-06-07 20:58:36 -07:00
|
|
|
explicit NewBigInt(Crypto::SignedBigInteger bigint)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::NewBigInt, sizeof(*this))
|
2021-06-08 07:59:25 +02:00
|
|
|
, m_bigint(move(bigint))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-08 07:59:25 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Crypto::SignedBigInteger m_bigint;
|
|
|
|
};
|
|
|
|
|
2021-06-08 23:06:52 +02:00
|
|
|
// NOTE: This instruction is variable-width depending on the number of elements!
|
|
|
|
class NewArray final : public Instruction {
|
|
|
|
public:
|
2021-06-13 14:06:26 -07:00
|
|
|
NewArray()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::NewArray, length_impl(0))
|
2021-06-13 14:06:26 -07:00
|
|
|
, m_element_count(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:48:42 +00:00
|
|
|
explicit NewArray(AK::Array<Register, 2> const& elements_range)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::NewArray, length_impl(elements_range[1].index() - elements_range[0].index() + 1))
|
2022-03-14 14:48:42 +00:00
|
|
|
, m_element_count(elements_range[1].index() - elements_range[0].index() + 1)
|
2021-06-08 23:06:52 +02:00
|
|
|
{
|
2022-03-14 14:48:42 +00:00
|
|
|
m_elements[0] = elements_range[0];
|
|
|
|
m_elements[1] = elements_range[1];
|
2021-06-08 23:06:52 +02:00
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-08 23:06:52 +02:00
|
|
|
|
2023-09-13 21:32:51 +02:00
|
|
|
size_t length_impl(size_t element_count) const
|
2021-06-13 20:40:20 +04:30
|
|
|
{
|
2023-09-13 21:32:51 +02:00
|
|
|
return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Register) * (element_count == 0 ? 0 : 2));
|
2021-06-13 20:40:20 +04:30
|
|
|
}
|
2021-06-12 05:49:09 +02:00
|
|
|
|
2022-10-22 20:21:08 +02:00
|
|
|
Register start() const
|
|
|
|
{
|
|
|
|
VERIFY(m_element_count);
|
|
|
|
return m_elements[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
Register end() const
|
|
|
|
{
|
|
|
|
VERIFY(m_element_count);
|
|
|
|
return m_elements[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t element_count() const { return m_element_count; }
|
|
|
|
|
2021-06-08 23:06:52 +02:00
|
|
|
private:
|
|
|
|
size_t m_element_count { 0 };
|
|
|
|
Register m_elements[];
|
|
|
|
};
|
|
|
|
|
2022-09-09 15:23:02 +02:00
|
|
|
class Append final : public Instruction {
|
|
|
|
public:
|
|
|
|
Append(Register lhs, bool is_spread)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Append, sizeof(*this))
|
2022-09-09 15:23:02 +02:00
|
|
|
, m_lhs(lhs)
|
|
|
|
, m_is_spread(is_spread)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-10-22 20:19:16 +02:00
|
|
|
|
2022-09-09 15:23:02 +02:00
|
|
|
private:
|
|
|
|
Register m_lhs;
|
|
|
|
bool m_is_spread = false;
|
|
|
|
};
|
|
|
|
|
2023-06-24 15:22:16 +02:00
|
|
|
class ImportCall final : public Instruction {
|
|
|
|
public:
|
|
|
|
ImportCall(Register specifier, Register options)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ImportCall, sizeof(*this))
|
2023-06-24 15:22:16 +02:00
|
|
|
, m_specifier(specifier)
|
|
|
|
, m_options(options)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_specifier;
|
|
|
|
Register m_options;
|
|
|
|
};
|
|
|
|
|
2021-06-13 14:06:26 -07:00
|
|
|
class IteratorToArray final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorToArray()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::IteratorToArray, sizeof(*this))
|
2021-06-13 14:06:26 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 14:06:26 -07:00
|
|
|
};
|
|
|
|
|
2021-06-07 20:58:36 -07:00
|
|
|
class ConcatString final : public Instruction {
|
|
|
|
public:
|
2021-06-12 11:22:46 +02:00
|
|
|
explicit ConcatString(Register lhs)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ConcatString, sizeof(*this))
|
2021-06-07 20:58:36 -07:00
|
|
|
, m_lhs(lhs)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-07 20:58:36 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_lhs;
|
|
|
|
};
|
|
|
|
|
2022-02-12 19:48:45 +03:30
|
|
|
enum class EnvironmentMode {
|
|
|
|
Lexical,
|
|
|
|
Var,
|
|
|
|
};
|
|
|
|
|
2023-06-16 16:43:24 +02:00
|
|
|
class CreateLexicalEnvironment final : public Instruction {
|
2022-02-12 19:48:45 +03:30
|
|
|
public:
|
2023-06-16 16:43:24 +02:00
|
|
|
explicit CreateLexicalEnvironment()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::CreateLexicalEnvironment, sizeof(*this))
|
2022-02-12 19:48:45 +03:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-02-12 19:48:45 +03:30
|
|
|
};
|
|
|
|
|
2022-03-13 16:01:18 +03:30
|
|
|
class EnterObjectEnvironment final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit EnterObjectEnvironment()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::EnterObjectEnvironment, sizeof(*this))
|
2022-03-13 16:01:18 +03:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-03-13 16:01:18 +03:30
|
|
|
};
|
|
|
|
|
2022-02-12 19:48:45 +03:30
|
|
|
class CreateVariable final : public Instruction {
|
|
|
|
public:
|
2023-09-17 21:53:48 +12:00
|
|
|
explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false, bool is_strict = false)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::CreateVariable, sizeof(*this))
|
2022-02-12 19:48:45 +03:30
|
|
|
, m_identifier(identifier)
|
|
|
|
, m_mode(mode)
|
|
|
|
, m_is_immutable(is_immutable)
|
2022-07-17 19:06:44 +01:00
|
|
|
, m_is_global(is_global)
|
2023-09-17 21:53:48 +12:00
|
|
|
, m_is_strict(is_strict)
|
2022-02-12 19:48:45 +03:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-02-12 19:48:45 +03:30
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_identifier;
|
|
|
|
EnvironmentMode m_mode;
|
2022-07-17 19:06:44 +01:00
|
|
|
bool m_is_immutable : 4 { false };
|
|
|
|
bool m_is_global : 4 { false };
|
2023-09-17 21:53:48 +12:00
|
|
|
bool m_is_strict { false };
|
2022-02-12 19:48:45 +03:30
|
|
|
};
|
|
|
|
|
2021-06-03 18:26:32 +02:00
|
|
|
class SetVariable final : public Instruction {
|
|
|
|
public:
|
2022-02-12 19:48:45 +03:30
|
|
|
enum class InitializationMode {
|
|
|
|
Initialize,
|
|
|
|
Set,
|
|
|
|
};
|
|
|
|
explicit SetVariable(IdentifierTableIndex identifier, InitializationMode initialization_mode = InitializationMode::Set, EnvironmentMode mode = EnvironmentMode::Lexical)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::SetVariable, sizeof(*this))
|
2021-06-12 11:22:46 +02:00
|
|
|
, m_identifier(identifier)
|
2022-02-12 19:48:45 +03:30
|
|
|
, m_mode(mode)
|
|
|
|
, m_initialization_mode(initialization_mode)
|
2021-06-03 18:26:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-03 18:26:32 +02:00
|
|
|
|
2022-10-22 20:21:08 +02:00
|
|
|
IdentifierTableIndex identifier() const { return m_identifier; }
|
|
|
|
|
2021-06-03 18:26:32 +02:00
|
|
|
private:
|
2021-10-24 15:34:30 +02:00
|
|
|
IdentifierTableIndex m_identifier;
|
2022-02-12 19:48:45 +03:30
|
|
|
EnvironmentMode m_mode;
|
|
|
|
InitializationMode m_initialization_mode { InitializationMode::Set };
|
2021-06-03 18:26:32 +02:00
|
|
|
};
|
|
|
|
|
2023-07-05 02:17:10 +02:00
|
|
|
class SetLocal final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit SetLocal(size_t index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::SetLocal, sizeof(*this))
|
2023-07-05 02:17:10 +02:00
|
|
|
, m_index(index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
size_t index() const { return m_index; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t m_index;
|
|
|
|
};
|
|
|
|
|
2023-08-01 14:33:58 +02:00
|
|
|
class GetCalleeAndThisFromEnvironment final : public Instruction {
|
|
|
|
public:
|
2023-10-26 10:39:40 +02:00
|
|
|
explicit GetCalleeAndThisFromEnvironment(IdentifierTableIndex identifier, Register callee_reg, Register this_reg, u32 cache_index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetCalleeAndThisFromEnvironment, sizeof(*this))
|
2023-08-01 14:33:58 +02:00
|
|
|
, m_identifier(identifier)
|
|
|
|
, m_callee_reg(callee_reg)
|
|
|
|
, m_this_reg(this_reg)
|
2023-10-26 10:39:40 +02:00
|
|
|
, m_cache_index(cache_index)
|
2023-08-01 14:33:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
IdentifierTableIndex identifier() const { return m_identifier; }
|
2023-10-26 10:39:40 +02:00
|
|
|
u32 cache_index() const { return m_cache_index; }
|
2023-08-01 14:33:58 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_identifier;
|
|
|
|
Register m_callee_reg;
|
|
|
|
Register m_this_reg;
|
2023-10-26 10:39:40 +02:00
|
|
|
u32 m_cache_index { 0 };
|
2023-08-01 14:33:58 +02:00
|
|
|
};
|
|
|
|
|
2021-06-03 18:26:32 +02:00
|
|
|
class GetVariable final : public Instruction {
|
|
|
|
public:
|
2023-10-26 10:39:40 +02:00
|
|
|
explicit GetVariable(IdentifierTableIndex identifier, u32 cache_index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetVariable, sizeof(*this))
|
2021-06-12 11:22:46 +02:00
|
|
|
, m_identifier(identifier)
|
2023-10-26 10:39:40 +02:00
|
|
|
, m_cache_index(cache_index)
|
2021-06-03 18:26:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-03 18:26:32 +02:00
|
|
|
|
2022-10-22 20:21:08 +02:00
|
|
|
IdentifierTableIndex identifier() const { return m_identifier; }
|
2023-10-26 10:39:40 +02:00
|
|
|
u32 cache_index() const { return m_cache_index; }
|
2022-10-22 20:21:08 +02:00
|
|
|
|
2021-06-03 18:26:32 +02:00
|
|
|
private:
|
2021-10-24 15:34:30 +02:00
|
|
|
IdentifierTableIndex m_identifier;
|
2023-10-26 10:39:40 +02:00
|
|
|
u32 m_cache_index { 0 };
|
2021-06-03 18:26:32 +02:00
|
|
|
};
|
|
|
|
|
2023-07-12 04:06:59 +02:00
|
|
|
class GetGlobal final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit GetGlobal(IdentifierTableIndex identifier, u32 cache_index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetGlobal, sizeof(*this))
|
2023-07-12 04:06:59 +02:00
|
|
|
, m_identifier(identifier)
|
|
|
|
, m_cache_index(cache_index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
2023-10-20 12:56:12 +02:00
|
|
|
IdentifierTableIndex identifier() const { return m_identifier; }
|
|
|
|
u32 cache_index() const { return m_cache_index; }
|
|
|
|
|
2023-07-12 04:06:59 +02:00
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_identifier;
|
|
|
|
u32 m_cache_index { 0 };
|
|
|
|
};
|
|
|
|
|
2023-07-05 02:17:10 +02:00
|
|
|
class GetLocal final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit GetLocal(size_t index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetLocal, sizeof(*this))
|
2023-07-05 02:17:10 +02:00
|
|
|
, m_index(index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
size_t index() const { return m_index; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t m_index;
|
|
|
|
};
|
|
|
|
|
2022-03-27 19:50:09 +01:00
|
|
|
class DeleteVariable final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit DeleteVariable(IdentifierTableIndex identifier)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::DeleteVariable, sizeof(*this))
|
2022-03-27 19:50:09 +01:00
|
|
|
, m_identifier(identifier)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-03-27 19:50:09 +01:00
|
|
|
|
2022-10-22 20:21:08 +02:00
|
|
|
IdentifierTableIndex identifier() const { return m_identifier; }
|
|
|
|
|
2022-03-27 19:50:09 +01:00
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_identifier;
|
|
|
|
};
|
|
|
|
|
2021-06-04 21:03:53 +02:00
|
|
|
class GetById final : public Instruction {
|
|
|
|
public:
|
2023-07-08 17:43:26 +02:00
|
|
|
GetById(IdentifierTableIndex property, u32 cache_index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetById, sizeof(*this))
|
2021-06-12 11:22:46 +02:00
|
|
|
, m_property(property)
|
2023-07-08 17:43:26 +02:00
|
|
|
, m_cache_index(cache_index)
|
2021-06-04 21:03:53 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-04 21:03:53 +02:00
|
|
|
|
2023-10-18 13:27:56 +02:00
|
|
|
IdentifierTableIndex property() const { return m_property; }
|
|
|
|
u32 cache_index() const { return m_cache_index; }
|
|
|
|
|
2021-06-04 21:03:53 +02:00
|
|
|
private:
|
2021-10-24 15:34:30 +02:00
|
|
|
IdentifierTableIndex m_property;
|
2023-07-08 17:43:26 +02:00
|
|
|
u32 m_cache_index { 0 };
|
2021-06-04 21:03:53 +02:00
|
|
|
};
|
|
|
|
|
2023-07-02 19:26:31 +01:00
|
|
|
class GetByIdWithThis final : public Instruction {
|
|
|
|
public:
|
2023-07-08 17:43:26 +02:00
|
|
|
GetByIdWithThis(IdentifierTableIndex property, Register this_value, u32 cache_index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetByIdWithThis, sizeof(*this))
|
2023-07-02 19:26:31 +01:00
|
|
|
, m_property(property)
|
|
|
|
, m_this_value(this_value)
|
2023-07-08 17:43:26 +02:00
|
|
|
, m_cache_index(cache_index)
|
2023-07-02 19:26:31 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
Register m_this_value;
|
2023-07-08 17:43:26 +02:00
|
|
|
u32 m_cache_index { 0 };
|
2023-07-02 19:26:31 +01:00
|
|
|
};
|
|
|
|
|
2023-06-23 08:16:17 +02:00
|
|
|
class GetPrivateById final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit GetPrivateById(IdentifierTableIndex property)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetPrivateById, sizeof(*this))
|
2023-06-23 08:16:17 +02:00
|
|
|
, m_property(property)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
};
|
|
|
|
|
2023-07-05 12:42:50 +02:00
|
|
|
class HasPrivateId final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit HasPrivateId(IdentifierTableIndex property)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::HasPrivateId, sizeof(*this))
|
2023-07-05 12:42:50 +02:00
|
|
|
, m_property(property)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
};
|
|
|
|
|
2022-03-31 00:59:58 +04:30
|
|
|
enum class PropertyKind {
|
|
|
|
Getter,
|
|
|
|
Setter,
|
|
|
|
KeyValue,
|
2023-07-10 08:44:28 +02:00
|
|
|
DirectKeyValue, // Used for Object expressions. Always sets an own property, never calls a setter.
|
2022-03-31 00:59:58 +04:30
|
|
|
Spread,
|
|
|
|
ProtoSetter,
|
|
|
|
};
|
|
|
|
|
2021-06-04 20:47:07 +02:00
|
|
|
class PutById final : public Instruction {
|
|
|
|
public:
|
2022-03-31 00:59:58 +04:30
|
|
|
explicit PutById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::PutById, sizeof(*this))
|
2021-06-07 15:12:43 +02:00
|
|
|
, m_base(base)
|
2021-06-12 11:22:46 +02:00
|
|
|
, m_property(property)
|
2022-03-31 00:59:58 +04:30
|
|
|
, m_kind(kind)
|
2021-06-04 20:47:07 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-06-23 08:16:17 +02:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
PropertyKind m_kind;
|
|
|
|
};
|
|
|
|
|
2023-07-02 19:26:31 +01:00
|
|
|
class PutByIdWithThis final : public Instruction {
|
|
|
|
public:
|
|
|
|
PutByIdWithThis(Register base, Register this_value, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::PutByIdWithThis, sizeof(*this))
|
2023-07-02 19:26:31 +01:00
|
|
|
, m_base(base)
|
|
|
|
, m_this_value(this_value)
|
|
|
|
, m_property(property)
|
|
|
|
, m_kind(kind)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
Register m_this_value;
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
PropertyKind m_kind;
|
|
|
|
};
|
|
|
|
|
2023-06-23 08:16:17 +02:00
|
|
|
class PutPrivateById final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit PutPrivateById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::PutPrivateById, sizeof(*this))
|
2023-06-23 08:16:17 +02:00
|
|
|
, m_base(base)
|
|
|
|
, m_property(property)
|
|
|
|
, m_kind(kind)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-04 20:47:07 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
2021-10-24 15:34:30 +02:00
|
|
|
IdentifierTableIndex m_property;
|
2022-03-31 00:59:58 +04:30
|
|
|
PropertyKind m_kind;
|
2021-06-04 20:47:07 +02:00
|
|
|
};
|
|
|
|
|
2022-03-27 19:50:09 +01:00
|
|
|
class DeleteById final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit DeleteById(IdentifierTableIndex property)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::DeleteById, sizeof(*this))
|
2022-03-27 19:50:09 +01:00
|
|
|
, m_property(property)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-03-27 19:50:09 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
};
|
|
|
|
|
2023-07-06 17:10:40 -04:00
|
|
|
class DeleteByIdWithThis final : public Instruction {
|
|
|
|
public:
|
|
|
|
DeleteByIdWithThis(Register this_value, IdentifierTableIndex property)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::DeleteByIdWithThis, sizeof(*this))
|
2023-07-06 17:10:40 -04:00
|
|
|
, m_this_value(this_value)
|
|
|
|
, m_property(property)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_this_value;
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
};
|
|
|
|
|
2021-06-11 00:35:25 +02:00
|
|
|
class GetByValue final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit GetByValue(Register base)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetByValue, sizeof(*this))
|
2021-06-11 00:35:25 +02:00
|
|
|
, m_base(base)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-11 00:35:25 +02:00
|
|
|
|
2023-10-20 12:38:43 +02:00
|
|
|
Register base() const { return m_base; }
|
|
|
|
|
2021-06-11 00:35:25 +02:00
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
};
|
|
|
|
|
2023-07-02 19:26:31 +01:00
|
|
|
class GetByValueWithThis final : public Instruction {
|
|
|
|
public:
|
|
|
|
GetByValueWithThis(Register base, Register this_value)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetByValueWithThis, sizeof(*this))
|
2023-07-02 19:26:31 +01:00
|
|
|
, m_base(base)
|
|
|
|
, m_this_value(this_value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
Register m_this_value;
|
|
|
|
};
|
|
|
|
|
2021-06-11 00:35:25 +02:00
|
|
|
class PutByValue final : public Instruction {
|
|
|
|
public:
|
2022-03-31 00:59:58 +04:30
|
|
|
PutByValue(Register base, Register property, PropertyKind kind = PropertyKind::KeyValue)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::PutByValue, sizeof(*this))
|
2021-06-11 00:35:25 +02:00
|
|
|
, m_base(base)
|
|
|
|
, m_property(property)
|
2022-03-31 00:59:58 +04:30
|
|
|
, m_kind(kind)
|
2021-06-11 00:35:25 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2023-07-02 19:26:31 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
Register m_property;
|
|
|
|
PropertyKind m_kind;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PutByValueWithThis final : public Instruction {
|
|
|
|
public:
|
|
|
|
PutByValueWithThis(Register base, Register property, Register this_value, PropertyKind kind = PropertyKind::KeyValue)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::PutByValueWithThis, sizeof(*this))
|
2023-07-02 19:26:31 +01:00
|
|
|
, m_base(base)
|
|
|
|
, m_property(property)
|
|
|
|
, m_this_value(this_value)
|
|
|
|
, m_kind(kind)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-11 00:35:25 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
Register m_property;
|
2023-07-02 19:26:31 +01:00
|
|
|
Register m_this_value;
|
2022-03-31 00:59:58 +04:30
|
|
|
PropertyKind m_kind;
|
2021-06-11 00:35:25 +02:00
|
|
|
};
|
|
|
|
|
2022-03-27 19:50:09 +01:00
|
|
|
class DeleteByValue final : public Instruction {
|
|
|
|
public:
|
|
|
|
DeleteByValue(Register base)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::DeleteByValue, sizeof(*this))
|
2022-03-27 19:50:09 +01:00
|
|
|
, m_base(base)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-03-27 19:50:09 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
};
|
|
|
|
|
2023-07-06 17:10:40 -04:00
|
|
|
class DeleteByValueWithThis final : public Instruction {
|
|
|
|
public:
|
|
|
|
DeleteByValueWithThis(Register base, Register this_value)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::DeleteByValueWithThis, sizeof(*this))
|
2023-07-06 17:10:40 -04:00
|
|
|
, m_base(base)
|
|
|
|
, m_this_value(this_value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_base;
|
|
|
|
Register m_this_value;
|
|
|
|
};
|
|
|
|
|
2021-06-08 11:28:27 +02:00
|
|
|
class Jump : public Instruction {
|
2021-06-04 12:07:38 +02:00
|
|
|
public:
|
2021-06-09 06:49:58 +04:30
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
2023-09-28 12:43:11 +02:00
|
|
|
explicit Jump(Type type, Label taken_target, Optional<Label> nontaken_target = {})
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(type, sizeof(*this))
|
2021-06-09 06:49:58 +04:30
|
|
|
, m_true_target(move(taken_target))
|
|
|
|
, m_false_target(move(nontaken_target))
|
2021-06-08 11:28:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-09-28 12:43:11 +02:00
|
|
|
explicit Jump(Label taken_target, Optional<Label> nontaken_target = {})
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Jump, sizeof(*this))
|
2021-06-09 06:49:58 +04:30
|
|
|
, m_true_target(move(taken_target))
|
|
|
|
, m_false_target(move(nontaken_target))
|
2021-06-04 12:07:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 20:40:20 +04:30
|
|
|
|
|
|
|
auto& true_target() const { return m_true_target; }
|
|
|
|
auto& false_target() const { return m_false_target; }
|
2021-06-09 06:49:58 +04:30
|
|
|
|
|
|
|
protected:
|
|
|
|
Optional<Label> m_true_target;
|
|
|
|
Optional<Label> m_false_target;
|
2021-06-04 12:07:38 +02:00
|
|
|
};
|
|
|
|
|
2021-06-09 06:49:58 +04:30
|
|
|
class JumpConditional final : public Jump {
|
2021-06-04 12:20:44 +02:00
|
|
|
public:
|
2023-09-28 12:43:11 +02:00
|
|
|
explicit JumpConditional(Label true_target, Label false_target)
|
2021-06-09 06:49:58 +04:30
|
|
|
: Jump(Type::JumpConditional, move(true_target), move(false_target))
|
2021-06-04 12:20:44 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-04 12:20:44 +02:00
|
|
|
};
|
|
|
|
|
2021-06-09 06:49:58 +04:30
|
|
|
class JumpNullish final : public Jump {
|
2021-06-08 02:18:47 +02:00
|
|
|
public:
|
2023-09-28 12:43:11 +02:00
|
|
|
explicit JumpNullish(Label true_target, Label false_target)
|
2021-06-09 06:49:58 +04:30
|
|
|
: Jump(Type::JumpNullish, move(true_target), move(false_target))
|
2021-06-08 02:18:47 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-08 02:18:47 +02:00
|
|
|
};
|
|
|
|
|
2021-06-13 12:24:40 -07:00
|
|
|
class JumpUndefined final : public Jump {
|
|
|
|
public:
|
2023-09-28 12:43:11 +02:00
|
|
|
explicit JumpUndefined(Label true_target, Label false_target)
|
2021-06-13 12:24:40 -07:00
|
|
|
: Jump(Type::JumpUndefined, move(true_target), move(false_target))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 12:24:40 -07:00
|
|
|
};
|
|
|
|
|
2023-07-02 15:59:54 +02:00
|
|
|
enum class CallType {
|
|
|
|
Call,
|
|
|
|
Construct,
|
|
|
|
DirectEval,
|
|
|
|
};
|
2021-06-10 23:01:49 +02:00
|
|
|
|
2023-07-02 16:33:00 +02:00
|
|
|
class Call final : public Instruction {
|
|
|
|
public:
|
|
|
|
Call(CallType type, Register callee, Register this_value, Register first_argument, u32 argument_count, Optional<StringTableIndex> expression_string = {})
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Call, sizeof(*this))
|
2023-07-02 16:33:00 +02:00
|
|
|
, m_callee(callee)
|
|
|
|
, m_this_value(this_value)
|
|
|
|
, m_first_argument(first_argument)
|
|
|
|
, m_argument_count(argument_count)
|
|
|
|
, m_type(type)
|
|
|
|
, m_expression_string(expression_string)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CallType call_type() const { return m_type; }
|
|
|
|
Register callee() const { return m_callee; }
|
|
|
|
Register this_value() const { return m_this_value; }
|
|
|
|
Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
|
|
|
|
|
2023-07-03 15:15:24 +02:00
|
|
|
Register first_argument() const { return m_first_argument; }
|
|
|
|
u32 argument_count() const { return m_argument_count; }
|
|
|
|
|
2023-07-02 16:33:00 +02:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register m_callee;
|
|
|
|
Register m_this_value;
|
|
|
|
Register m_first_argument;
|
|
|
|
u32 m_argument_count { 0 };
|
|
|
|
CallType m_type;
|
|
|
|
Optional<StringTableIndex> m_expression_string;
|
|
|
|
};
|
|
|
|
|
2023-07-02 15:59:54 +02:00
|
|
|
class CallWithArgumentArray final : public Instruction {
|
|
|
|
public:
|
|
|
|
CallWithArgumentArray(CallType type, Register callee, Register this_value, Optional<StringTableIndex> expression_string = {})
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::CallWithArgumentArray, sizeof(*this))
|
2021-06-05 15:15:30 +02:00
|
|
|
, m_callee(callee)
|
|
|
|
, m_this_value(this_value)
|
2021-06-10 23:01:49 +02:00
|
|
|
, m_type(type)
|
2022-10-01 01:36:06 +02:00
|
|
|
, m_expression_string(expression_string)
|
2021-06-05 15:15:30 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-02 16:33:00 +02:00
|
|
|
CallType call_type() const { return m_type; }
|
|
|
|
Register callee() const { return m_callee; }
|
|
|
|
Register this_value() const { return m_this_value; }
|
|
|
|
Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-07 15:12:43 +02:00
|
|
|
|
2021-06-05 15:15:30 +02:00
|
|
|
private:
|
|
|
|
Register m_callee;
|
|
|
|
Register m_this_value;
|
2021-06-10 23:01:49 +02:00
|
|
|
CallType m_type;
|
2022-10-01 01:36:06 +02:00
|
|
|
Optional<StringTableIndex> m_expression_string;
|
2021-06-05 15:15:30 +02:00
|
|
|
};
|
|
|
|
|
2023-07-02 15:59:54 +02:00
|
|
|
class SuperCallWithArgumentArray : public Instruction {
|
2022-08-30 18:03:02 +02:00
|
|
|
public:
|
2023-07-02 15:59:54 +02:00
|
|
|
explicit SuperCallWithArgumentArray(bool is_synthetic)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::SuperCallWithArgumentArray, sizeof(*this))
|
2022-08-30 18:03:02 +02:00
|
|
|
, m_is_synthetic(is_synthetic)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-08-30 18:03:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_is_synthetic;
|
|
|
|
};
|
|
|
|
|
2021-06-30 15:42:13 -03:00
|
|
|
class NewClass final : public Instruction {
|
|
|
|
public:
|
2023-06-28 18:17:13 +02:00
|
|
|
explicit NewClass(ClassExpression const& class_expression, Optional<IdentifierTableIndex> lhs_name)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::NewClass, sizeof(*this))
|
2021-06-30 15:42:13 -03:00
|
|
|
, m_class_expression(class_expression)
|
2023-06-28 18:17:13 +02:00
|
|
|
, m_lhs_name(lhs_name)
|
2021-06-30 15:42:13 -03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-30 15:42:13 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
ClassExpression const& m_class_expression;
|
2023-06-28 18:17:13 +02:00
|
|
|
Optional<IdentifierTableIndex> m_lhs_name;
|
2021-06-30 15:42:13 -03:00
|
|
|
};
|
|
|
|
|
2021-06-10 00:49:23 +02:00
|
|
|
class NewFunction final : public Instruction {
|
2021-06-05 15:14:09 +02:00
|
|
|
public:
|
2023-06-28 18:17:13 +02:00
|
|
|
explicit NewFunction(FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Register> home_object = {})
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::NewFunction, sizeof(*this))
|
2021-06-10 00:49:23 +02:00
|
|
|
, m_function_node(function_node)
|
2023-06-28 18:17:13 +02:00
|
|
|
, m_lhs_name(lhs_name)
|
2023-06-16 10:25:05 +02:00
|
|
|
, m_home_object(move(home_object))
|
2021-06-05 15:14:09 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-05 15:14:09 +02:00
|
|
|
|
|
|
|
private:
|
2023-06-23 14:27:42 +02:00
|
|
|
FunctionExpression const& m_function_node;
|
2023-06-28 18:17:13 +02:00
|
|
|
Optional<IdentifierTableIndex> m_lhs_name;
|
2023-06-16 10:25:05 +02:00
|
|
|
Optional<Register> m_home_object;
|
2021-06-05 15:14:09 +02:00
|
|
|
};
|
|
|
|
|
2023-06-16 16:34:47 +02:00
|
|
|
class BlockDeclarationInstantiation final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::BlockDeclarationInstantiation, sizeof(*this))
|
2023-06-16 16:34:47 +02:00
|
|
|
, m_scope_node(scope_node)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ScopeNode const& m_scope_node;
|
|
|
|
};
|
|
|
|
|
2021-06-05 15:53:36 +02:00
|
|
|
class Return final : public Instruction {
|
|
|
|
public:
|
2021-06-09 06:49:58 +04:30
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
2021-06-07 20:58:36 -07:00
|
|
|
Return()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Return, sizeof(*this))
|
2021-06-05 15:53:36 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-05 15:53:36 +02:00
|
|
|
};
|
|
|
|
|
2021-06-09 11:40:38 +02:00
|
|
|
class Increment final : public Instruction {
|
|
|
|
public:
|
|
|
|
Increment()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Increment, sizeof(*this))
|
2021-06-09 11:40:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-09 11:40:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Decrement final : public Instruction {
|
|
|
|
public:
|
|
|
|
Decrement()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Decrement, sizeof(*this))
|
2021-06-09 11:40:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-09 11:40:38 +02:00
|
|
|
};
|
|
|
|
|
2023-06-16 10:51:40 +02:00
|
|
|
class ToNumeric final : public Instruction {
|
|
|
|
public:
|
|
|
|
ToNumeric()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ToNumeric, sizeof(*this))
|
2023-06-16 10:51:40 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
};
|
|
|
|
|
2021-06-09 18:18:56 +02:00
|
|
|
class Throw final : public Instruction {
|
|
|
|
public:
|
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
Throw()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Throw, sizeof(*this))
|
2021-06-09 18:18:56 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-09 18:18:56 +02:00
|
|
|
};
|
|
|
|
|
2022-12-09 18:48:57 +00:00
|
|
|
class ThrowIfNotObject final : public Instruction {
|
|
|
|
public:
|
|
|
|
ThrowIfNotObject()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ThrowIfNotObject, sizeof(*this))
|
2022-12-09 18:48:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
};
|
|
|
|
|
2023-06-25 08:50:07 +02:00
|
|
|
class ThrowIfNullish final : public Instruction {
|
|
|
|
public:
|
|
|
|
ThrowIfNullish()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ThrowIfNullish, sizeof(*this))
|
2023-06-25 08:50:07 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
};
|
|
|
|
|
2021-06-10 15:04:38 +02:00
|
|
|
class EnterUnwindContext final : public Instruction {
|
|
|
|
public:
|
2021-06-13 20:39:40 +04:30
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
EnterUnwindContext(Label entry_point, Optional<Label> handler_target, Optional<Label> finalizer_target)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::EnterUnwindContext, sizeof(*this))
|
2021-06-13 20:39:40 +04:30
|
|
|
, m_entry_point(move(entry_point))
|
2021-06-12 11:22:46 +02:00
|
|
|
, m_handler_target(move(handler_target))
|
|
|
|
, m_finalizer_target(move(finalizer_target))
|
2021-06-10 15:04:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 20:40:20 +04:30
|
|
|
|
|
|
|
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 15:04:38 +02:00
|
|
|
|
|
|
|
private:
|
2021-06-13 20:39:40 +04:30
|
|
|
Label m_entry_point;
|
2021-06-10 15:04:38 +02:00
|
|
|
Optional<Label> m_handler_target;
|
|
|
|
Optional<Label> m_finalizer_target;
|
|
|
|
};
|
|
|
|
|
2022-11-25 16:15:34 +01:00
|
|
|
class ScheduleJump final : public Instruction {
|
|
|
|
public:
|
|
|
|
// Note: We use this instruction to tell the next `finally` block to
|
|
|
|
// continue execution with a specific break/continue target;
|
|
|
|
// FIXME: We currently don't clear the interpreter internal flag, when we change
|
|
|
|
// the control-flow (`break`, `continue`) in a finally-block,
|
|
|
|
// FIXME: .NET on x86_64 uses a call to the finally instead, which could make this
|
|
|
|
// easier, at the cost of making control-flow changes (`break`, `continue`, `return`)
|
|
|
|
// in the finally-block more difficult, but as stated above, those
|
|
|
|
// aren't handled 100% correctly at the moment anyway
|
|
|
|
// It might be worth investigating a similar mechanism
|
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
ScheduleJump(Label target)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ScheduleJump, sizeof(*this))
|
2022-11-25 16:15:34 +01:00
|
|
|
, m_target(target)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Label target() const { return m_target; }
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Label m_target;
|
|
|
|
};
|
|
|
|
|
2023-06-16 16:43:24 +02:00
|
|
|
class LeaveLexicalEnvironment final : public Instruction {
|
2022-02-12 19:48:45 +03:30
|
|
|
public:
|
2023-06-16 16:43:24 +02:00
|
|
|
LeaveLexicalEnvironment()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::LeaveLexicalEnvironment, sizeof(*this))
|
2022-02-12 19:48:45 +03:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-02-12 19:48:45 +03:30
|
|
|
};
|
|
|
|
|
2021-06-10 15:04:38 +02:00
|
|
|
class LeaveUnwindContext final : public Instruction {
|
|
|
|
public:
|
|
|
|
LeaveUnwindContext()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::LeaveUnwindContext, sizeof(*this))
|
2021-06-10 15:04:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-10 15:04:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContinuePendingUnwind final : public Instruction {
|
|
|
|
public:
|
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
2021-06-12 11:22:46 +02:00
|
|
|
explicit ContinuePendingUnwind(Label resume_target)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ContinuePendingUnwind, sizeof(*this))
|
2021-06-10 15:04:38 +02:00
|
|
|
, m_resume_target(resume_target)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 20:40:20 +04:30
|
|
|
|
|
|
|
auto& resume_target() const { return m_resume_target; }
|
2021-06-10 15:04:38 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Label m_resume_target;
|
|
|
|
};
|
2021-06-10 22:12:21 +02:00
|
|
|
|
2021-06-11 01:38:30 +04:30
|
|
|
class Yield final : public Instruction {
|
|
|
|
public:
|
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
explicit Yield(Label continuation_label)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Yield, sizeof(*this))
|
2021-06-11 01:38:30 +04:30
|
|
|
, m_continuation_label(continuation_label)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-13 10:29:30 +03:30
|
|
|
explicit Yield(nullptr_t)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Yield, sizeof(*this))
|
2021-06-11 01:38:30 +04:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 20:40:20 +04:30
|
|
|
|
|
|
|
auto& continuation() const { return m_continuation_label; }
|
2021-06-11 01:38:30 +04:30
|
|
|
|
|
|
|
private:
|
|
|
|
Optional<Label> m_continuation_label;
|
|
|
|
};
|
|
|
|
|
2023-07-14 21:42:43 +01:00
|
|
|
class Await final : public Instruction {
|
|
|
|
public:
|
|
|
|
constexpr static bool IsTerminator = true;
|
|
|
|
|
|
|
|
explicit Await(Label continuation_label)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::Await, sizeof(*this))
|
2023-07-14 21:42:43 +01:00
|
|
|
, m_continuation_label(continuation_label)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
auto& continuation() const { return m_continuation_label; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Label m_continuation_label;
|
|
|
|
};
|
|
|
|
|
2021-07-01 12:24:46 +02:00
|
|
|
class PushDeclarativeEnvironment final : public Instruction {
|
2021-06-10 22:12:21 +02:00
|
|
|
public:
|
2021-07-01 12:24:46 +02:00
|
|
|
explicit PushDeclarativeEnvironment(HashMap<u32, Variable> variables)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::PushDeclarativeEnvironment, sizeof(*this))
|
2021-06-10 22:12:21 +02:00
|
|
|
, m_variables(move(variables))
|
|
|
|
{
|
|
|
|
}
|
2021-06-13 13:40:48 -07:00
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-10 22:12:21 +02:00
|
|
|
|
2021-06-11 01:38:30 +04:30
|
|
|
private:
|
2021-06-10 22:12:21 +02:00
|
|
|
HashMap<u32, Variable> m_variables;
|
|
|
|
};
|
2021-06-14 09:37:35 +02:00
|
|
|
|
2021-06-13 13:40:48 -07:00
|
|
|
class GetIterator final : public Instruction {
|
|
|
|
public:
|
2023-06-27 19:24:34 +01:00
|
|
|
GetIterator(IteratorHint hint = IteratorHint::Sync)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetIterator, sizeof(*this))
|
2023-06-27 19:24:34 +01:00
|
|
|
, m_hint(hint)
|
2021-06-13 13:40:48 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2023-06-27 19:24:34 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
IteratorHint m_hint { IteratorHint::Sync };
|
2021-06-13 13:40:48 -07:00
|
|
|
};
|
|
|
|
|
2022-12-09 18:48:57 +00:00
|
|
|
class GetMethod final : public Instruction {
|
|
|
|
public:
|
|
|
|
GetMethod(IdentifierTableIndex property)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetMethod, sizeof(*this))
|
2022-12-09 18:48:57 +00:00
|
|
|
, m_property(property)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_property;
|
|
|
|
};
|
|
|
|
|
2022-03-18 20:18:19 +03:30
|
|
|
class GetObjectPropertyIterator final : public Instruction {
|
|
|
|
public:
|
|
|
|
GetObjectPropertyIterator()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetObjectPropertyIterator, sizeof(*this))
|
2022-03-18 20:18:19 +03:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-03-18 20:18:19 +03:30
|
|
|
};
|
|
|
|
|
2022-12-09 18:48:57 +00:00
|
|
|
class IteratorClose final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::IteratorClose, sizeof(*this))
|
2022-12-09 18:48:57 +00:00
|
|
|
, m_completion_type(completion_type)
|
|
|
|
, m_completion_value(completion_value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Completion::Type m_completion_type { Completion::Type::Normal };
|
|
|
|
Optional<Value> m_completion_value;
|
|
|
|
};
|
|
|
|
|
2023-07-14 21:42:43 +01:00
|
|
|
class AsyncIteratorClose final : public Instruction {
|
|
|
|
public:
|
|
|
|
AsyncIteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::AsyncIteratorClose, sizeof(*this))
|
2023-07-14 21:42:43 +01:00
|
|
|
, m_completion_type(completion_type)
|
|
|
|
, m_completion_value(completion_value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Completion::Type m_completion_type { Completion::Type::Normal };
|
|
|
|
Optional<Value> m_completion_value;
|
|
|
|
};
|
|
|
|
|
2021-06-13 13:40:48 -07:00
|
|
|
class IteratorNext final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorNext()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::IteratorNext, sizeof(*this))
|
2021-06-13 13:40:48 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 13:40:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class IteratorResultDone final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorResultDone()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::IteratorResultDone, sizeof(*this))
|
2021-06-13 13:40:48 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 13:40:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class IteratorResultValue final : public Instruction {
|
|
|
|
public:
|
|
|
|
IteratorResultValue()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::IteratorResultValue, sizeof(*this))
|
2021-06-13 13:40:48 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-06-13 13:40:48 -07:00
|
|
|
};
|
|
|
|
|
2021-10-24 14:43:00 +02:00
|
|
|
class ResolveThisBinding final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit ResolveThisBinding()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ResolveThisBinding, sizeof(*this))
|
2021-10-24 14:43:00 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2021-10-24 14:43:00 +02:00
|
|
|
};
|
|
|
|
|
2023-05-15 18:45:16 +01:00
|
|
|
class ResolveSuperBase final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit ResolveSuperBase()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::ResolveSuperBase, sizeof(*this))
|
2023-05-15 18:45:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
};
|
|
|
|
|
2022-03-19 19:40:21 +00:00
|
|
|
class GetNewTarget final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit GetNewTarget()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetNewTarget, sizeof(*this))
|
2022-03-19 19:40:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-03-19 19:40:21 +00:00
|
|
|
};
|
|
|
|
|
2023-07-11 23:07:12 -04:00
|
|
|
class GetImportMeta final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit GetImportMeta()
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::GetImportMeta, sizeof(*this))
|
2023-07-11 23:07:12 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
};
|
|
|
|
|
2022-06-11 23:12:22 +01:00
|
|
|
class TypeofVariable final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit TypeofVariable(IdentifierTableIndex identifier)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::TypeofVariable, sizeof(*this))
|
2022-06-11 23:12:22 +01:00
|
|
|
, m_identifier(identifier)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
2022-12-06 01:12:49 +00:00
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
2022-06-11 23:12:22 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
IdentifierTableIndex m_identifier;
|
|
|
|
};
|
|
|
|
|
2023-07-05 02:17:10 +02:00
|
|
|
class TypeofLocal final : public Instruction {
|
|
|
|
public:
|
|
|
|
explicit TypeofLocal(size_t index)
|
2023-09-13 21:32:51 +02:00
|
|
|
: Instruction(Type::TypeofLocal, sizeof(*this))
|
2023-07-05 02:17:10 +02:00
|
|
|
, m_index(index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
|
|
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t m_index;
|
|
|
|
};
|
|
|
|
|
2021-06-03 10:46:30 +02:00
|
|
|
}
|
2021-06-09 09:19:34 +02:00
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
2022-02-07 14:36:45 +01:00
|
|
|
ALWAYS_INLINE ThrowCompletionOr<void> Instruction::execute(Bytecode::Interpreter& interpreter) const
|
2021-06-09 09:19:34 +02:00
|
|
|
{
|
|
|
|
#define __BYTECODE_OP(op) \
|
|
|
|
case Instruction::Type::op: \
|
2021-06-15 18:08:12 +04:30
|
|
|
return static_cast<Bytecode::Op::op const&>(*this).execute_impl(interpreter);
|
2021-06-09 09:19:34 +02:00
|
|
|
|
|
|
|
switch (type()) {
|
|
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
2021-06-13 20:40:20 +04:30
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef __BYTECODE_OP
|
|
|
|
}
|
|
|
|
|
2021-06-09 09:19:34 +02:00
|
|
|
}
|