12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054 |
- /*
- * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org>
- * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
- * Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
- #pragma once
- #include <AK/FixedArray.h>
- #include <AK/StdLibExtras.h>
- #include <LibCrypto/BigInt/SignedBigInteger.h>
- #include <LibJS/Bytecode/Builtins.h>
- #include <LibJS/Bytecode/IdentifierTable.h>
- #include <LibJS/Bytecode/Instruction.h>
- #include <LibJS/Bytecode/Label.h>
- #include <LibJS/Bytecode/Operand.h>
- #include <LibJS/Bytecode/RegexTable.h>
- #include <LibJS/Bytecode/Register.h>
- #include <LibJS/Bytecode/ScopedOperand.h>
- #include <LibJS/Bytecode/StringTable.h>
- #include <LibJS/Heap/Cell.h>
- #include <LibJS/Runtime/Environment.h>
- #include <LibJS/Runtime/Iterator.h>
- #include <LibJS/Runtime/Value.h>
- #include <LibJS/Runtime/ValueTraits.h>
- namespace JS {
- class FunctionExpression;
- }
- namespace JS::Bytecode::Op {
- class Mov final : public Instruction {
- public:
- Mov(Operand dst, Operand src)
- : Instruction(Type::Mov)
- , m_dst(dst)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand src() const { return m_src; }
- private:
- Operand m_dst;
- Operand m_src;
- };
- #define JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(O) \
- O(Add, add) \
- O(BitwiseAnd, bitwise_and) \
- O(BitwiseOr, bitwise_or) \
- O(BitwiseXor, bitwise_xor) \
- O(GreaterThan, greater_than) \
- O(GreaterThanEquals, greater_than_equals) \
- O(LeftShift, left_shift) \
- O(LessThan, less_than) \
- O(LessThanEquals, less_than_equals) \
- O(Mul, mul) \
- O(RightShift, right_shift) \
- O(Sub, sub) \
- O(UnsignedRightShift, unsigned_right_shift)
- #define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \
- O(Div, div) \
- O(Exp, exp) \
- O(Mod, mod) \
- O(In, in) \
- O(InstanceOf, instance_of) \
- O(LooselyInequals, loosely_inequals) \
- O(LooselyEquals, loosely_equals) \
- O(StrictlyInequals, strict_inequals) \
- O(StrictlyEquals, strict_equals)
- #define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
- class OpTitleCase final : public Instruction { \
- public: \
- explicit OpTitleCase(Operand dst, Operand lhs, Operand rhs) \
- : Instruction(Type::OpTitleCase) \
- , m_dst(dst) \
- , m_lhs(lhs) \
- , m_rhs(rhs) \
- { \
- } \
- \
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
- ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
- \
- Operand dst() const { return m_dst; } \
- Operand lhs() const { return m_lhs; } \
- Operand rhs() const { return m_rhs; } \
- \
- private: \
- Operand m_dst; \
- Operand m_lhs; \
- Operand m_rhs; \
- };
- JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(JS_DECLARE_COMMON_BINARY_OP)
- JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(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_)
- #define JS_DECLARE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
- class OpTitleCase final : public Instruction { \
- public: \
- OpTitleCase(Operand dst, Operand src) \
- : Instruction(Type::OpTitleCase) \
- , m_dst(dst) \
- , m_src(src) \
- { \
- } \
- \
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
- ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
- \
- Operand dst() const { return m_dst; } \
- Operand src() const { return m_src; } \
- \
- private: \
- Operand m_dst; \
- Operand m_src; \
- };
- JS_ENUMERATE_COMMON_UNARY_OPS(JS_DECLARE_COMMON_UNARY_OP)
- #undef JS_DECLARE_COMMON_UNARY_OP
- class NewObject final : public Instruction {
- public:
- explicit NewObject(Operand dst)
- : Instruction(Type::NewObject)
- , m_dst(dst)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- private:
- Operand m_dst;
- };
- class NewRegExp final : public Instruction {
- public:
- NewRegExp(Operand dst, StringTableIndex source_index, StringTableIndex flags_index, RegexTableIndex regex_index)
- : Instruction(Type::NewRegExp)
- , m_dst(dst)
- , m_source_index(source_index)
- , m_flags_index(flags_index)
- , m_regex_index(regex_index)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- StringTableIndex source_index() const { return m_source_index; }
- StringTableIndex flags_index() const { return m_flags_index; }
- RegexTableIndex regex_index() const { return m_regex_index; }
- private:
- Operand m_dst;
- StringTableIndex m_source_index;
- StringTableIndex m_flags_index;
- RegexTableIndex m_regex_index;
- };
- #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: \
- New##ErrorName(Operand dst, StringTableIndex error_string) \
- : Instruction(Type::New##ErrorName) \
- , m_dst(dst) \
- , m_error_string(error_string) \
- { \
- } \
- \
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
- ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
- \
- Operand dst() const { return m_dst; } \
- StringTableIndex error_string() const { return m_error_string; } \
- \
- private: \
- Operand m_dst; \
- StringTableIndex m_error_string; \
- };
- JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DECLARE_NEW_BUILTIN_ERROR_OP)
- #undef JS_DECLARE_NEW_BUILTIN_ERROR_OP
- // NOTE: This instruction is variable-width depending on the number of excluded names
- class CopyObjectExcludingProperties final : public Instruction {
- public:
- static constexpr bool IsVariableLength = true;
- CopyObjectExcludingProperties(Operand dst, Operand from_object, Vector<ScopedOperand> const& excluded_names)
- : Instruction(Type::CopyObjectExcludingProperties)
- , m_dst(dst)
- , 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];
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- size_t length_impl() const
- {
- return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_excluded_names_count);
- }
- Operand dst() const { return m_dst; }
- Operand from_object() const { return m_from_object; }
- size_t excluded_names_count() const { return m_excluded_names_count; }
- Operand const* excluded_names() const { return m_excluded_names; }
- private:
- Operand m_dst;
- Operand m_from_object;
- size_t m_excluded_names_count { 0 };
- Operand m_excluded_names[];
- };
- // NOTE: This instruction is variable-width depending on the number of elements!
- class NewArray final : public Instruction {
- public:
- static constexpr bool IsVariableLength = true;
- explicit NewArray(Operand dst)
- : Instruction(Type::NewArray)
- , m_dst(dst)
- , m_element_count(0)
- {
- }
- NewArray(Operand dst, ReadonlySpan<ScopedOperand> elements)
- : Instruction(Type::NewArray)
- , m_dst(dst)
- , m_element_count(elements.size())
- {
- for (size_t i = 0; i < m_element_count; ++i)
- m_elements[i] = elements[i];
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- size_t length_impl() const
- {
- return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_element_count);
- }
- size_t element_count() const { return m_element_count; }
- private:
- Operand m_dst;
- size_t m_element_count { 0 };
- Operand m_elements[];
- };
- class NewPrimitiveArray final : public Instruction {
- public:
- static constexpr bool IsVariableLength = true;
- NewPrimitiveArray(Operand dst, ReadonlySpan<Value> elements)
- : Instruction(Type::NewPrimitiveArray)
- , m_dst(dst)
- , m_element_count(elements.size())
- {
- for (size_t i = 0; i < m_element_count; ++i)
- m_elements[i] = elements[i];
- }
- size_t length_impl() const
- {
- return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Value) * m_element_count);
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- ReadonlySpan<Value> elements() const { return { m_elements, m_element_count }; }
- private:
- Operand m_dst;
- size_t m_element_count { 0 };
- Value m_elements[];
- };
- class ArrayAppend final : public Instruction {
- public:
- ArrayAppend(Operand dst, Operand src, bool is_spread)
- : Instruction(Type::ArrayAppend)
- , m_dst(dst)
- , m_src(src)
- , m_is_spread(is_spread)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand src() const { return m_src; }
- bool is_spread() const { return m_is_spread; }
- private:
- Operand m_dst;
- Operand m_src;
- bool m_is_spread = false;
- };
- class ImportCall final : public Instruction {
- public:
- ImportCall(Operand dst, Operand specifier, Operand options)
- : Instruction(Type::ImportCall)
- , m_dst(dst)
- , m_specifier(specifier)
- , m_options(options)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand specifier() const { return m_specifier; }
- Operand options() const { return m_options; }
- private:
- Operand m_dst;
- Operand m_specifier;
- Operand m_options;
- };
- class IteratorToArray final : public Instruction {
- public:
- explicit IteratorToArray(Operand dst, Operand iterator)
- : Instruction(Type::IteratorToArray)
- , m_dst(dst)
- , m_iterator(iterator)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand iterator() const { return m_iterator; }
- private:
- Operand m_dst;
- Operand m_iterator;
- };
- class ConcatString final : public Instruction {
- public:
- explicit ConcatString(Operand dst, Operand src)
- : Instruction(Type::ConcatString)
- , m_dst(dst)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand src() const { return m_src; }
- private:
- Operand m_dst;
- Operand m_src;
- };
- enum class EnvironmentMode {
- Lexical,
- Var,
- };
- class CreateLexicalEnvironment final : public Instruction {
- public:
- explicit CreateLexicalEnvironment()
- : Instruction(Type::CreateLexicalEnvironment)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- };
- class EnterObjectEnvironment final : public Instruction {
- public:
- explicit EnterObjectEnvironment(Operand object)
- : Instruction(Type::EnterObjectEnvironment)
- , m_object(object)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand object() const { return m_object; }
- private:
- Operand m_object;
- };
- class Catch final : public Instruction {
- public:
- explicit Catch(Operand dst)
- : Instruction(Type::Catch)
- , m_dst(dst)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- private:
- Operand m_dst;
- };
- class LeaveFinally final : public Instruction {
- public:
- explicit LeaveFinally()
- : Instruction(Type::LeaveFinally)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- };
- class RestoreScheduledJump final : public Instruction {
- public:
- explicit RestoreScheduledJump()
- : Instruction(Type::RestoreScheduledJump)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- };
- class CreateVariable final : public Instruction {
- public:
- explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false, bool is_strict = false)
- : Instruction(Type::CreateVariable)
- , m_identifier(identifier)
- , m_mode(mode)
- , m_is_immutable(is_immutable)
- , m_is_global(is_global)
- , m_is_strict(is_strict)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- IdentifierTableIndex identifier() const { return m_identifier; }
- EnvironmentMode mode() const { return m_mode; }
- bool is_immutable() const { return m_is_immutable; }
- bool is_global() const { return m_is_global; }
- bool is_strict() const { return m_is_strict; }
- private:
- IdentifierTableIndex m_identifier;
- EnvironmentMode m_mode;
- bool m_is_immutable : 4 { false };
- bool m_is_global : 4 { false };
- bool m_is_strict { false };
- };
- class SetVariable final : public Instruction {
- public:
- enum class InitializationMode {
- Initialize,
- Set,
- };
- explicit SetVariable(IdentifierTableIndex identifier, Operand src, u32 cache_index, InitializationMode initialization_mode = InitializationMode::Set, EnvironmentMode mode = EnvironmentMode::Lexical)
- : Instruction(Type::SetVariable)
- , m_identifier(identifier)
- , m_src(src)
- , m_mode(mode)
- , m_initialization_mode(initialization_mode)
- , m_cache_index(cache_index)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- IdentifierTableIndex identifier() const { return m_identifier; }
- Operand src() const { return m_src; }
- EnvironmentMode mode() const { return m_mode; }
- InitializationMode initialization_mode() const { return m_initialization_mode; }
- u32 cache_index() const { return m_cache_index; }
- private:
- IdentifierTableIndex m_identifier;
- Operand m_src;
- EnvironmentMode m_mode;
- InitializationMode m_initialization_mode { InitializationMode::Set };
- u32 m_cache_index { 0 };
- };
- class SetLocal final : public Instruction {
- public:
- SetLocal(size_t index, Operand src)
- : Instruction(Type::SetLocal)
- , m_index(index)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- u32 index() const { return m_index; }
- Operand dst() const { return Operand(Operand::Type::Local, m_index); }
- Operand src() const { return m_src; }
- private:
- u32 m_index;
- Operand m_src;
- };
- class GetCalleeAndThisFromEnvironment final : public Instruction {
- public:
- explicit GetCalleeAndThisFromEnvironment(Operand callee, Operand this_value, IdentifierTableIndex identifier, u32 cache_index)
- : Instruction(Type::GetCalleeAndThisFromEnvironment)
- , m_identifier(identifier)
- , m_callee(callee)
- , m_this_value(this_value)
- , m_cache_index(cache_index)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- IdentifierTableIndex identifier() const { return m_identifier; }
- u32 cache_index() const { return m_cache_index; }
- Operand callee() const { return m_callee; }
- Operand this_() const { return m_this_value; }
- private:
- IdentifierTableIndex m_identifier;
- Operand m_callee;
- Operand m_this_value;
- u32 m_cache_index { 0 };
- };
- class GetVariable final : public Instruction {
- public:
- explicit GetVariable(Operand dst, IdentifierTableIndex identifier, u32 cache_index)
- : Instruction(Type::GetVariable)
- , m_dst(dst)
- , m_identifier(identifier)
- , m_cache_index(cache_index)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- IdentifierTableIndex identifier() const { return m_identifier; }
- u32 cache_index() const { return m_cache_index; }
- private:
- Operand m_dst;
- IdentifierTableIndex m_identifier;
- u32 m_cache_index { 0 };
- };
- class GetGlobal final : public Instruction {
- public:
- GetGlobal(Operand dst, IdentifierTableIndex identifier, u32 cache_index)
- : Instruction(Type::GetGlobal)
- , m_dst(dst)
- , m_identifier(identifier)
- , m_cache_index(cache_index)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- IdentifierTableIndex identifier() const { return m_identifier; }
- u32 cache_index() const { return m_cache_index; }
- private:
- Operand m_dst;
- IdentifierTableIndex m_identifier;
- u32 m_cache_index { 0 };
- };
- class DeleteVariable final : public Instruction {
- public:
- explicit DeleteVariable(Operand dst, IdentifierTableIndex identifier)
- : Instruction(Type::DeleteVariable)
- , m_dst(dst)
- , m_identifier(identifier)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- IdentifierTableIndex identifier() const { return m_identifier; }
- private:
- Operand m_dst;
- IdentifierTableIndex m_identifier;
- };
- class GetById final : public Instruction {
- public:
- GetById(Operand dst, Operand base, IdentifierTableIndex property, Optional<IdentifierTableIndex> base_identifier, u32 cache_index)
- : Instruction(Type::GetById)
- , m_dst(dst)
- , m_base(base)
- , m_property(property)
- , m_base_identifier(move(base_identifier))
- , m_cache_index(cache_index)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- IdentifierTableIndex property() const { return m_property; }
- u32 cache_index() const { return m_cache_index; }
- private:
- Operand m_dst;
- Operand m_base;
- IdentifierTableIndex m_property;
- Optional<IdentifierTableIndex> m_base_identifier;
- u32 m_cache_index { 0 };
- };
- class GetByIdWithThis final : public Instruction {
- public:
- GetByIdWithThis(Operand dst, Operand base, IdentifierTableIndex property, Operand this_value, u32 cache_index)
- : Instruction(Type::GetByIdWithThis)
- , m_dst(dst)
- , m_base(base)
- , m_property(property)
- , m_this_value(this_value)
- , m_cache_index(cache_index)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- IdentifierTableIndex property() const { return m_property; }
- Operand this_value() const { return m_this_value; }
- u32 cache_index() const { return m_cache_index; }
- private:
- Operand m_dst;
- Operand m_base;
- IdentifierTableIndex m_property;
- Operand m_this_value;
- u32 m_cache_index { 0 };
- };
- class GetPrivateById final : public Instruction {
- public:
- explicit GetPrivateById(Operand dst, Operand base, IdentifierTableIndex property)
- : Instruction(Type::GetPrivateById)
- , m_dst(dst)
- , m_base(base)
- , m_property(property)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- IdentifierTableIndex property() const { return m_property; }
- private:
- Operand m_dst;
- Operand m_base;
- IdentifierTableIndex m_property;
- };
- class HasPrivateId final : public Instruction {
- public:
- HasPrivateId(Operand dst, Operand base, IdentifierTableIndex property)
- : Instruction(Type::HasPrivateId)
- , m_dst(dst)
- , m_base(base)
- , m_property(property)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- IdentifierTableIndex property() const { return m_property; }
- private:
- Operand m_dst;
- Operand m_base;
- IdentifierTableIndex m_property;
- };
- enum class PropertyKind {
- Getter,
- Setter,
- KeyValue,
- DirectKeyValue, // Used for Object expressions. Always sets an own property, never calls a setter.
- Spread,
- ProtoSetter,
- };
- class PutById final : public Instruction {
- public:
- explicit PutById(Operand base, IdentifierTableIndex property, Operand src, PropertyKind kind, u32 cache_index, Optional<IdentifierTableIndex> base_identifier = {})
- : Instruction(Type::PutById)
- , m_base(base)
- , m_property(property)
- , m_src(src)
- , m_kind(kind)
- , m_cache_index(cache_index)
- , m_base_identifier(move(base_identifier))
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand base() const { return m_base; }
- IdentifierTableIndex property() const { return m_property; }
- Operand src() const { return m_src; }
- PropertyKind kind() const { return m_kind; }
- u32 cache_index() const { return m_cache_index; }
- private:
- Operand m_base;
- IdentifierTableIndex m_property;
- Operand m_src;
- PropertyKind m_kind;
- u32 m_cache_index { 0 };
- Optional<IdentifierTableIndex> m_base_identifier {};
- };
- class PutByIdWithThis final : public Instruction {
- public:
- PutByIdWithThis(Operand base, Operand this_value, IdentifierTableIndex property, Operand src, PropertyKind kind, u32 cache_index)
- : Instruction(Type::PutByIdWithThis)
- , m_base(base)
- , m_this_value(this_value)
- , m_property(property)
- , m_src(src)
- , m_kind(kind)
- , m_cache_index(cache_index)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand base() const { return m_base; }
- Operand this_value() const { return m_this_value; }
- IdentifierTableIndex property() const { return m_property; }
- Operand src() const { return m_src; }
- PropertyKind kind() const { return m_kind; }
- u32 cache_index() const { return m_cache_index; }
- private:
- Operand m_base;
- Operand m_this_value;
- IdentifierTableIndex m_property;
- Operand m_src;
- PropertyKind m_kind;
- u32 m_cache_index { 0 };
- };
- class PutPrivateById final : public Instruction {
- public:
- explicit PutPrivateById(Operand base, IdentifierTableIndex property, Operand src, PropertyKind kind = PropertyKind::KeyValue)
- : Instruction(Type::PutPrivateById)
- , m_base(base)
- , m_property(property)
- , m_src(src)
- , m_kind(kind)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand base() const { return m_base; }
- IdentifierTableIndex property() const { return m_property; }
- Operand src() const { return m_src; }
- private:
- Operand m_base;
- IdentifierTableIndex m_property;
- Operand m_src;
- PropertyKind m_kind;
- };
- class DeleteById final : public Instruction {
- public:
- explicit DeleteById(Operand dst, Operand base, IdentifierTableIndex property)
- : Instruction(Type::DeleteById)
- , m_dst(dst)
- , m_base(base)
- , m_property(property)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- IdentifierTableIndex property() const { return m_property; }
- private:
- Operand m_dst;
- Operand m_base;
- IdentifierTableIndex m_property;
- };
- class DeleteByIdWithThis final : public Instruction {
- public:
- DeleteByIdWithThis(Operand dst, Operand base, Operand this_value, IdentifierTableIndex property)
- : Instruction(Type::DeleteByIdWithThis)
- , m_dst(dst)
- , m_base(base)
- , m_this_value(this_value)
- , m_property(property)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- Operand this_value() const { return m_this_value; }
- IdentifierTableIndex property() const { return m_property; }
- private:
- Operand m_dst;
- Operand m_base;
- Operand m_this_value;
- IdentifierTableIndex m_property;
- };
- class GetByValue final : public Instruction {
- public:
- GetByValue(Operand dst, Operand base, Operand property, Optional<IdentifierTableIndex> base_identifier = {})
- : Instruction(Type::GetByValue)
- , m_dst(dst)
- , m_base(base)
- , m_property(property)
- , m_base_identifier(move(base_identifier))
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- Operand property() const { return m_property; }
- Optional<DeprecatedFlyString const&> base_identifier(Bytecode::Interpreter const&) const;
- private:
- Operand m_dst;
- Operand m_base;
- Operand m_property;
- Optional<IdentifierTableIndex> m_base_identifier;
- };
- class GetByValueWithThis final : public Instruction {
- public:
- GetByValueWithThis(Operand dst, Operand base, Operand property, Operand this_value)
- : Instruction(Type::GetByValueWithThis)
- , m_dst(dst)
- , m_base(base)
- , m_property(property)
- , m_this_value(this_value)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- Operand property() const { return m_property; }
- Operand this_value() const { return m_this_value; }
- private:
- Operand m_dst;
- Operand m_base;
- Operand m_property;
- Operand m_this_value;
- };
- class PutByValue final : public Instruction {
- public:
- PutByValue(Operand base, Operand property, Operand src, PropertyKind kind = PropertyKind::KeyValue, Optional<IdentifierTableIndex> base_identifier = {})
- : Instruction(Type::PutByValue)
- , m_base(base)
- , m_property(property)
- , m_src(src)
- , m_kind(kind)
- , m_base_identifier(move(base_identifier))
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand base() const { return m_base; }
- Operand property() const { return m_property; }
- Operand src() const { return m_src; }
- PropertyKind kind() const { return m_kind; }
- private:
- Operand m_base;
- Operand m_property;
- Operand m_src;
- PropertyKind m_kind;
- Optional<IdentifierTableIndex> m_base_identifier;
- };
- class PutByValueWithThis final : public Instruction {
- public:
- PutByValueWithThis(Operand base, Operand property, Operand this_value, Operand src, PropertyKind kind = PropertyKind::KeyValue)
- : Instruction(Type::PutByValueWithThis)
- , m_base(base)
- , m_property(property)
- , m_this_value(this_value)
- , m_src(src)
- , m_kind(kind)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand base() const { return m_base; }
- Operand property() const { return m_property; }
- Operand this_value() const { return m_this_value; }
- Operand src() const { return m_src; }
- PropertyKind kind() const { return m_kind; }
- private:
- Operand m_base;
- Operand m_property;
- Operand m_this_value;
- Operand m_src;
- PropertyKind m_kind;
- };
- class DeleteByValue final : public Instruction {
- public:
- DeleteByValue(Operand dst, Operand base, Operand property)
- : Instruction(Type::DeleteByValue)
- , m_dst(dst)
- , m_base(base)
- , m_property(property)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- Operand property() const { return m_property; }
- private:
- Operand m_dst;
- Operand m_base;
- Operand m_property;
- };
- class DeleteByValueWithThis final : public Instruction {
- public:
- DeleteByValueWithThis(Operand dst, Operand base, Operand this_value, Operand property)
- : Instruction(Type::DeleteByValueWithThis)
- , m_dst(dst)
- , m_base(base)
- , m_this_value(this_value)
- , m_property(property)
- {
- }
- Operand dst() const { return m_dst; }
- Operand base() const { return m_base; }
- Operand this_value() const { return m_this_value; }
- Operand property() const { return m_property; }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- private:
- Operand m_dst;
- Operand m_base;
- Operand m_this_value;
- Operand m_property;
- };
- class Jump final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit Jump(Label target)
- : Instruction(Type::Jump)
- , m_target(target)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_target);
- }
- auto& target() const { return m_target; }
- protected:
- Label m_target;
- };
- class JumpIf final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit JumpIf(Operand condition, Label true_target, Label false_target)
- : Instruction(Type::JumpIf)
- , m_condition(condition)
- , m_true_target(true_target)
- , m_false_target(false_target)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_true_target);
- visitor(m_false_target);
- }
- Operand condition() const { return m_condition; }
- auto& true_target() const { return m_true_target; }
- auto& false_target() const { return m_false_target; }
- private:
- Operand m_condition;
- Label m_true_target;
- Label m_false_target;
- };
- class JumpTrue final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit JumpTrue(Operand condition, Label target)
- : Instruction(Type::JumpTrue)
- , m_condition(condition)
- , m_target(target)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_target);
- }
- Operand condition() const { return m_condition; }
- auto& target() const { return m_target; }
- private:
- Operand m_condition;
- Label m_target;
- };
- class JumpFalse final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit JumpFalse(Operand condition, Label target)
- : Instruction(Type::JumpFalse)
- , m_condition(condition)
- , m_target(target)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_target);
- }
- Operand condition() const { return m_condition; }
- auto& target() const { return m_target; }
- private:
- Operand m_condition;
- Label m_target;
- };
- #define JS_ENUMERATE_COMPARISON_OPS(X) \
- X(LessThan, less_than) \
- X(LessThanEquals, less_than_equals) \
- X(GreaterThan, greater_than) \
- X(GreaterThanEquals, greater_than_equals) \
- X(LooselyEquals, loosely_equals) \
- X(LooselyInequals, loosely_inequals) \
- X(StrictlyEquals, strict_equals) \
- X(StrictlyInequals, strict_inequals)
- #define DECLARE_COMPARISON_OP(op_TitleCase, op_snake_case) \
- class Jump##op_TitleCase final : public Instruction { \
- public: \
- constexpr static bool IsTerminator = true; \
- \
- explicit Jump##op_TitleCase(Operand lhs, Operand rhs, Label true_target, Label false_target) \
- : Instruction(Type::Jump##op_TitleCase) \
- , m_lhs(lhs) \
- , m_rhs(rhs) \
- , m_true_target(true_target) \
- , m_false_target(false_target) \
- { \
- } \
- \
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
- ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
- void visit_labels_impl(Function<void(Label&)> visitor) \
- { \
- visitor(m_true_target); \
- visitor(m_false_target); \
- } \
- \
- Operand lhs() const { return m_lhs; } \
- Operand rhs() const { return m_rhs; } \
- auto& true_target() const { return m_true_target; } \
- auto& false_target() const { return m_false_target; } \
- \
- private: \
- Operand m_lhs; \
- Operand m_rhs; \
- Label m_true_target; \
- Label m_false_target; \
- };
- JS_ENUMERATE_COMPARISON_OPS(DECLARE_COMPARISON_OP)
- class JumpNullish final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit JumpNullish(Operand condition, Label true_target, Label false_target)
- : Instruction(Type::JumpNullish)
- , m_condition(condition)
- , m_true_target(true_target)
- , m_false_target(false_target)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_true_target);
- visitor(m_false_target);
- }
- Operand condition() const { return m_condition; }
- auto& true_target() const { return m_true_target; }
- auto& false_target() const { return m_false_target; }
- private:
- Operand m_condition;
- Label m_true_target;
- Label m_false_target;
- };
- class JumpUndefined final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit JumpUndefined(Operand condition, Label true_target, Label false_target)
- : Instruction(Type::JumpUndefined)
- , m_condition(condition)
- , m_true_target(true_target)
- , m_false_target(false_target)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_true_target);
- visitor(m_false_target);
- }
- Operand condition() const { return m_condition; }
- auto& true_target() const { return m_true_target; }
- auto& false_target() const { return m_false_target; }
- private:
- Operand m_condition;
- Label m_true_target;
- Label m_false_target;
- };
- enum class CallType : u8 {
- Call,
- Construct,
- DirectEval,
- };
- class Call final : public Instruction {
- public:
- static constexpr bool IsVariableLength = true;
- Call(CallType type, Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {}, Optional<Builtin> builtin = {})
- : Instruction(Type::Call)
- , m_dst(dst)
- , m_callee(callee)
- , m_this_value(this_value)
- , m_argument_count(arguments.size())
- , m_type(type)
- , m_builtin(builtin)
- , m_expression_string(expression_string)
- {
- for (size_t i = 0; i < arguments.size(); ++i)
- m_arguments[i] = arguments[i];
- }
- size_t length_impl() const
- {
- return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
- }
- CallType call_type() const { return m_type; }
- Operand dst() const { return m_dst; }
- Operand callee() const { return m_callee; }
- Operand this_value() const { return m_this_value; }
- Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
- u32 argument_count() const { return m_argument_count; }
- Optional<Builtin> const& builtin() const { return m_builtin; }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- private:
- Operand m_dst;
- Operand m_callee;
- Operand m_this_value;
- u32 m_argument_count { 0 };
- CallType m_type;
- Optional<Builtin> m_builtin;
- Optional<StringTableIndex> m_expression_string;
- Operand m_arguments[];
- };
- class CallWithArgumentArray final : public Instruction {
- public:
- CallWithArgumentArray(CallType type, Operand dst, Operand callee, Operand this_value, Operand arguments, Optional<StringTableIndex> expression_string = {})
- : Instruction(Type::CallWithArgumentArray)
- , m_dst(dst)
- , m_callee(callee)
- , m_this_value(this_value)
- , m_arguments(arguments)
- , m_type(type)
- , m_expression_string(expression_string)
- {
- }
- Operand dst() const { return m_dst; }
- CallType call_type() const { return m_type; }
- Operand callee() const { return m_callee; }
- Operand this_value() const { return m_this_value; }
- Operand arguments() const { return m_arguments; }
- Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- private:
- Operand m_dst;
- Operand m_callee;
- Operand m_this_value;
- Operand m_arguments;
- CallType m_type;
- Optional<StringTableIndex> m_expression_string;
- };
- class SuperCallWithArgumentArray : public Instruction {
- public:
- explicit SuperCallWithArgumentArray(Operand dst, Operand arguments, bool is_synthetic)
- : Instruction(Type::SuperCallWithArgumentArray)
- , m_dst(dst)
- , m_arguments(arguments)
- , m_is_synthetic(is_synthetic)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand arguments() const { return m_arguments; }
- bool is_synthetic() const { return m_is_synthetic; }
- private:
- Operand m_dst;
- Operand m_arguments;
- bool m_is_synthetic;
- };
- class NewClass final : public Instruction {
- public:
- explicit NewClass(Operand dst, Optional<Operand> super_class, ClassExpression const& class_expression, Optional<IdentifierTableIndex> lhs_name)
- : Instruction(Type::NewClass)
- , m_dst(dst)
- , m_super_class(super_class)
- , m_class_expression(class_expression)
- , m_lhs_name(lhs_name)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Optional<Operand> const& super_class() const { return m_super_class; }
- ClassExpression const& class_expression() const { return m_class_expression; }
- Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
- private:
- Operand m_dst;
- Optional<Operand> m_super_class;
- ClassExpression const& m_class_expression;
- Optional<IdentifierTableIndex> m_lhs_name;
- };
- class NewFunction final : public Instruction {
- public:
- explicit NewFunction(Operand dst, FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Operand> home_object = {})
- : Instruction(Type::NewFunction)
- , m_dst(dst)
- , m_function_node(function_node)
- , m_lhs_name(lhs_name)
- , m_home_object(move(home_object))
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- FunctionExpression const& function_node() const { return m_function_node; }
- Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
- Optional<Operand> const& home_object() const { return m_home_object; }
- private:
- Operand m_dst;
- FunctionExpression const& m_function_node;
- Optional<IdentifierTableIndex> m_lhs_name;
- Optional<Operand> m_home_object;
- };
- class BlockDeclarationInstantiation final : public Instruction {
- public:
- explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
- : Instruction(Type::BlockDeclarationInstantiation)
- , m_scope_node(scope_node)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- ScopeNode const& scope_node() const { return m_scope_node; }
- private:
- ScopeNode const& m_scope_node;
- };
- class Return final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit Return(Optional<Operand> value = {})
- : Instruction(Type::Return)
- , m_value(value)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Optional<Operand> const& value() const { return m_value; }
- private:
- Optional<Operand> m_value;
- };
- class Increment final : public Instruction {
- public:
- explicit Increment(Operand dst)
- : Instruction(Type::Increment)
- , m_dst(dst)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- private:
- Operand m_dst;
- };
- class PostfixIncrement final : public Instruction {
- public:
- explicit PostfixIncrement(Operand dst, Operand src)
- : Instruction(Type::PostfixIncrement)
- , m_dst(dst)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand src() const { return m_src; }
- private:
- Operand m_dst;
- Operand m_src;
- };
- class Decrement final : public Instruction {
- public:
- explicit Decrement(Operand dst)
- : Instruction(Type::Decrement)
- , m_dst(dst)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- private:
- Operand m_dst;
- };
- class PostfixDecrement final : public Instruction {
- public:
- explicit PostfixDecrement(Operand dst, Operand src)
- : Instruction(Type::PostfixDecrement)
- , m_dst(dst)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand src() const { return m_src; }
- private:
- Operand m_dst;
- Operand m_src;
- };
- class Throw final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit Throw(Operand src)
- : Instruction(Type::Throw)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand src() const { return m_src; }
- private:
- Operand m_src;
- };
- class ThrowIfNotObject final : public Instruction {
- public:
- ThrowIfNotObject(Operand src)
- : Instruction(Type::ThrowIfNotObject)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand src() const { return m_src; }
- private:
- Operand m_src;
- };
- class ThrowIfNullish final : public Instruction {
- public:
- explicit ThrowIfNullish(Operand src)
- : Instruction(Type::ThrowIfNullish)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand src() const { return m_src; }
- private:
- Operand m_src;
- };
- class ThrowIfTDZ final : public Instruction {
- public:
- explicit ThrowIfTDZ(Operand src)
- : Instruction(Type::ThrowIfTDZ)
- , m_src(src)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand src() const { return m_src; }
- private:
- Operand m_src;
- };
- class EnterUnwindContext final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- EnterUnwindContext(Label entry_point)
- : Instruction(Type::EnterUnwindContext)
- , m_entry_point(move(entry_point))
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_entry_point);
- }
- auto& entry_point() const { return m_entry_point; }
- private:
- Label m_entry_point;
- };
- 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;
- constexpr static bool IsTerminator = true;
- ScheduleJump(Label target)
- : Instruction(Type::ScheduleJump)
- , m_target(target)
- {
- }
- Label target() const { return m_target; }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_target);
- }
- private:
- Label m_target;
- };
- class LeaveLexicalEnvironment final : public Instruction {
- public:
- LeaveLexicalEnvironment()
- : Instruction(Type::LeaveLexicalEnvironment)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- };
- class LeaveUnwindContext final : public Instruction {
- public:
- LeaveUnwindContext()
- : Instruction(Type::LeaveUnwindContext)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- };
- class ContinuePendingUnwind final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit ContinuePendingUnwind(Label resume_target)
- : Instruction(Type::ContinuePendingUnwind)
- , m_resume_target(resume_target)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_resume_target);
- }
- auto& resume_target() const { return m_resume_target; }
- private:
- Label m_resume_target;
- };
- class Yield final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit Yield(Label continuation_label, Operand value)
- : Instruction(Type::Yield)
- , m_continuation_label(continuation_label)
- , m_value(value)
- {
- }
- explicit Yield(nullptr_t, Operand value)
- : Instruction(Type::Yield)
- , m_value(value)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- if (m_continuation_label.has_value())
- visitor(m_continuation_label.value());
- }
- auto& continuation() const { return m_continuation_label; }
- Operand value() const { return m_value; }
- private:
- Optional<Label> m_continuation_label;
- Operand m_value;
- };
- class Await final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit Await(Label continuation_label, Operand argument)
- : Instruction(Type::Await)
- , m_continuation_label(continuation_label)
- , m_argument(argument)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- void visit_labels_impl(Function<void(Label&)> visitor)
- {
- visitor(m_continuation_label);
- }
- auto& continuation() const { return m_continuation_label; }
- Operand argument() const { return m_argument; }
- private:
- Label m_continuation_label;
- Operand m_argument;
- };
- class GetIterator final : public Instruction {
- public:
- GetIterator(Operand dst, Operand iterable, IteratorHint hint = IteratorHint::Sync)
- : Instruction(Type::GetIterator)
- , m_dst(dst)
- , m_iterable(iterable)
- , m_hint(hint)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand iterable() const { return m_iterable; }
- IteratorHint hint() const { return m_hint; }
- private:
- Operand m_dst;
- Operand m_iterable;
- IteratorHint m_hint { IteratorHint::Sync };
- };
- class GetObjectFromIteratorRecord final : public Instruction {
- public:
- GetObjectFromIteratorRecord(Operand object, Operand iterator_record)
- : Instruction(Type::GetObjectFromIteratorRecord)
- , m_object(object)
- , m_iterator_record(iterator_record)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand object() const { return m_object; }
- Operand iterator_record() const { return m_iterator_record; }
- private:
- Operand m_object;
- Operand m_iterator_record;
- };
- class GetNextMethodFromIteratorRecord final : public Instruction {
- public:
- GetNextMethodFromIteratorRecord(Operand next_method, Operand iterator_record)
- : Instruction(Type::GetNextMethodFromIteratorRecord)
- , m_next_method(next_method)
- , m_iterator_record(iterator_record)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand next_method() const { return m_next_method; }
- Operand iterator_record() const { return m_iterator_record; }
- private:
- Operand m_next_method;
- Operand m_iterator_record;
- };
- class GetMethod final : public Instruction {
- public:
- GetMethod(Operand dst, Operand object, IdentifierTableIndex property)
- : Instruction(Type::GetMethod)
- , m_dst(dst)
- , m_object(object)
- , m_property(property)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand object() const { return m_object; }
- IdentifierTableIndex property() const { return m_property; }
- private:
- Operand m_dst;
- Operand m_object;
- IdentifierTableIndex m_property;
- };
- class GetObjectPropertyIterator final : public Instruction {
- public:
- GetObjectPropertyIterator(Operand dst, Operand object)
- : Instruction(Type::GetObjectPropertyIterator)
- , m_dst(dst)
- , m_object(object)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand object() const { return m_object; }
- private:
- Operand m_dst;
- Operand m_object;
- };
- class IteratorClose final : public Instruction {
- public:
- IteratorClose(Operand iterator_record, Completion::Type completion_type, Optional<Value> completion_value)
- : Instruction(Type::IteratorClose)
- , m_iterator_record(iterator_record)
- , m_completion_type(completion_type)
- , m_completion_value(completion_value)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand iterator_record() const { return m_iterator_record; }
- Completion::Type completion_type() const { return m_completion_type; }
- Optional<Value> const& completion_value() const { return m_completion_value; }
- private:
- Operand m_iterator_record;
- Completion::Type m_completion_type { Completion::Type::Normal };
- Optional<Value> m_completion_value;
- };
- class AsyncIteratorClose final : public Instruction {
- public:
- AsyncIteratorClose(Operand iterator_record, Completion::Type completion_type, Optional<Value> completion_value)
- : Instruction(Type::AsyncIteratorClose)
- , m_iterator_record(iterator_record)
- , m_completion_type(completion_type)
- , m_completion_value(completion_value)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand iterator_record() const { return m_iterator_record; }
- Completion::Type completion_type() const { return m_completion_type; }
- Optional<Value> const& completion_value() const { return m_completion_value; }
- private:
- Operand m_iterator_record;
- Completion::Type m_completion_type { Completion::Type::Normal };
- Optional<Value> m_completion_value;
- };
- class IteratorNext final : public Instruction {
- public:
- IteratorNext(Operand dst, Operand iterator_record)
- : Instruction(Type::IteratorNext)
- , m_dst(dst)
- , m_iterator_record(iterator_record)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- Operand iterator_record() const { return m_iterator_record; }
- private:
- Operand m_dst;
- Operand m_iterator_record;
- };
- class ResolveThisBinding final : public Instruction {
- public:
- explicit ResolveThisBinding(Operand dst)
- : Instruction(Type::ResolveThisBinding)
- , m_dst(dst)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- private:
- Operand m_dst;
- };
- class ResolveSuperBase final : public Instruction {
- public:
- explicit ResolveSuperBase(Operand dst)
- : Instruction(Type::ResolveSuperBase)
- , m_dst(dst)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- private:
- Operand m_dst;
- };
- class GetNewTarget final : public Instruction {
- public:
- explicit GetNewTarget(Operand dst)
- : Instruction(Type::GetNewTarget)
- , m_dst(dst)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- private:
- Operand m_dst;
- };
- class GetImportMeta final : public Instruction {
- public:
- explicit GetImportMeta(Operand dst)
- : Instruction(Type::GetImportMeta)
- , m_dst(dst)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- private:
- Operand m_dst;
- };
- class TypeofVariable final : public Instruction {
- public:
- TypeofVariable(Operand dst, IdentifierTableIndex identifier)
- : Instruction(Type::TypeofVariable)
- , m_dst(dst)
- , m_identifier(identifier)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand dst() const { return m_dst; }
- IdentifierTableIndex identifier() const { return m_identifier; }
- private:
- Operand m_dst;
- IdentifierTableIndex m_identifier;
- };
- class End final : public Instruction {
- public:
- constexpr static bool IsTerminator = true;
- explicit End(Operand value)
- : Instruction(Type::End)
- , m_value(value)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- Operand value() const { return m_value; }
- private:
- Operand m_value;
- };
- class Dump final : public Instruction {
- public:
- explicit Dump(StringView text, Operand value)
- : Instruction(Type::Dump)
- , m_text(text)
- , m_value(value)
- {
- }
- ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
- ByteString to_byte_string_impl(Bytecode::Executable const&) const;
- private:
- StringView m_text;
- Operand m_value;
- };
- }
|