Op.h 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859
  1. /*
  2. * Copyright (c) 2021-2023, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/FixedArray.h>
  10. #include <AK/StdLibExtras.h>
  11. #include <LibCrypto/BigInt/SignedBigInteger.h>
  12. #include <LibJS/Bytecode/Builtins.h>
  13. #include <LibJS/Bytecode/IdentifierTable.h>
  14. #include <LibJS/Bytecode/Instruction.h>
  15. #include <LibJS/Bytecode/Label.h>
  16. #include <LibJS/Bytecode/Operand.h>
  17. #include <LibJS/Bytecode/RegexTable.h>
  18. #include <LibJS/Bytecode/Register.h>
  19. #include <LibJS/Bytecode/ScopedOperand.h>
  20. #include <LibJS/Bytecode/StringTable.h>
  21. #include <LibJS/Heap/Cell.h>
  22. #include <LibJS/Runtime/Environment.h>
  23. #include <LibJS/Runtime/Iterator.h>
  24. #include <LibJS/Runtime/Value.h>
  25. #include <LibJS/Runtime/ValueTraits.h>
  26. namespace JS {
  27. class FunctionExpression;
  28. }
  29. namespace JS::Bytecode::Op {
  30. class CreateRestParams final : public Instruction {
  31. public:
  32. CreateRestParams(Operand dst, u32 rest_index)
  33. : Instruction(Type::CreateRestParams)
  34. , m_dst(dst)
  35. , m_rest_index(rest_index)
  36. {
  37. }
  38. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  39. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  40. void visit_operands_impl(Function<void(Operand&)> visitor)
  41. {
  42. visitor(m_dst);
  43. }
  44. private:
  45. Operand m_dst;
  46. u32 m_rest_index;
  47. };
  48. class CreateArguments final : public Instruction {
  49. public:
  50. enum class Kind {
  51. Mapped,
  52. Unmapped,
  53. };
  54. CreateArguments(Optional<Operand> dst, Kind kind, bool is_immutable)
  55. : Instruction(Type::CreateArguments)
  56. , m_dst(dst)
  57. , m_kind(kind)
  58. , m_is_immutable(is_immutable)
  59. {
  60. }
  61. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  62. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  63. void visit_operands_impl(Function<void(Operand&)> visitor)
  64. {
  65. if (m_dst.has_value())
  66. visitor(m_dst.value());
  67. }
  68. private:
  69. Optional<Operand> m_dst;
  70. Kind m_kind;
  71. bool m_is_immutable { false };
  72. };
  73. class Mov final : public Instruction {
  74. public:
  75. Mov(Operand dst, Operand src)
  76. : Instruction(Type::Mov)
  77. , m_dst(dst)
  78. , m_src(src)
  79. {
  80. }
  81. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  82. void visit_operands_impl(Function<void(Operand&)> visitor)
  83. {
  84. visitor(m_dst);
  85. visitor(m_src);
  86. }
  87. Operand dst() const { return m_dst; }
  88. Operand src() const { return m_src; }
  89. private:
  90. Operand m_dst;
  91. Operand m_src;
  92. };
  93. #define JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(O) \
  94. O(Add, add) \
  95. O(BitwiseAnd, bitwise_and) \
  96. O(BitwiseOr, bitwise_or) \
  97. O(BitwiseXor, bitwise_xor) \
  98. O(GreaterThan, greater_than) \
  99. O(GreaterThanEquals, greater_than_equals) \
  100. O(LeftShift, left_shift) \
  101. O(LessThan, less_than) \
  102. O(LessThanEquals, less_than_equals) \
  103. O(Mul, mul) \
  104. O(RightShift, right_shift) \
  105. O(Sub, sub) \
  106. O(UnsignedRightShift, unsigned_right_shift)
  107. #define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \
  108. O(Div, div) \
  109. O(Exp, exp) \
  110. O(Mod, mod) \
  111. O(In, in) \
  112. O(InstanceOf, instance_of) \
  113. O(LooselyInequals, loosely_inequals) \
  114. O(LooselyEquals, loosely_equals) \
  115. O(StrictlyInequals, strict_inequals) \
  116. O(StrictlyEquals, strict_equals)
  117. #define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
  118. class OpTitleCase final : public Instruction { \
  119. public: \
  120. explicit OpTitleCase(Operand dst, Operand lhs, Operand rhs) \
  121. : Instruction(Type::OpTitleCase) \
  122. , m_dst(dst) \
  123. , m_lhs(lhs) \
  124. , m_rhs(rhs) \
  125. { \
  126. } \
  127. \
  128. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  129. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  130. void visit_operands_impl(Function<void(Operand&)> visitor) \
  131. { \
  132. visitor(m_dst); \
  133. visitor(m_lhs); \
  134. visitor(m_rhs); \
  135. } \
  136. \
  137. Operand dst() const { return m_dst; } \
  138. Operand lhs() const { return m_lhs; } \
  139. Operand rhs() const { return m_rhs; } \
  140. \
  141. private: \
  142. Operand m_dst; \
  143. Operand m_lhs; \
  144. Operand m_rhs; \
  145. };
  146. JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(JS_DECLARE_COMMON_BINARY_OP)
  147. JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(JS_DECLARE_COMMON_BINARY_OP)
  148. #undef JS_DECLARE_COMMON_BINARY_OP
  149. #define JS_ENUMERATE_COMMON_UNARY_OPS(O) \
  150. O(BitwiseNot, bitwise_not) \
  151. O(Not, not_) \
  152. O(UnaryPlus, unary_plus) \
  153. O(UnaryMinus, unary_minus) \
  154. O(Typeof, typeof_)
  155. #define JS_DECLARE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
  156. class OpTitleCase final : public Instruction { \
  157. public: \
  158. OpTitleCase(Operand dst, Operand src) \
  159. : Instruction(Type::OpTitleCase) \
  160. , m_dst(dst) \
  161. , m_src(src) \
  162. { \
  163. } \
  164. \
  165. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  166. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  167. void visit_operands_impl(Function<void(Operand&)> visitor) \
  168. { \
  169. visitor(m_dst); \
  170. visitor(m_src); \
  171. } \
  172. \
  173. Operand dst() const { return m_dst; } \
  174. Operand src() const { return m_src; } \
  175. \
  176. private: \
  177. Operand m_dst; \
  178. Operand m_src; \
  179. };
  180. JS_ENUMERATE_COMMON_UNARY_OPS(JS_DECLARE_COMMON_UNARY_OP)
  181. #undef JS_DECLARE_COMMON_UNARY_OP
  182. class NewObject final : public Instruction {
  183. public:
  184. explicit NewObject(Operand dst)
  185. : Instruction(Type::NewObject)
  186. , m_dst(dst)
  187. {
  188. }
  189. void execute_impl(Bytecode::Interpreter&) const;
  190. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  191. void visit_operands_impl(Function<void(Operand&)> visitor)
  192. {
  193. visitor(m_dst);
  194. }
  195. Operand dst() const { return m_dst; }
  196. private:
  197. Operand m_dst;
  198. };
  199. class NewRegExp final : public Instruction {
  200. public:
  201. NewRegExp(Operand dst, StringTableIndex source_index, StringTableIndex flags_index, RegexTableIndex regex_index)
  202. : Instruction(Type::NewRegExp)
  203. , m_dst(dst)
  204. , m_source_index(source_index)
  205. , m_flags_index(flags_index)
  206. , m_regex_index(regex_index)
  207. {
  208. }
  209. void execute_impl(Bytecode::Interpreter&) const;
  210. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  211. void visit_operands_impl(Function<void(Operand&)> visitor)
  212. {
  213. visitor(m_dst);
  214. }
  215. Operand dst() const { return m_dst; }
  216. StringTableIndex source_index() const { return m_source_index; }
  217. StringTableIndex flags_index() const { return m_flags_index; }
  218. RegexTableIndex regex_index() const { return m_regex_index; }
  219. private:
  220. Operand m_dst;
  221. StringTableIndex m_source_index;
  222. StringTableIndex m_flags_index;
  223. RegexTableIndex m_regex_index;
  224. };
  225. #define JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(O) \
  226. O(TypeError)
  227. #define JS_DECLARE_NEW_BUILTIN_ERROR_OP(ErrorName) \
  228. class New##ErrorName final : public Instruction { \
  229. public: \
  230. New##ErrorName(Operand dst, StringTableIndex error_string) \
  231. : Instruction(Type::New##ErrorName) \
  232. , m_dst(dst) \
  233. , m_error_string(error_string) \
  234. { \
  235. } \
  236. \
  237. void execute_impl(Bytecode::Interpreter&) const; \
  238. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  239. void visit_operands_impl(Function<void(Operand&)> visitor) \
  240. { \
  241. visitor(m_dst); \
  242. } \
  243. \
  244. Operand dst() const { return m_dst; } \
  245. StringTableIndex error_string() const { return m_error_string; } \
  246. \
  247. private: \
  248. Operand m_dst; \
  249. StringTableIndex m_error_string; \
  250. };
  251. JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DECLARE_NEW_BUILTIN_ERROR_OP)
  252. #undef JS_DECLARE_NEW_BUILTIN_ERROR_OP
  253. // NOTE: This instruction is variable-width depending on the number of excluded names
  254. class CopyObjectExcludingProperties final : public Instruction {
  255. public:
  256. static constexpr bool IsVariableLength = true;
  257. CopyObjectExcludingProperties(Operand dst, Operand from_object, Vector<ScopedOperand> const& excluded_names)
  258. : Instruction(Type::CopyObjectExcludingProperties)
  259. , m_dst(dst)
  260. , m_from_object(from_object)
  261. , m_excluded_names_count(excluded_names.size())
  262. {
  263. for (size_t i = 0; i < m_excluded_names_count; i++)
  264. m_excluded_names[i] = excluded_names[i];
  265. }
  266. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  267. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  268. void visit_operands_impl(Function<void(Operand&)> visitor)
  269. {
  270. visitor(m_dst);
  271. visitor(m_from_object);
  272. for (size_t i = 0; i < m_excluded_names_count; i++)
  273. visitor(m_excluded_names[i]);
  274. }
  275. size_t length_impl() const
  276. {
  277. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_excluded_names_count);
  278. }
  279. Operand dst() const { return m_dst; }
  280. Operand from_object() const { return m_from_object; }
  281. size_t excluded_names_count() const { return m_excluded_names_count; }
  282. Operand const* excluded_names() const { return m_excluded_names; }
  283. private:
  284. Operand m_dst;
  285. Operand m_from_object;
  286. size_t m_excluded_names_count { 0 };
  287. Operand m_excluded_names[];
  288. };
  289. // NOTE: This instruction is variable-width depending on the number of elements!
  290. class NewArray final : public Instruction {
  291. public:
  292. static constexpr bool IsVariableLength = true;
  293. explicit NewArray(Operand dst)
  294. : Instruction(Type::NewArray)
  295. , m_dst(dst)
  296. , m_element_count(0)
  297. {
  298. }
  299. NewArray(Operand dst, ReadonlySpan<ScopedOperand> elements)
  300. : Instruction(Type::NewArray)
  301. , m_dst(dst)
  302. , m_element_count(elements.size())
  303. {
  304. for (size_t i = 0; i < m_element_count; ++i)
  305. m_elements[i] = elements[i];
  306. }
  307. void execute_impl(Bytecode::Interpreter&) const;
  308. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  309. void visit_operands_impl(Function<void(Operand&)> visitor)
  310. {
  311. visitor(m_dst);
  312. for (size_t i = 0; i < m_element_count; i++)
  313. visitor(m_elements[i]);
  314. }
  315. Operand dst() const { return m_dst; }
  316. size_t length_impl() const
  317. {
  318. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_element_count);
  319. }
  320. size_t element_count() const { return m_element_count; }
  321. private:
  322. Operand m_dst;
  323. size_t m_element_count { 0 };
  324. Operand m_elements[];
  325. };
  326. class NewPrimitiveArray final : public Instruction {
  327. public:
  328. static constexpr bool IsVariableLength = true;
  329. NewPrimitiveArray(Operand dst, ReadonlySpan<Value> elements)
  330. : Instruction(Type::NewPrimitiveArray)
  331. , m_dst(dst)
  332. , m_element_count(elements.size())
  333. {
  334. for (size_t i = 0; i < m_element_count; ++i)
  335. m_elements[i] = elements[i];
  336. }
  337. size_t length_impl() const
  338. {
  339. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Value) * m_element_count);
  340. }
  341. void execute_impl(Bytecode::Interpreter&) const;
  342. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  343. void visit_operands_impl(Function<void(Operand&)> visitor)
  344. {
  345. visitor(m_dst);
  346. }
  347. Operand dst() const { return m_dst; }
  348. ReadonlySpan<Value> elements() const { return { m_elements, m_element_count }; }
  349. private:
  350. Operand m_dst;
  351. size_t m_element_count { 0 };
  352. Value m_elements[];
  353. };
  354. class AddPrivateName final : public Instruction {
  355. public:
  356. explicit AddPrivateName(IdentifierTableIndex name)
  357. : Instruction(Type::AddPrivateName)
  358. , m_name(name)
  359. {
  360. }
  361. void execute_impl(Bytecode::Interpreter&) const;
  362. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  363. private:
  364. IdentifierTableIndex m_name;
  365. };
  366. class ArrayAppend final : public Instruction {
  367. public:
  368. ArrayAppend(Operand dst, Operand src, bool is_spread)
  369. : Instruction(Type::ArrayAppend)
  370. , m_dst(dst)
  371. , m_src(src)
  372. , m_is_spread(is_spread)
  373. {
  374. }
  375. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  376. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  377. void visit_operands_impl(Function<void(Operand&)> visitor)
  378. {
  379. visitor(m_dst);
  380. visitor(m_src);
  381. }
  382. Operand dst() const { return m_dst; }
  383. Operand src() const { return m_src; }
  384. bool is_spread() const { return m_is_spread; }
  385. private:
  386. Operand m_dst;
  387. Operand m_src;
  388. bool m_is_spread = false;
  389. };
  390. class ImportCall final : public Instruction {
  391. public:
  392. ImportCall(Operand dst, Operand specifier, Operand options)
  393. : Instruction(Type::ImportCall)
  394. , m_dst(dst)
  395. , m_specifier(specifier)
  396. , m_options(options)
  397. {
  398. }
  399. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  400. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  401. void visit_operands_impl(Function<void(Operand&)> visitor)
  402. {
  403. visitor(m_dst);
  404. visitor(m_specifier);
  405. visitor(m_options);
  406. }
  407. Operand dst() const { return m_dst; }
  408. Operand specifier() const { return m_specifier; }
  409. Operand options() const { return m_options; }
  410. private:
  411. Operand m_dst;
  412. Operand m_specifier;
  413. Operand m_options;
  414. };
  415. class IteratorToArray final : public Instruction {
  416. public:
  417. explicit IteratorToArray(Operand dst, Operand iterator)
  418. : Instruction(Type::IteratorToArray)
  419. , m_dst(dst)
  420. , m_iterator(iterator)
  421. {
  422. }
  423. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  424. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  425. Operand dst() const { return m_dst; }
  426. Operand iterator() const { return m_iterator; }
  427. void visit_operands_impl(Function<void(Operand&)> visitor)
  428. {
  429. visitor(m_dst);
  430. visitor(m_iterator);
  431. }
  432. private:
  433. Operand m_dst;
  434. Operand m_iterator;
  435. };
  436. class ConcatString final : public Instruction {
  437. public:
  438. explicit ConcatString(Operand dst, Operand src)
  439. : Instruction(Type::ConcatString)
  440. , m_dst(dst)
  441. , m_src(src)
  442. {
  443. }
  444. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  445. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  446. Operand dst() const { return m_dst; }
  447. Operand src() const { return m_src; }
  448. void visit_operands_impl(Function<void(Operand&)> visitor)
  449. {
  450. visitor(m_dst);
  451. visitor(m_src);
  452. }
  453. private:
  454. Operand m_dst;
  455. Operand m_src;
  456. };
  457. enum class EnvironmentMode {
  458. Lexical,
  459. Var,
  460. };
  461. enum class BindingInitializationMode {
  462. Initialize,
  463. Set,
  464. };
  465. class CreateLexicalEnvironment final : public Instruction {
  466. public:
  467. explicit CreateLexicalEnvironment(u32 capacity = 0)
  468. : Instruction(Type::CreateLexicalEnvironment)
  469. , m_capacity(capacity)
  470. {
  471. }
  472. void execute_impl(Bytecode::Interpreter&) const;
  473. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  474. private:
  475. u32 m_capacity { 0 };
  476. };
  477. class CreateVariableEnvironment final : public Instruction {
  478. public:
  479. explicit CreateVariableEnvironment(u32 capacity = 0)
  480. : Instruction(Type::CreateVariableEnvironment)
  481. , m_capacity(capacity)
  482. {
  483. }
  484. void execute_impl(Bytecode::Interpreter&) const;
  485. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  486. private:
  487. u32 m_capacity { 0 };
  488. };
  489. class CreatePrivateEnvironment final : public Instruction {
  490. public:
  491. explicit CreatePrivateEnvironment()
  492. : Instruction(Type::CreatePrivateEnvironment)
  493. {
  494. }
  495. void execute_impl(Bytecode::Interpreter&) const;
  496. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  497. };
  498. class EnterObjectEnvironment final : public Instruction {
  499. public:
  500. explicit EnterObjectEnvironment(Operand object)
  501. : Instruction(Type::EnterObjectEnvironment)
  502. , m_object(object)
  503. {
  504. }
  505. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  506. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  507. Operand object() const { return m_object; }
  508. void visit_operands_impl(Function<void(Operand&)> visitor)
  509. {
  510. visitor(m_object);
  511. }
  512. private:
  513. Operand m_object;
  514. };
  515. class Catch final : public Instruction {
  516. public:
  517. explicit Catch(Operand dst)
  518. : Instruction(Type::Catch)
  519. , m_dst(dst)
  520. {
  521. }
  522. void execute_impl(Bytecode::Interpreter&) const;
  523. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  524. Operand dst() const { return m_dst; }
  525. void visit_operands_impl(Function<void(Operand&)> visitor)
  526. {
  527. visitor(m_dst);
  528. }
  529. private:
  530. Operand m_dst;
  531. };
  532. class LeaveFinally final : public Instruction {
  533. public:
  534. explicit LeaveFinally()
  535. : Instruction(Type::LeaveFinally)
  536. {
  537. }
  538. void execute_impl(Bytecode::Interpreter&) const;
  539. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  540. };
  541. class RestoreScheduledJump final : public Instruction {
  542. public:
  543. explicit RestoreScheduledJump()
  544. : Instruction(Type::RestoreScheduledJump)
  545. {
  546. }
  547. void execute_impl(Bytecode::Interpreter&) const;
  548. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  549. };
  550. class CreateVariable final : public Instruction {
  551. public:
  552. explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false, bool is_strict = false)
  553. : Instruction(Type::CreateVariable)
  554. , m_identifier(identifier)
  555. , m_mode(mode)
  556. , m_is_immutable(is_immutable)
  557. , m_is_global(is_global)
  558. , m_is_strict(is_strict)
  559. {
  560. }
  561. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  562. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  563. IdentifierTableIndex identifier() const { return m_identifier; }
  564. EnvironmentMode mode() const { return m_mode; }
  565. bool is_immutable() const { return m_is_immutable; }
  566. bool is_global() const { return m_is_global; }
  567. bool is_strict() const { return m_is_strict; }
  568. private:
  569. IdentifierTableIndex m_identifier;
  570. EnvironmentMode m_mode;
  571. bool m_is_immutable : 4 { false };
  572. bool m_is_global : 4 { false };
  573. bool m_is_strict { false };
  574. };
  575. class InitializeLexicalBinding final : public Instruction {
  576. public:
  577. explicit InitializeLexicalBinding(IdentifierTableIndex identifier, Operand src)
  578. : Instruction(Type::InitializeLexicalBinding)
  579. , m_identifier(identifier)
  580. , m_src(src)
  581. {
  582. }
  583. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  584. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  585. void visit_operands_impl(Function<void(Operand&)> visitor)
  586. {
  587. visitor(m_src);
  588. }
  589. IdentifierTableIndex identifier() const { return m_identifier; }
  590. Operand src() const { return m_src; }
  591. private:
  592. IdentifierTableIndex m_identifier;
  593. Operand m_src;
  594. mutable EnvironmentCoordinate m_cache;
  595. };
  596. class InitializeVariableBinding final : public Instruction {
  597. public:
  598. explicit InitializeVariableBinding(IdentifierTableIndex identifier, Operand src)
  599. : Instruction(Type::InitializeVariableBinding)
  600. , m_identifier(identifier)
  601. , m_src(src)
  602. {
  603. }
  604. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  605. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  606. void visit_operands_impl(Function<void(Operand&)> visitor)
  607. {
  608. visitor(m_src);
  609. }
  610. IdentifierTableIndex identifier() const { return m_identifier; }
  611. Operand src() const { return m_src; }
  612. private:
  613. IdentifierTableIndex m_identifier;
  614. Operand m_src;
  615. mutable EnvironmentCoordinate m_cache;
  616. };
  617. class SetLexicalBinding final : public Instruction {
  618. public:
  619. explicit SetLexicalBinding(IdentifierTableIndex identifier, Operand src)
  620. : Instruction(Type::SetLexicalBinding)
  621. , m_identifier(identifier)
  622. , m_src(src)
  623. {
  624. }
  625. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  626. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  627. void visit_operands_impl(Function<void(Operand&)> visitor)
  628. {
  629. visitor(m_src);
  630. }
  631. IdentifierTableIndex identifier() const { return m_identifier; }
  632. Operand src() const { return m_src; }
  633. private:
  634. IdentifierTableIndex m_identifier;
  635. Operand m_src;
  636. mutable EnvironmentCoordinate m_cache;
  637. };
  638. class SetVariableBinding final : public Instruction {
  639. public:
  640. explicit SetVariableBinding(IdentifierTableIndex identifier, Operand src)
  641. : Instruction(Type::SetVariableBinding)
  642. , m_identifier(identifier)
  643. , m_src(src)
  644. {
  645. }
  646. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  647. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  648. void visit_operands_impl(Function<void(Operand&)> visitor)
  649. {
  650. visitor(m_src);
  651. }
  652. IdentifierTableIndex identifier() const { return m_identifier; }
  653. Operand src() const { return m_src; }
  654. private:
  655. IdentifierTableIndex m_identifier;
  656. Operand m_src;
  657. mutable EnvironmentCoordinate m_cache;
  658. };
  659. class SetArgument final : public Instruction {
  660. public:
  661. SetArgument(size_t index, Operand src)
  662. : Instruction(Type::SetArgument)
  663. , m_index(index)
  664. , m_src(src)
  665. {
  666. }
  667. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  668. void visit_operands_impl(Function<void(Operand&)> visitor)
  669. {
  670. visitor(m_src);
  671. }
  672. size_t index() const { return m_index; }
  673. Operand src() const { return m_src; }
  674. private:
  675. u32 m_index;
  676. Operand m_src;
  677. };
  678. class GetArgument final : public Instruction {
  679. public:
  680. GetArgument(Operand dst, size_t index)
  681. : Instruction(Type::GetArgument)
  682. , m_index(index)
  683. , m_dst(dst)
  684. {
  685. }
  686. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  687. void visit_operands_impl(Function<void(Operand&)> visitor)
  688. {
  689. visitor(m_dst);
  690. }
  691. u32 index() const { return m_index; }
  692. Operand dst() const { return m_dst; }
  693. private:
  694. u32 m_index;
  695. Operand m_dst;
  696. };
  697. class GetCalleeAndThisFromEnvironment final : public Instruction {
  698. public:
  699. explicit GetCalleeAndThisFromEnvironment(Operand callee, Operand this_value, IdentifierTableIndex identifier)
  700. : Instruction(Type::GetCalleeAndThisFromEnvironment)
  701. , m_identifier(identifier)
  702. , m_callee(callee)
  703. , m_this_value(this_value)
  704. {
  705. }
  706. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  707. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  708. void visit_operands_impl(Function<void(Operand&)> visitor)
  709. {
  710. visitor(m_callee);
  711. visitor(m_this_value);
  712. }
  713. IdentifierTableIndex identifier() const { return m_identifier; }
  714. Operand callee() const { return m_callee; }
  715. Operand this_() const { return m_this_value; }
  716. private:
  717. IdentifierTableIndex m_identifier;
  718. Operand m_callee;
  719. Operand m_this_value;
  720. mutable EnvironmentCoordinate m_cache;
  721. };
  722. class GetBinding final : public Instruction {
  723. public:
  724. explicit GetBinding(Operand dst, IdentifierTableIndex identifier)
  725. : Instruction(Type::GetBinding)
  726. , m_dst(dst)
  727. , m_identifier(identifier)
  728. {
  729. }
  730. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  731. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  732. Operand dst() const { return m_dst; }
  733. IdentifierTableIndex identifier() const { return m_identifier; }
  734. void visit_operands_impl(Function<void(Operand&)> visitor)
  735. {
  736. visitor(m_dst);
  737. }
  738. private:
  739. Operand m_dst;
  740. IdentifierTableIndex m_identifier;
  741. mutable EnvironmentCoordinate m_cache;
  742. };
  743. class GetGlobal final : public Instruction {
  744. public:
  745. GetGlobal(Operand dst, IdentifierTableIndex identifier, u32 cache_index)
  746. : Instruction(Type::GetGlobal)
  747. , m_dst(dst)
  748. , m_identifier(identifier)
  749. , m_cache_index(cache_index)
  750. {
  751. }
  752. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  753. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  754. Operand dst() const { return m_dst; }
  755. IdentifierTableIndex identifier() const { return m_identifier; }
  756. u32 cache_index() const { return m_cache_index; }
  757. void visit_operands_impl(Function<void(Operand&)> visitor)
  758. {
  759. visitor(m_dst);
  760. }
  761. private:
  762. Operand m_dst;
  763. IdentifierTableIndex m_identifier;
  764. u32 m_cache_index { 0 };
  765. };
  766. class DeleteVariable final : public Instruction {
  767. public:
  768. explicit DeleteVariable(Operand dst, IdentifierTableIndex identifier)
  769. : Instruction(Type::DeleteVariable)
  770. , m_dst(dst)
  771. , m_identifier(identifier)
  772. {
  773. }
  774. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  775. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  776. Operand dst() const { return m_dst; }
  777. IdentifierTableIndex identifier() const { return m_identifier; }
  778. void visit_operands_impl(Function<void(Operand&)> visitor)
  779. {
  780. visitor(m_dst);
  781. }
  782. private:
  783. Operand m_dst;
  784. IdentifierTableIndex m_identifier;
  785. };
  786. class GetById final : public Instruction {
  787. public:
  788. GetById(Operand dst, Operand base, IdentifierTableIndex property, Optional<IdentifierTableIndex> base_identifier, u32 cache_index)
  789. : Instruction(Type::GetById)
  790. , m_dst(dst)
  791. , m_base(base)
  792. , m_property(property)
  793. , m_base_identifier(move(base_identifier))
  794. , m_cache_index(cache_index)
  795. {
  796. }
  797. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  798. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  799. void visit_operands_impl(Function<void(Operand&)> visitor)
  800. {
  801. visitor(m_dst);
  802. visitor(m_base);
  803. }
  804. Operand dst() const { return m_dst; }
  805. Operand base() const { return m_base; }
  806. IdentifierTableIndex property() const { return m_property; }
  807. u32 cache_index() const { return m_cache_index; }
  808. private:
  809. Operand m_dst;
  810. Operand m_base;
  811. IdentifierTableIndex m_property;
  812. Optional<IdentifierTableIndex> m_base_identifier;
  813. u32 m_cache_index { 0 };
  814. };
  815. class GetByIdWithThis final : public Instruction {
  816. public:
  817. GetByIdWithThis(Operand dst, Operand base, IdentifierTableIndex property, Operand this_value, u32 cache_index)
  818. : Instruction(Type::GetByIdWithThis)
  819. , m_dst(dst)
  820. , m_base(base)
  821. , m_property(property)
  822. , m_this_value(this_value)
  823. , m_cache_index(cache_index)
  824. {
  825. }
  826. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  827. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  828. void visit_operands_impl(Function<void(Operand&)> visitor)
  829. {
  830. visitor(m_dst);
  831. visitor(m_base);
  832. visitor(m_this_value);
  833. }
  834. Operand dst() const { return m_dst; }
  835. Operand base() const { return m_base; }
  836. IdentifierTableIndex property() const { return m_property; }
  837. Operand this_value() const { return m_this_value; }
  838. u32 cache_index() const { return m_cache_index; }
  839. private:
  840. Operand m_dst;
  841. Operand m_base;
  842. IdentifierTableIndex m_property;
  843. Operand m_this_value;
  844. u32 m_cache_index { 0 };
  845. };
  846. class GetLength final : public Instruction {
  847. public:
  848. GetLength(Operand dst, Operand base, Optional<IdentifierTableIndex> base_identifier, u32 cache_index)
  849. : Instruction(Type::GetLength)
  850. , m_dst(dst)
  851. , m_base(base)
  852. , m_base_identifier(move(base_identifier))
  853. , m_cache_index(cache_index)
  854. {
  855. }
  856. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  857. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  858. void visit_operands_impl(Function<void(Operand&)> visitor)
  859. {
  860. visitor(m_dst);
  861. visitor(m_base);
  862. }
  863. Operand dst() const { return m_dst; }
  864. Operand base() const { return m_base; }
  865. u32 cache_index() const { return m_cache_index; }
  866. private:
  867. Operand m_dst;
  868. Operand m_base;
  869. Optional<IdentifierTableIndex> m_base_identifier;
  870. u32 m_cache_index { 0 };
  871. };
  872. class GetLengthWithThis final : public Instruction {
  873. public:
  874. GetLengthWithThis(Operand dst, Operand base, Operand this_value, u32 cache_index)
  875. : Instruction(Type::GetLengthWithThis)
  876. , m_dst(dst)
  877. , m_base(base)
  878. , m_this_value(this_value)
  879. , m_cache_index(cache_index)
  880. {
  881. }
  882. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  883. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  884. void visit_operands_impl(Function<void(Operand&)> visitor)
  885. {
  886. visitor(m_dst);
  887. visitor(m_base);
  888. visitor(m_this_value);
  889. }
  890. Operand dst() const { return m_dst; }
  891. Operand base() const { return m_base; }
  892. Operand this_value() const { return m_this_value; }
  893. u32 cache_index() const { return m_cache_index; }
  894. private:
  895. Operand m_dst;
  896. Operand m_base;
  897. Operand m_this_value;
  898. u32 m_cache_index { 0 };
  899. };
  900. class GetPrivateById final : public Instruction {
  901. public:
  902. explicit GetPrivateById(Operand dst, Operand base, IdentifierTableIndex property)
  903. : Instruction(Type::GetPrivateById)
  904. , m_dst(dst)
  905. , m_base(base)
  906. , m_property(property)
  907. {
  908. }
  909. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  910. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  911. void visit_operands_impl(Function<void(Operand&)> visitor)
  912. {
  913. visitor(m_dst);
  914. visitor(m_base);
  915. }
  916. Operand dst() const { return m_dst; }
  917. Operand base() const { return m_base; }
  918. IdentifierTableIndex property() const { return m_property; }
  919. private:
  920. Operand m_dst;
  921. Operand m_base;
  922. IdentifierTableIndex m_property;
  923. };
  924. class HasPrivateId final : public Instruction {
  925. public:
  926. HasPrivateId(Operand dst, Operand base, IdentifierTableIndex property)
  927. : Instruction(Type::HasPrivateId)
  928. , m_dst(dst)
  929. , m_base(base)
  930. , m_property(property)
  931. {
  932. }
  933. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  934. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  935. void visit_operands_impl(Function<void(Operand&)> visitor)
  936. {
  937. visitor(m_dst);
  938. visitor(m_base);
  939. }
  940. Operand dst() const { return m_dst; }
  941. Operand base() const { return m_base; }
  942. IdentifierTableIndex property() const { return m_property; }
  943. private:
  944. Operand m_dst;
  945. Operand m_base;
  946. IdentifierTableIndex m_property;
  947. };
  948. enum class PropertyKind {
  949. Getter,
  950. Setter,
  951. KeyValue,
  952. DirectKeyValue, // Used for Object expressions. Always sets an own property, never calls a setter.
  953. ProtoSetter,
  954. };
  955. class PutBySpread final : public Instruction {
  956. public:
  957. PutBySpread(Operand base, Operand src)
  958. : Instruction(Type::PutBySpread)
  959. , m_base(base)
  960. , m_src(src)
  961. {
  962. }
  963. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  964. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  965. void visit_operands_impl(Function<void(Operand&)> visitor)
  966. {
  967. visitor(m_base);
  968. visitor(m_src);
  969. }
  970. Operand base() const { return m_base; }
  971. Operand src() const { return m_src; }
  972. private:
  973. Operand m_base;
  974. Operand m_src;
  975. };
  976. class PutById final : public Instruction {
  977. public:
  978. explicit PutById(Operand base, IdentifierTableIndex property, Operand src, PropertyKind kind, u32 cache_index, Optional<IdentifierTableIndex> base_identifier = {})
  979. : Instruction(Type::PutById)
  980. , m_base(base)
  981. , m_property(property)
  982. , m_src(src)
  983. , m_kind(kind)
  984. , m_cache_index(cache_index)
  985. , m_base_identifier(move(base_identifier))
  986. {
  987. }
  988. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  989. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  990. void visit_operands_impl(Function<void(Operand&)> visitor)
  991. {
  992. visitor(m_base);
  993. visitor(m_src);
  994. }
  995. Operand base() const { return m_base; }
  996. IdentifierTableIndex property() const { return m_property; }
  997. Operand src() const { return m_src; }
  998. PropertyKind kind() const { return m_kind; }
  999. u32 cache_index() const { return m_cache_index; }
  1000. private:
  1001. Operand m_base;
  1002. IdentifierTableIndex m_property;
  1003. Operand m_src;
  1004. PropertyKind m_kind;
  1005. u32 m_cache_index { 0 };
  1006. Optional<IdentifierTableIndex> m_base_identifier {};
  1007. };
  1008. class PutByIdWithThis final : public Instruction {
  1009. public:
  1010. PutByIdWithThis(Operand base, Operand this_value, IdentifierTableIndex property, Operand src, PropertyKind kind, u32 cache_index)
  1011. : Instruction(Type::PutByIdWithThis)
  1012. , m_base(base)
  1013. , m_this_value(this_value)
  1014. , m_property(property)
  1015. , m_src(src)
  1016. , m_kind(kind)
  1017. , m_cache_index(cache_index)
  1018. {
  1019. }
  1020. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1021. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1022. void visit_operands_impl(Function<void(Operand&)> visitor)
  1023. {
  1024. visitor(m_base);
  1025. visitor(m_this_value);
  1026. visitor(m_src);
  1027. }
  1028. Operand base() const { return m_base; }
  1029. Operand this_value() const { return m_this_value; }
  1030. IdentifierTableIndex property() const { return m_property; }
  1031. Operand src() const { return m_src; }
  1032. PropertyKind kind() const { return m_kind; }
  1033. u32 cache_index() const { return m_cache_index; }
  1034. private:
  1035. Operand m_base;
  1036. Operand m_this_value;
  1037. IdentifierTableIndex m_property;
  1038. Operand m_src;
  1039. PropertyKind m_kind;
  1040. u32 m_cache_index { 0 };
  1041. };
  1042. class PutPrivateById final : public Instruction {
  1043. public:
  1044. explicit PutPrivateById(Operand base, IdentifierTableIndex property, Operand src, PropertyKind kind = PropertyKind::KeyValue)
  1045. : Instruction(Type::PutPrivateById)
  1046. , m_base(base)
  1047. , m_property(property)
  1048. , m_src(src)
  1049. , m_kind(kind)
  1050. {
  1051. }
  1052. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1053. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1054. void visit_operands_impl(Function<void(Operand&)> visitor)
  1055. {
  1056. visitor(m_base);
  1057. visitor(m_src);
  1058. }
  1059. Operand base() const { return m_base; }
  1060. IdentifierTableIndex property() const { return m_property; }
  1061. Operand src() const { return m_src; }
  1062. private:
  1063. Operand m_base;
  1064. IdentifierTableIndex m_property;
  1065. Operand m_src;
  1066. PropertyKind m_kind;
  1067. };
  1068. class DeleteById final : public Instruction {
  1069. public:
  1070. explicit DeleteById(Operand dst, Operand base, IdentifierTableIndex property)
  1071. : Instruction(Type::DeleteById)
  1072. , m_dst(dst)
  1073. , m_base(base)
  1074. , m_property(property)
  1075. {
  1076. }
  1077. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1078. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1079. void visit_operands_impl(Function<void(Operand&)> visitor)
  1080. {
  1081. visitor(m_dst);
  1082. visitor(m_base);
  1083. }
  1084. Operand dst() const { return m_dst; }
  1085. Operand base() const { return m_base; }
  1086. IdentifierTableIndex property() const { return m_property; }
  1087. private:
  1088. Operand m_dst;
  1089. Operand m_base;
  1090. IdentifierTableIndex m_property;
  1091. };
  1092. class DeleteByIdWithThis final : public Instruction {
  1093. public:
  1094. DeleteByIdWithThis(Operand dst, Operand base, Operand this_value, IdentifierTableIndex property)
  1095. : Instruction(Type::DeleteByIdWithThis)
  1096. , m_dst(dst)
  1097. , m_base(base)
  1098. , m_this_value(this_value)
  1099. , m_property(property)
  1100. {
  1101. }
  1102. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1103. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1104. void visit_operands_impl(Function<void(Operand&)> visitor)
  1105. {
  1106. visitor(m_dst);
  1107. visitor(m_base);
  1108. visitor(m_this_value);
  1109. }
  1110. Operand dst() const { return m_dst; }
  1111. Operand base() const { return m_base; }
  1112. Operand this_value() const { return m_this_value; }
  1113. IdentifierTableIndex property() const { return m_property; }
  1114. private:
  1115. Operand m_dst;
  1116. Operand m_base;
  1117. Operand m_this_value;
  1118. IdentifierTableIndex m_property;
  1119. };
  1120. class GetByValue final : public Instruction {
  1121. public:
  1122. GetByValue(Operand dst, Operand base, Operand property, Optional<IdentifierTableIndex> base_identifier = {})
  1123. : Instruction(Type::GetByValue)
  1124. , m_dst(dst)
  1125. , m_base(base)
  1126. , m_property(property)
  1127. , m_base_identifier(move(base_identifier))
  1128. {
  1129. }
  1130. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1131. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1132. void visit_operands_impl(Function<void(Operand&)> visitor)
  1133. {
  1134. visitor(m_dst);
  1135. visitor(m_base);
  1136. visitor(m_property);
  1137. }
  1138. Operand dst() const { return m_dst; }
  1139. Operand base() const { return m_base; }
  1140. Operand property() const { return m_property; }
  1141. Optional<DeprecatedFlyString const&> base_identifier(Bytecode::Interpreter const&) const;
  1142. private:
  1143. Operand m_dst;
  1144. Operand m_base;
  1145. Operand m_property;
  1146. Optional<IdentifierTableIndex> m_base_identifier;
  1147. };
  1148. class GetByValueWithThis final : public Instruction {
  1149. public:
  1150. GetByValueWithThis(Operand dst, Operand base, Operand property, Operand this_value)
  1151. : Instruction(Type::GetByValueWithThis)
  1152. , m_dst(dst)
  1153. , m_base(base)
  1154. , m_property(property)
  1155. , m_this_value(this_value)
  1156. {
  1157. }
  1158. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1159. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1160. void visit_operands_impl(Function<void(Operand&)> visitor)
  1161. {
  1162. visitor(m_dst);
  1163. visitor(m_base);
  1164. visitor(m_property);
  1165. visitor(m_this_value);
  1166. }
  1167. Operand dst() const { return m_dst; }
  1168. Operand base() const { return m_base; }
  1169. Operand property() const { return m_property; }
  1170. Operand this_value() const { return m_this_value; }
  1171. private:
  1172. Operand m_dst;
  1173. Operand m_base;
  1174. Operand m_property;
  1175. Operand m_this_value;
  1176. };
  1177. class PutByValue final : public Instruction {
  1178. public:
  1179. PutByValue(Operand base, Operand property, Operand src, PropertyKind kind = PropertyKind::KeyValue, Optional<IdentifierTableIndex> base_identifier = {})
  1180. : Instruction(Type::PutByValue)
  1181. , m_base(base)
  1182. , m_property(property)
  1183. , m_src(src)
  1184. , m_kind(kind)
  1185. , m_base_identifier(move(base_identifier))
  1186. {
  1187. }
  1188. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1189. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1190. void visit_operands_impl(Function<void(Operand&)> visitor)
  1191. {
  1192. visitor(m_base);
  1193. visitor(m_property);
  1194. visitor(m_src);
  1195. }
  1196. Operand base() const { return m_base; }
  1197. Operand property() const { return m_property; }
  1198. Operand src() const { return m_src; }
  1199. PropertyKind kind() const { return m_kind; }
  1200. private:
  1201. Operand m_base;
  1202. Operand m_property;
  1203. Operand m_src;
  1204. PropertyKind m_kind;
  1205. Optional<IdentifierTableIndex> m_base_identifier;
  1206. };
  1207. class PutByValueWithThis final : public Instruction {
  1208. public:
  1209. PutByValueWithThis(Operand base, Operand property, Operand this_value, Operand src, PropertyKind kind = PropertyKind::KeyValue)
  1210. : Instruction(Type::PutByValueWithThis)
  1211. , m_base(base)
  1212. , m_property(property)
  1213. , m_this_value(this_value)
  1214. , m_src(src)
  1215. , m_kind(kind)
  1216. {
  1217. }
  1218. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1219. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1220. void visit_operands_impl(Function<void(Operand&)> visitor)
  1221. {
  1222. visitor(m_base);
  1223. visitor(m_property);
  1224. visitor(m_this_value);
  1225. visitor(m_src);
  1226. }
  1227. Operand base() const { return m_base; }
  1228. Operand property() const { return m_property; }
  1229. Operand this_value() const { return m_this_value; }
  1230. Operand src() const { return m_src; }
  1231. PropertyKind kind() const { return m_kind; }
  1232. private:
  1233. Operand m_base;
  1234. Operand m_property;
  1235. Operand m_this_value;
  1236. Operand m_src;
  1237. PropertyKind m_kind;
  1238. };
  1239. class DeleteByValue final : public Instruction {
  1240. public:
  1241. DeleteByValue(Operand dst, Operand base, Operand property)
  1242. : Instruction(Type::DeleteByValue)
  1243. , m_dst(dst)
  1244. , m_base(base)
  1245. , m_property(property)
  1246. {
  1247. }
  1248. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1249. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1250. void visit_operands_impl(Function<void(Operand&)> visitor)
  1251. {
  1252. visitor(m_dst);
  1253. visitor(m_base);
  1254. visitor(m_property);
  1255. }
  1256. Operand dst() const { return m_dst; }
  1257. Operand base() const { return m_base; }
  1258. Operand property() const { return m_property; }
  1259. private:
  1260. Operand m_dst;
  1261. Operand m_base;
  1262. Operand m_property;
  1263. };
  1264. class DeleteByValueWithThis final : public Instruction {
  1265. public:
  1266. DeleteByValueWithThis(Operand dst, Operand base, Operand this_value, Operand property)
  1267. : Instruction(Type::DeleteByValueWithThis)
  1268. , m_dst(dst)
  1269. , m_base(base)
  1270. , m_this_value(this_value)
  1271. , m_property(property)
  1272. {
  1273. }
  1274. Operand dst() const { return m_dst; }
  1275. Operand base() const { return m_base; }
  1276. Operand this_value() const { return m_this_value; }
  1277. Operand property() const { return m_property; }
  1278. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1279. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1280. void visit_operands_impl(Function<void(Operand&)> visitor)
  1281. {
  1282. visitor(m_dst);
  1283. visitor(m_base);
  1284. visitor(m_this_value);
  1285. visitor(m_property);
  1286. }
  1287. private:
  1288. Operand m_dst;
  1289. Operand m_base;
  1290. Operand m_this_value;
  1291. Operand m_property;
  1292. };
  1293. class Jump final : public Instruction {
  1294. public:
  1295. constexpr static bool IsTerminator = true;
  1296. explicit Jump(Label target)
  1297. : Instruction(Type::Jump)
  1298. , m_target(target)
  1299. {
  1300. }
  1301. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1302. void visit_labels_impl(Function<void(Label&)> visitor)
  1303. {
  1304. visitor(m_target);
  1305. }
  1306. auto& target() const { return m_target; }
  1307. protected:
  1308. Label m_target;
  1309. };
  1310. class JumpIf final : public Instruction {
  1311. public:
  1312. constexpr static bool IsTerminator = true;
  1313. explicit JumpIf(Operand condition, Label true_target, Label false_target)
  1314. : Instruction(Type::JumpIf)
  1315. , m_condition(condition)
  1316. , m_true_target(true_target)
  1317. , m_false_target(false_target)
  1318. {
  1319. }
  1320. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1321. void visit_labels_impl(Function<void(Label&)> visitor)
  1322. {
  1323. visitor(m_true_target);
  1324. visitor(m_false_target);
  1325. }
  1326. void visit_operands_impl(Function<void(Operand&)> visitor)
  1327. {
  1328. visitor(m_condition);
  1329. }
  1330. Operand condition() const { return m_condition; }
  1331. auto& true_target() const { return m_true_target; }
  1332. auto& false_target() const { return m_false_target; }
  1333. private:
  1334. Operand m_condition;
  1335. Label m_true_target;
  1336. Label m_false_target;
  1337. };
  1338. class JumpTrue final : public Instruction {
  1339. public:
  1340. constexpr static bool IsTerminator = true;
  1341. explicit JumpTrue(Operand condition, Label target)
  1342. : Instruction(Type::JumpTrue)
  1343. , m_condition(condition)
  1344. , m_target(target)
  1345. {
  1346. }
  1347. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1348. void visit_labels_impl(Function<void(Label&)> visitor)
  1349. {
  1350. visitor(m_target);
  1351. }
  1352. void visit_operands_impl(Function<void(Operand&)> visitor)
  1353. {
  1354. visitor(m_condition);
  1355. }
  1356. Operand condition() const { return m_condition; }
  1357. auto& target() const { return m_target; }
  1358. private:
  1359. Operand m_condition;
  1360. Label m_target;
  1361. };
  1362. class JumpFalse final : public Instruction {
  1363. public:
  1364. constexpr static bool IsTerminator = true;
  1365. explicit JumpFalse(Operand condition, Label target)
  1366. : Instruction(Type::JumpFalse)
  1367. , m_condition(condition)
  1368. , m_target(target)
  1369. {
  1370. }
  1371. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1372. void visit_labels_impl(Function<void(Label&)> visitor)
  1373. {
  1374. visitor(m_target);
  1375. }
  1376. void visit_operands_impl(Function<void(Operand&)> visitor)
  1377. {
  1378. visitor(m_condition);
  1379. }
  1380. Operand condition() const { return m_condition; }
  1381. auto& target() const { return m_target; }
  1382. private:
  1383. Operand m_condition;
  1384. Label m_target;
  1385. };
  1386. #define JS_ENUMERATE_COMPARISON_OPS(X) \
  1387. X(LessThan, less_than, <) \
  1388. X(LessThanEquals, less_than_equals, <=) \
  1389. X(GreaterThan, greater_than, >) \
  1390. X(GreaterThanEquals, greater_than_equals, >=) \
  1391. X(LooselyEquals, loosely_equals, ==) \
  1392. X(LooselyInequals, loosely_inequals, !=) \
  1393. X(StrictlyEquals, strict_equals, ==) \
  1394. X(StrictlyInequals, strict_inequals, !=)
  1395. #define DECLARE_COMPARISON_OP(op_TitleCase, op_snake_case, numeric_operator) \
  1396. class Jump##op_TitleCase final : public Instruction { \
  1397. public: \
  1398. constexpr static bool IsTerminator = true; \
  1399. \
  1400. explicit Jump##op_TitleCase(Operand lhs, Operand rhs, Label true_target, Label false_target) \
  1401. : Instruction(Type::Jump##op_TitleCase) \
  1402. , m_lhs(lhs) \
  1403. , m_rhs(rhs) \
  1404. , m_true_target(true_target) \
  1405. , m_false_target(false_target) \
  1406. { \
  1407. } \
  1408. \
  1409. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  1410. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  1411. void visit_labels_impl(Function<void(Label&)> visitor) \
  1412. { \
  1413. visitor(m_true_target); \
  1414. visitor(m_false_target); \
  1415. } \
  1416. void visit_operands_impl(Function<void(Operand&)> visitor) \
  1417. { \
  1418. visitor(m_lhs); \
  1419. visitor(m_rhs); \
  1420. } \
  1421. \
  1422. Operand lhs() const { return m_lhs; } \
  1423. Operand rhs() const { return m_rhs; } \
  1424. auto& true_target() const { return m_true_target; } \
  1425. auto& false_target() const { return m_false_target; } \
  1426. \
  1427. private: \
  1428. Operand m_lhs; \
  1429. Operand m_rhs; \
  1430. Label m_true_target; \
  1431. Label m_false_target; \
  1432. };
  1433. JS_ENUMERATE_COMPARISON_OPS(DECLARE_COMPARISON_OP)
  1434. class JumpNullish final : public Instruction {
  1435. public:
  1436. constexpr static bool IsTerminator = true;
  1437. explicit JumpNullish(Operand condition, Label true_target, Label false_target)
  1438. : Instruction(Type::JumpNullish)
  1439. , m_condition(condition)
  1440. , m_true_target(true_target)
  1441. , m_false_target(false_target)
  1442. {
  1443. }
  1444. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1445. void visit_labels_impl(Function<void(Label&)> visitor)
  1446. {
  1447. visitor(m_true_target);
  1448. visitor(m_false_target);
  1449. }
  1450. void visit_operands_impl(Function<void(Operand&)> visitor)
  1451. {
  1452. visitor(m_condition);
  1453. }
  1454. Operand condition() const { return m_condition; }
  1455. auto& true_target() const { return m_true_target; }
  1456. auto& false_target() const { return m_false_target; }
  1457. private:
  1458. Operand m_condition;
  1459. Label m_true_target;
  1460. Label m_false_target;
  1461. };
  1462. class JumpUndefined final : public Instruction {
  1463. public:
  1464. constexpr static bool IsTerminator = true;
  1465. explicit JumpUndefined(Operand condition, Label true_target, Label false_target)
  1466. : Instruction(Type::JumpUndefined)
  1467. , m_condition(condition)
  1468. , m_true_target(true_target)
  1469. , m_false_target(false_target)
  1470. {
  1471. }
  1472. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1473. void visit_labels_impl(Function<void(Label&)> visitor)
  1474. {
  1475. visitor(m_true_target);
  1476. visitor(m_false_target);
  1477. }
  1478. void visit_operands_impl(Function<void(Operand&)> visitor)
  1479. {
  1480. visitor(m_condition);
  1481. }
  1482. Operand condition() const { return m_condition; }
  1483. auto& true_target() const { return m_true_target; }
  1484. auto& false_target() const { return m_false_target; }
  1485. private:
  1486. Operand m_condition;
  1487. Label m_true_target;
  1488. Label m_false_target;
  1489. };
  1490. enum class CallType : u8 {
  1491. Call,
  1492. Construct,
  1493. DirectEval,
  1494. };
  1495. class Call final : public Instruction {
  1496. public:
  1497. static constexpr bool IsVariableLength = true;
  1498. Call(Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {})
  1499. : Instruction(Type::Call)
  1500. , m_dst(dst)
  1501. , m_callee(callee)
  1502. , m_this_value(this_value)
  1503. , m_argument_count(arguments.size())
  1504. , m_expression_string(expression_string)
  1505. {
  1506. for (size_t i = 0; i < arguments.size(); ++i)
  1507. m_arguments[i] = arguments[i];
  1508. }
  1509. size_t length_impl() const
  1510. {
  1511. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
  1512. }
  1513. Operand dst() const { return m_dst; }
  1514. Operand callee() const { return m_callee; }
  1515. Operand this_value() const { return m_this_value; }
  1516. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1517. u32 argument_count() const { return m_argument_count; }
  1518. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1519. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1520. void visit_operands_impl(Function<void(Operand&)> visitor)
  1521. {
  1522. visitor(m_dst);
  1523. visitor(m_callee);
  1524. visitor(m_this_value);
  1525. for (size_t i = 0; i < m_argument_count; i++)
  1526. visitor(m_arguments[i]);
  1527. }
  1528. private:
  1529. Operand m_dst;
  1530. Operand m_callee;
  1531. Operand m_this_value;
  1532. u32 m_argument_count { 0 };
  1533. Optional<StringTableIndex> m_expression_string;
  1534. Operand m_arguments[];
  1535. };
  1536. class CallBuiltin final : public Instruction {
  1537. public:
  1538. static constexpr bool IsVariableLength = true;
  1539. CallBuiltin(Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Builtin builtin, Optional<StringTableIndex> expression_string = {})
  1540. : Instruction(Type::CallBuiltin)
  1541. , m_dst(dst)
  1542. , m_callee(callee)
  1543. , m_this_value(this_value)
  1544. , m_argument_count(arguments.size())
  1545. , m_builtin(builtin)
  1546. , m_expression_string(expression_string)
  1547. {
  1548. for (size_t i = 0; i < arguments.size(); ++i)
  1549. m_arguments[i] = arguments[i];
  1550. }
  1551. size_t length_impl() const
  1552. {
  1553. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
  1554. }
  1555. Operand dst() const { return m_dst; }
  1556. Operand callee() const { return m_callee; }
  1557. Operand this_value() const { return m_this_value; }
  1558. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1559. u32 argument_count() const { return m_argument_count; }
  1560. Builtin const& builtin() const { return m_builtin; }
  1561. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1562. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1563. void visit_operands_impl(Function<void(Operand&)> visitor)
  1564. {
  1565. visitor(m_dst);
  1566. visitor(m_callee);
  1567. visitor(m_this_value);
  1568. for (size_t i = 0; i < m_argument_count; i++)
  1569. visitor(m_arguments[i]);
  1570. }
  1571. private:
  1572. Operand m_dst;
  1573. Operand m_callee;
  1574. Operand m_this_value;
  1575. u32 m_argument_count { 0 };
  1576. Builtin m_builtin;
  1577. Optional<StringTableIndex> m_expression_string;
  1578. Operand m_arguments[];
  1579. };
  1580. class CallConstruct final : public Instruction {
  1581. public:
  1582. static constexpr bool IsVariableLength = true;
  1583. CallConstruct(Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {})
  1584. : Instruction(Type::CallConstruct)
  1585. , m_dst(dst)
  1586. , m_callee(callee)
  1587. , m_this_value(this_value)
  1588. , m_argument_count(arguments.size())
  1589. , m_expression_string(expression_string)
  1590. {
  1591. for (size_t i = 0; i < arguments.size(); ++i)
  1592. m_arguments[i] = arguments[i];
  1593. }
  1594. size_t length_impl() const
  1595. {
  1596. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
  1597. }
  1598. Operand dst() const { return m_dst; }
  1599. Operand callee() const { return m_callee; }
  1600. Operand this_value() const { return m_this_value; }
  1601. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1602. u32 argument_count() const { return m_argument_count; }
  1603. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1604. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1605. void visit_operands_impl(Function<void(Operand&)> visitor)
  1606. {
  1607. visitor(m_dst);
  1608. visitor(m_callee);
  1609. visitor(m_this_value);
  1610. for (size_t i = 0; i < m_argument_count; i++)
  1611. visitor(m_arguments[i]);
  1612. }
  1613. private:
  1614. Operand m_dst;
  1615. Operand m_callee;
  1616. Operand m_this_value;
  1617. u32 m_argument_count { 0 };
  1618. Optional<StringTableIndex> m_expression_string;
  1619. Operand m_arguments[];
  1620. };
  1621. class CallDirectEval final : public Instruction {
  1622. public:
  1623. static constexpr bool IsVariableLength = true;
  1624. CallDirectEval(Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {})
  1625. : Instruction(Type::CallDirectEval)
  1626. , m_dst(dst)
  1627. , m_callee(callee)
  1628. , m_this_value(this_value)
  1629. , m_argument_count(arguments.size())
  1630. , m_expression_string(expression_string)
  1631. {
  1632. for (size_t i = 0; i < arguments.size(); ++i)
  1633. m_arguments[i] = arguments[i];
  1634. }
  1635. size_t length_impl() const
  1636. {
  1637. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
  1638. }
  1639. Operand dst() const { return m_dst; }
  1640. Operand callee() const { return m_callee; }
  1641. Operand this_value() const { return m_this_value; }
  1642. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1643. u32 argument_count() const { return m_argument_count; }
  1644. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1645. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1646. void visit_operands_impl(Function<void(Operand&)> visitor)
  1647. {
  1648. visitor(m_dst);
  1649. visitor(m_callee);
  1650. visitor(m_this_value);
  1651. for (size_t i = 0; i < m_argument_count; i++)
  1652. visitor(m_arguments[i]);
  1653. }
  1654. private:
  1655. Operand m_dst;
  1656. Operand m_callee;
  1657. Operand m_this_value;
  1658. u32 m_argument_count { 0 };
  1659. Optional<StringTableIndex> m_expression_string;
  1660. Operand m_arguments[];
  1661. };
  1662. class CallWithArgumentArray final : public Instruction {
  1663. public:
  1664. CallWithArgumentArray(CallType type, Operand dst, Operand callee, Operand this_value, Operand arguments, Optional<StringTableIndex> expression_string = {})
  1665. : Instruction(Type::CallWithArgumentArray)
  1666. , m_dst(dst)
  1667. , m_callee(callee)
  1668. , m_this_value(this_value)
  1669. , m_arguments(arguments)
  1670. , m_type(type)
  1671. , m_expression_string(expression_string)
  1672. {
  1673. }
  1674. Operand dst() const { return m_dst; }
  1675. CallType call_type() const { return m_type; }
  1676. Operand callee() const { return m_callee; }
  1677. Operand this_value() const { return m_this_value; }
  1678. Operand arguments() const { return m_arguments; }
  1679. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1680. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1681. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1682. void visit_operands_impl(Function<void(Operand&)> visitor)
  1683. {
  1684. visitor(m_dst);
  1685. visitor(m_callee);
  1686. visitor(m_this_value);
  1687. visitor(m_arguments);
  1688. }
  1689. private:
  1690. Operand m_dst;
  1691. Operand m_callee;
  1692. Operand m_this_value;
  1693. Operand m_arguments;
  1694. CallType m_type;
  1695. Optional<StringTableIndex> m_expression_string;
  1696. };
  1697. class SuperCallWithArgumentArray : public Instruction {
  1698. public:
  1699. explicit SuperCallWithArgumentArray(Operand dst, Operand arguments, bool is_synthetic)
  1700. : Instruction(Type::SuperCallWithArgumentArray)
  1701. , m_dst(dst)
  1702. , m_arguments(arguments)
  1703. , m_is_synthetic(is_synthetic)
  1704. {
  1705. }
  1706. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1707. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1708. void visit_operands_impl(Function<void(Operand&)> visitor)
  1709. {
  1710. visitor(m_dst);
  1711. visitor(m_arguments);
  1712. }
  1713. Operand dst() const { return m_dst; }
  1714. Operand arguments() const { return m_arguments; }
  1715. bool is_synthetic() const { return m_is_synthetic; }
  1716. private:
  1717. Operand m_dst;
  1718. Operand m_arguments;
  1719. bool m_is_synthetic;
  1720. };
  1721. class NewClass final : public Instruction {
  1722. public:
  1723. static constexpr bool IsVariableLength = true;
  1724. explicit NewClass(Operand dst, Optional<Operand> super_class, ClassExpression const& class_expression, Optional<IdentifierTableIndex> lhs_name, ReadonlySpan<Optional<ScopedOperand>> elements_keys)
  1725. : Instruction(Type::NewClass)
  1726. , m_dst(dst)
  1727. , m_super_class(super_class)
  1728. , m_class_expression(class_expression)
  1729. , m_lhs_name(lhs_name)
  1730. , m_element_keys_count(elements_keys.size())
  1731. {
  1732. for (size_t i = 0; i < m_element_keys_count; i++) {
  1733. if (elements_keys[i].has_value())
  1734. m_element_keys[i] = elements_keys[i]->operand();
  1735. }
  1736. }
  1737. size_t length_impl() const
  1738. {
  1739. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Optional<Operand>) * m_element_keys_count);
  1740. }
  1741. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1742. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1743. void visit_operands_impl(Function<void(Operand&)> visitor)
  1744. {
  1745. visitor(m_dst);
  1746. if (m_super_class.has_value())
  1747. visitor(m_super_class.value());
  1748. for (size_t i = 0; i < m_element_keys_count; i++) {
  1749. if (m_element_keys[i].has_value())
  1750. visitor(m_element_keys[i].value());
  1751. }
  1752. }
  1753. Operand dst() const { return m_dst; }
  1754. Optional<Operand> const& super_class() const { return m_super_class; }
  1755. ClassExpression const& class_expression() const { return m_class_expression; }
  1756. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  1757. private:
  1758. Operand m_dst;
  1759. Optional<Operand> m_super_class;
  1760. ClassExpression const& m_class_expression;
  1761. Optional<IdentifierTableIndex> m_lhs_name;
  1762. size_t m_element_keys_count { 0 };
  1763. Optional<Operand> m_element_keys[];
  1764. };
  1765. class NewFunction final : public Instruction {
  1766. public:
  1767. explicit NewFunction(Operand dst, FunctionNode const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Operand> home_object = {})
  1768. : Instruction(Type::NewFunction)
  1769. , m_dst(dst)
  1770. , m_function_node(function_node)
  1771. , m_lhs_name(lhs_name)
  1772. , m_home_object(move(home_object))
  1773. {
  1774. }
  1775. void execute_impl(Bytecode::Interpreter&) const;
  1776. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1777. void visit_operands_impl(Function<void(Operand&)> visitor)
  1778. {
  1779. visitor(m_dst);
  1780. if (m_home_object.has_value())
  1781. visitor(m_home_object.value());
  1782. }
  1783. Operand dst() const { return m_dst; }
  1784. FunctionNode const& function_node() const { return m_function_node; }
  1785. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  1786. Optional<Operand> const& home_object() const { return m_home_object; }
  1787. private:
  1788. Operand m_dst;
  1789. FunctionNode const& m_function_node;
  1790. Optional<IdentifierTableIndex> m_lhs_name;
  1791. Optional<Operand> m_home_object;
  1792. };
  1793. class BlockDeclarationInstantiation final : public Instruction {
  1794. public:
  1795. explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
  1796. : Instruction(Type::BlockDeclarationInstantiation)
  1797. , m_scope_node(scope_node)
  1798. {
  1799. }
  1800. void execute_impl(Bytecode::Interpreter&) const;
  1801. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1802. ScopeNode const& scope_node() const { return m_scope_node; }
  1803. private:
  1804. ScopeNode const& m_scope_node;
  1805. };
  1806. class Return final : public Instruction {
  1807. public:
  1808. constexpr static bool IsTerminator = true;
  1809. explicit Return(Optional<Operand> value = {})
  1810. : Instruction(Type::Return)
  1811. , m_value(value)
  1812. {
  1813. }
  1814. void execute_impl(Bytecode::Interpreter&) const;
  1815. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1816. void visit_operands_impl(Function<void(Operand&)> visitor)
  1817. {
  1818. if (m_value.has_value())
  1819. visitor(m_value.value());
  1820. }
  1821. Optional<Operand> const& value() const { return m_value; }
  1822. private:
  1823. Optional<Operand> m_value;
  1824. };
  1825. class Increment final : public Instruction {
  1826. public:
  1827. explicit Increment(Operand dst)
  1828. : Instruction(Type::Increment)
  1829. , m_dst(dst)
  1830. {
  1831. }
  1832. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1833. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1834. void visit_operands_impl(Function<void(Operand&)> visitor)
  1835. {
  1836. visitor(m_dst);
  1837. }
  1838. Operand dst() const { return m_dst; }
  1839. private:
  1840. Operand m_dst;
  1841. };
  1842. class PostfixIncrement final : public Instruction {
  1843. public:
  1844. explicit PostfixIncrement(Operand dst, Operand src)
  1845. : Instruction(Type::PostfixIncrement)
  1846. , m_dst(dst)
  1847. , m_src(src)
  1848. {
  1849. }
  1850. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1851. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1852. void visit_operands_impl(Function<void(Operand&)> visitor)
  1853. {
  1854. visitor(m_dst);
  1855. visitor(m_src);
  1856. }
  1857. Operand dst() const { return m_dst; }
  1858. Operand src() const { return m_src; }
  1859. private:
  1860. Operand m_dst;
  1861. Operand m_src;
  1862. };
  1863. class Decrement final : public Instruction {
  1864. public:
  1865. explicit Decrement(Operand dst)
  1866. : Instruction(Type::Decrement)
  1867. , m_dst(dst)
  1868. {
  1869. }
  1870. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1871. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1872. void visit_operands_impl(Function<void(Operand&)> visitor)
  1873. {
  1874. visitor(m_dst);
  1875. }
  1876. Operand dst() const { return m_dst; }
  1877. private:
  1878. Operand m_dst;
  1879. };
  1880. class PostfixDecrement final : public Instruction {
  1881. public:
  1882. explicit PostfixDecrement(Operand dst, Operand src)
  1883. : Instruction(Type::PostfixDecrement)
  1884. , m_dst(dst)
  1885. , m_src(src)
  1886. {
  1887. }
  1888. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1889. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1890. void visit_operands_impl(Function<void(Operand&)> visitor)
  1891. {
  1892. visitor(m_dst);
  1893. visitor(m_src);
  1894. }
  1895. Operand dst() const { return m_dst; }
  1896. Operand src() const { return m_src; }
  1897. private:
  1898. Operand m_dst;
  1899. Operand m_src;
  1900. };
  1901. class Throw final : public Instruction {
  1902. public:
  1903. constexpr static bool IsTerminator = true;
  1904. explicit Throw(Operand src)
  1905. : Instruction(Type::Throw)
  1906. , m_src(src)
  1907. {
  1908. }
  1909. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1910. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1911. void visit_operands_impl(Function<void(Operand&)> visitor)
  1912. {
  1913. visitor(m_src);
  1914. }
  1915. Operand src() const { return m_src; }
  1916. private:
  1917. Operand m_src;
  1918. };
  1919. class ThrowIfNotObject final : public Instruction {
  1920. public:
  1921. ThrowIfNotObject(Operand src)
  1922. : Instruction(Type::ThrowIfNotObject)
  1923. , m_src(src)
  1924. {
  1925. }
  1926. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1927. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1928. void visit_operands_impl(Function<void(Operand&)> visitor)
  1929. {
  1930. visitor(m_src);
  1931. }
  1932. Operand src() const { return m_src; }
  1933. private:
  1934. Operand m_src;
  1935. };
  1936. class ThrowIfNullish final : public Instruction {
  1937. public:
  1938. explicit ThrowIfNullish(Operand src)
  1939. : Instruction(Type::ThrowIfNullish)
  1940. , m_src(src)
  1941. {
  1942. }
  1943. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1944. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1945. void visit_operands_impl(Function<void(Operand&)> visitor)
  1946. {
  1947. visitor(m_src);
  1948. }
  1949. Operand src() const { return m_src; }
  1950. private:
  1951. Operand m_src;
  1952. };
  1953. class ThrowIfTDZ final : public Instruction {
  1954. public:
  1955. explicit ThrowIfTDZ(Operand src)
  1956. : Instruction(Type::ThrowIfTDZ)
  1957. , m_src(src)
  1958. {
  1959. }
  1960. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1961. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1962. void visit_operands_impl(Function<void(Operand&)> visitor)
  1963. {
  1964. visitor(m_src);
  1965. }
  1966. Operand src() const { return m_src; }
  1967. private:
  1968. Operand m_src;
  1969. };
  1970. class EnterUnwindContext final : public Instruction {
  1971. public:
  1972. constexpr static bool IsTerminator = true;
  1973. EnterUnwindContext(Label entry_point)
  1974. : Instruction(Type::EnterUnwindContext)
  1975. , m_entry_point(move(entry_point))
  1976. {
  1977. }
  1978. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1979. void visit_labels_impl(Function<void(Label&)> visitor)
  1980. {
  1981. visitor(m_entry_point);
  1982. }
  1983. auto& entry_point() const { return m_entry_point; }
  1984. private:
  1985. Label m_entry_point;
  1986. };
  1987. class ScheduleJump final : public Instruction {
  1988. public:
  1989. // Note: We use this instruction to tell the next `finally` block to
  1990. // continue execution with a specific break/continue target;
  1991. constexpr static bool IsTerminator = true;
  1992. ScheduleJump(Label target)
  1993. : Instruction(Type::ScheduleJump)
  1994. , m_target(target)
  1995. {
  1996. }
  1997. Label target() const { return m_target; }
  1998. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1999. void visit_labels_impl(Function<void(Label&)> visitor)
  2000. {
  2001. visitor(m_target);
  2002. }
  2003. private:
  2004. Label m_target;
  2005. };
  2006. class LeaveLexicalEnvironment final : public Instruction {
  2007. public:
  2008. LeaveLexicalEnvironment()
  2009. : Instruction(Type::LeaveLexicalEnvironment)
  2010. {
  2011. }
  2012. void execute_impl(Bytecode::Interpreter&) const;
  2013. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2014. };
  2015. class LeavePrivateEnvironment final : public Instruction {
  2016. public:
  2017. LeavePrivateEnvironment()
  2018. : Instruction(Type::LeavePrivateEnvironment)
  2019. {
  2020. }
  2021. void execute_impl(Bytecode::Interpreter&) const;
  2022. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2023. };
  2024. class LeaveUnwindContext final : public Instruction {
  2025. public:
  2026. LeaveUnwindContext()
  2027. : Instruction(Type::LeaveUnwindContext)
  2028. {
  2029. }
  2030. void execute_impl(Bytecode::Interpreter&) const;
  2031. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2032. };
  2033. class ContinuePendingUnwind final : public Instruction {
  2034. public:
  2035. constexpr static bool IsTerminator = true;
  2036. explicit ContinuePendingUnwind(Label resume_target)
  2037. : Instruction(Type::ContinuePendingUnwind)
  2038. , m_resume_target(resume_target)
  2039. {
  2040. }
  2041. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2042. void visit_labels_impl(Function<void(Label&)> visitor)
  2043. {
  2044. visitor(m_resume_target);
  2045. }
  2046. auto& resume_target() const { return m_resume_target; }
  2047. private:
  2048. Label m_resume_target;
  2049. };
  2050. class Yield final : public Instruction {
  2051. public:
  2052. constexpr static bool IsTerminator = true;
  2053. explicit Yield(Label continuation_label, Operand value)
  2054. : Instruction(Type::Yield)
  2055. , m_continuation_label(continuation_label)
  2056. , m_value(value)
  2057. {
  2058. }
  2059. explicit Yield(nullptr_t, Operand value)
  2060. : Instruction(Type::Yield)
  2061. , m_value(value)
  2062. {
  2063. }
  2064. void execute_impl(Bytecode::Interpreter&) const;
  2065. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2066. void visit_labels_impl(Function<void(Label&)> visitor)
  2067. {
  2068. if (m_continuation_label.has_value())
  2069. visitor(m_continuation_label.value());
  2070. }
  2071. void visit_operands_impl(Function<void(Operand&)> visitor)
  2072. {
  2073. visitor(m_value);
  2074. }
  2075. auto& continuation() const { return m_continuation_label; }
  2076. Operand value() const { return m_value; }
  2077. private:
  2078. Optional<Label> m_continuation_label;
  2079. Operand m_value;
  2080. };
  2081. class PrepareYield final : public Instruction {
  2082. public:
  2083. explicit PrepareYield(Operand dest, Operand value)
  2084. : Instruction(Type::PrepareYield)
  2085. , m_dest(dest)
  2086. , m_value(value)
  2087. {
  2088. }
  2089. void execute_impl(Bytecode::Interpreter&) const;
  2090. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2091. void visit_operands_impl(Function<void(Operand&)> visitor)
  2092. {
  2093. visitor(m_dest);
  2094. visitor(m_value);
  2095. }
  2096. Operand destination() const { return m_dest; }
  2097. Operand value() const { return m_value; }
  2098. private:
  2099. Operand m_dest;
  2100. Operand m_value;
  2101. };
  2102. class Await final : public Instruction {
  2103. public:
  2104. constexpr static bool IsTerminator = true;
  2105. explicit Await(Label continuation_label, Operand argument)
  2106. : Instruction(Type::Await)
  2107. , m_continuation_label(continuation_label)
  2108. , m_argument(argument)
  2109. {
  2110. }
  2111. void execute_impl(Bytecode::Interpreter&) const;
  2112. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2113. void visit_labels_impl(Function<void(Label&)> visitor)
  2114. {
  2115. visitor(m_continuation_label);
  2116. }
  2117. void visit_operands_impl(Function<void(Operand&)> visitor)
  2118. {
  2119. visitor(m_argument);
  2120. }
  2121. auto& continuation() const { return m_continuation_label; }
  2122. Operand argument() const { return m_argument; }
  2123. private:
  2124. Label m_continuation_label;
  2125. Operand m_argument;
  2126. };
  2127. class GetIterator final : public Instruction {
  2128. public:
  2129. GetIterator(Operand dst, Operand iterable, IteratorHint hint = IteratorHint::Sync)
  2130. : Instruction(Type::GetIterator)
  2131. , m_dst(dst)
  2132. , m_iterable(iterable)
  2133. , m_hint(hint)
  2134. {
  2135. }
  2136. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2137. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2138. void visit_operands_impl(Function<void(Operand&)> visitor)
  2139. {
  2140. visitor(m_dst);
  2141. visitor(m_iterable);
  2142. }
  2143. Operand dst() const { return m_dst; }
  2144. Operand iterable() const { return m_iterable; }
  2145. IteratorHint hint() const { return m_hint; }
  2146. private:
  2147. Operand m_dst;
  2148. Operand m_iterable;
  2149. IteratorHint m_hint { IteratorHint::Sync };
  2150. };
  2151. class GetObjectFromIteratorRecord final : public Instruction {
  2152. public:
  2153. GetObjectFromIteratorRecord(Operand object, Operand iterator_record)
  2154. : Instruction(Type::GetObjectFromIteratorRecord)
  2155. , m_object(object)
  2156. , m_iterator_record(iterator_record)
  2157. {
  2158. }
  2159. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2160. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2161. void visit_operands_impl(Function<void(Operand&)> visitor)
  2162. {
  2163. visitor(m_object);
  2164. visitor(m_iterator_record);
  2165. }
  2166. Operand object() const { return m_object; }
  2167. Operand iterator_record() const { return m_iterator_record; }
  2168. private:
  2169. Operand m_object;
  2170. Operand m_iterator_record;
  2171. };
  2172. class GetNextMethodFromIteratorRecord final : public Instruction {
  2173. public:
  2174. GetNextMethodFromIteratorRecord(Operand next_method, Operand iterator_record)
  2175. : Instruction(Type::GetNextMethodFromIteratorRecord)
  2176. , m_next_method(next_method)
  2177. , m_iterator_record(iterator_record)
  2178. {
  2179. }
  2180. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2181. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2182. void visit_operands_impl(Function<void(Operand&)> visitor)
  2183. {
  2184. visitor(m_next_method);
  2185. visitor(m_iterator_record);
  2186. }
  2187. Operand next_method() const { return m_next_method; }
  2188. Operand iterator_record() const { return m_iterator_record; }
  2189. private:
  2190. Operand m_next_method;
  2191. Operand m_iterator_record;
  2192. };
  2193. class GetMethod final : public Instruction {
  2194. public:
  2195. GetMethod(Operand dst, Operand object, IdentifierTableIndex property)
  2196. : Instruction(Type::GetMethod)
  2197. , m_dst(dst)
  2198. , m_object(object)
  2199. , m_property(property)
  2200. {
  2201. }
  2202. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2203. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2204. void visit_operands_impl(Function<void(Operand&)> visitor)
  2205. {
  2206. visitor(m_dst);
  2207. visitor(m_object);
  2208. }
  2209. Operand dst() const { return m_dst; }
  2210. Operand object() const { return m_object; }
  2211. IdentifierTableIndex property() const { return m_property; }
  2212. private:
  2213. Operand m_dst;
  2214. Operand m_object;
  2215. IdentifierTableIndex m_property;
  2216. };
  2217. class GetObjectPropertyIterator final : public Instruction {
  2218. public:
  2219. GetObjectPropertyIterator(Operand dst, Operand object)
  2220. : Instruction(Type::GetObjectPropertyIterator)
  2221. , m_dst(dst)
  2222. , m_object(object)
  2223. {
  2224. }
  2225. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2226. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2227. void visit_operands_impl(Function<void(Operand&)> visitor)
  2228. {
  2229. visitor(m_dst);
  2230. visitor(m_object);
  2231. }
  2232. Operand dst() const { return m_dst; }
  2233. Operand object() const { return m_object; }
  2234. private:
  2235. Operand m_dst;
  2236. Operand m_object;
  2237. };
  2238. class IteratorClose final : public Instruction {
  2239. public:
  2240. IteratorClose(Operand iterator_record, Completion::Type completion_type, Optional<Value> completion_value)
  2241. : Instruction(Type::IteratorClose)
  2242. , m_iterator_record(iterator_record)
  2243. , m_completion_type(completion_type)
  2244. , m_completion_value(completion_value)
  2245. {
  2246. }
  2247. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2248. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2249. void visit_operands_impl(Function<void(Operand&)> visitor)
  2250. {
  2251. visitor(m_iterator_record);
  2252. }
  2253. Operand iterator_record() const { return m_iterator_record; }
  2254. Completion::Type completion_type() const { return m_completion_type; }
  2255. Optional<Value> const& completion_value() const { return m_completion_value; }
  2256. private:
  2257. Operand m_iterator_record;
  2258. Completion::Type m_completion_type { Completion::Type::Normal };
  2259. Optional<Value> m_completion_value;
  2260. };
  2261. class AsyncIteratorClose final : public Instruction {
  2262. public:
  2263. AsyncIteratorClose(Operand iterator_record, Completion::Type completion_type, Optional<Value> completion_value)
  2264. : Instruction(Type::AsyncIteratorClose)
  2265. , m_iterator_record(iterator_record)
  2266. , m_completion_type(completion_type)
  2267. , m_completion_value(completion_value)
  2268. {
  2269. }
  2270. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2271. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2272. void visit_operands_impl(Function<void(Operand&)> visitor)
  2273. {
  2274. visitor(m_iterator_record);
  2275. }
  2276. Operand iterator_record() const { return m_iterator_record; }
  2277. Completion::Type completion_type() const { return m_completion_type; }
  2278. Optional<Value> const& completion_value() const { return m_completion_value; }
  2279. private:
  2280. Operand m_iterator_record;
  2281. Completion::Type m_completion_type { Completion::Type::Normal };
  2282. Optional<Value> m_completion_value;
  2283. };
  2284. class IteratorNext final : public Instruction {
  2285. public:
  2286. IteratorNext(Operand dst, Operand iterator_record)
  2287. : Instruction(Type::IteratorNext)
  2288. , m_dst(dst)
  2289. , m_iterator_record(iterator_record)
  2290. {
  2291. }
  2292. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2293. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2294. void visit_operands_impl(Function<void(Operand&)> visitor)
  2295. {
  2296. visitor(m_dst);
  2297. visitor(m_iterator_record);
  2298. }
  2299. Operand dst() const { return m_dst; }
  2300. Operand iterator_record() const { return m_iterator_record; }
  2301. private:
  2302. Operand m_dst;
  2303. Operand m_iterator_record;
  2304. };
  2305. class ResolveThisBinding final : public Instruction {
  2306. public:
  2307. ResolveThisBinding()
  2308. : Instruction(Type::ResolveThisBinding)
  2309. {
  2310. }
  2311. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2312. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2313. void visit_operands_impl(Function<void(Operand&)>) { }
  2314. };
  2315. class ResolveSuperBase final : public Instruction {
  2316. public:
  2317. explicit ResolveSuperBase(Operand dst)
  2318. : Instruction(Type::ResolveSuperBase)
  2319. , m_dst(dst)
  2320. {
  2321. }
  2322. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2323. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2324. void visit_operands_impl(Function<void(Operand&)> visitor)
  2325. {
  2326. visitor(m_dst);
  2327. }
  2328. Operand dst() const { return m_dst; }
  2329. private:
  2330. Operand m_dst;
  2331. };
  2332. class GetNewTarget final : public Instruction {
  2333. public:
  2334. explicit GetNewTarget(Operand dst)
  2335. : Instruction(Type::GetNewTarget)
  2336. , m_dst(dst)
  2337. {
  2338. }
  2339. void execute_impl(Bytecode::Interpreter&) const;
  2340. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2341. void visit_operands_impl(Function<void(Operand&)> visitor)
  2342. {
  2343. visitor(m_dst);
  2344. }
  2345. Operand dst() const { return m_dst; }
  2346. private:
  2347. Operand m_dst;
  2348. };
  2349. class GetImportMeta final : public Instruction {
  2350. public:
  2351. explicit GetImportMeta(Operand dst)
  2352. : Instruction(Type::GetImportMeta)
  2353. , m_dst(dst)
  2354. {
  2355. }
  2356. void execute_impl(Bytecode::Interpreter&) const;
  2357. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2358. void visit_operands_impl(Function<void(Operand&)> visitor)
  2359. {
  2360. visitor(m_dst);
  2361. }
  2362. Operand dst() const { return m_dst; }
  2363. private:
  2364. Operand m_dst;
  2365. };
  2366. class TypeofBinding final : public Instruction {
  2367. public:
  2368. TypeofBinding(Operand dst, IdentifierTableIndex identifier)
  2369. : Instruction(Type::TypeofBinding)
  2370. , m_dst(dst)
  2371. , m_identifier(identifier)
  2372. {
  2373. }
  2374. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2375. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2376. void visit_operands_impl(Function<void(Operand&)> visitor)
  2377. {
  2378. visitor(m_dst);
  2379. }
  2380. Operand dst() const { return m_dst; }
  2381. IdentifierTableIndex identifier() const { return m_identifier; }
  2382. private:
  2383. Operand m_dst;
  2384. IdentifierTableIndex m_identifier;
  2385. mutable EnvironmentCoordinate m_cache;
  2386. };
  2387. class End final : public Instruction {
  2388. public:
  2389. constexpr static bool IsTerminator = true;
  2390. explicit End(Operand value)
  2391. : Instruction(Type::End)
  2392. , m_value(value)
  2393. {
  2394. }
  2395. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2396. void visit_operands_impl(Function<void(Operand&)> visitor)
  2397. {
  2398. visitor(m_value);
  2399. }
  2400. Operand value() const { return m_value; }
  2401. private:
  2402. Operand m_value;
  2403. };
  2404. class Dump final : public Instruction {
  2405. public:
  2406. explicit Dump(StringView text, Operand value)
  2407. : Instruction(Type::Dump)
  2408. , m_text(text)
  2409. , m_value(value)
  2410. {
  2411. }
  2412. void execute_impl(Bytecode::Interpreter&) const;
  2413. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2414. void visit_operands_impl(Function<void(Operand&)> visitor)
  2415. {
  2416. visitor(m_value);
  2417. }
  2418. private:
  2419. StringView m_text;
  2420. Operand m_value;
  2421. };
  2422. }