Op.h 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  1. /*
  2. * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.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. private:
  41. Operand m_dst;
  42. u32 m_rest_index;
  43. };
  44. class CreateArguments final : public Instruction {
  45. public:
  46. enum class Kind {
  47. Mapped,
  48. Unmapped,
  49. };
  50. CreateArguments(Kind kind, bool is_immutable)
  51. : Instruction(Type::CreateArguments)
  52. , m_kind(kind)
  53. , m_is_immutable(is_immutable)
  54. {
  55. }
  56. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  57. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  58. private:
  59. Kind m_kind;
  60. bool m_is_immutable { false };
  61. };
  62. class Mov final : public Instruction {
  63. public:
  64. Mov(Operand dst, Operand src)
  65. : Instruction(Type::Mov)
  66. , m_dst(dst)
  67. , m_src(src)
  68. {
  69. }
  70. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  71. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  72. Operand dst() const { return m_dst; }
  73. Operand src() const { return m_src; }
  74. private:
  75. Operand m_dst;
  76. Operand m_src;
  77. };
  78. #define JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(O) \
  79. O(Add, add) \
  80. O(BitwiseAnd, bitwise_and) \
  81. O(BitwiseOr, bitwise_or) \
  82. O(BitwiseXor, bitwise_xor) \
  83. O(GreaterThan, greater_than) \
  84. O(GreaterThanEquals, greater_than_equals) \
  85. O(LeftShift, left_shift) \
  86. O(LessThan, less_than) \
  87. O(LessThanEquals, less_than_equals) \
  88. O(Mul, mul) \
  89. O(RightShift, right_shift) \
  90. O(Sub, sub) \
  91. O(UnsignedRightShift, unsigned_right_shift)
  92. #define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \
  93. O(Div, div) \
  94. O(Exp, exp) \
  95. O(Mod, mod) \
  96. O(In, in) \
  97. O(InstanceOf, instance_of) \
  98. O(LooselyInequals, loosely_inequals) \
  99. O(LooselyEquals, loosely_equals) \
  100. O(StrictlyInequals, strict_inequals) \
  101. O(StrictlyEquals, strict_equals)
  102. #define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
  103. class OpTitleCase final : public Instruction { \
  104. public: \
  105. explicit OpTitleCase(Operand dst, Operand lhs, Operand rhs) \
  106. : Instruction(Type::OpTitleCase) \
  107. , m_dst(dst) \
  108. , m_lhs(lhs) \
  109. , m_rhs(rhs) \
  110. { \
  111. } \
  112. \
  113. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  114. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  115. \
  116. Operand dst() const { return m_dst; } \
  117. Operand lhs() const { return m_lhs; } \
  118. Operand rhs() const { return m_rhs; } \
  119. \
  120. private: \
  121. Operand m_dst; \
  122. Operand m_lhs; \
  123. Operand m_rhs; \
  124. };
  125. JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(JS_DECLARE_COMMON_BINARY_OP)
  126. JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(JS_DECLARE_COMMON_BINARY_OP)
  127. #undef JS_DECLARE_COMMON_BINARY_OP
  128. #define JS_ENUMERATE_COMMON_UNARY_OPS(O) \
  129. O(BitwiseNot, bitwise_not) \
  130. O(Not, not_) \
  131. O(UnaryPlus, unary_plus) \
  132. O(UnaryMinus, unary_minus) \
  133. O(Typeof, typeof_)
  134. #define JS_DECLARE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
  135. class OpTitleCase final : public Instruction { \
  136. public: \
  137. OpTitleCase(Operand dst, Operand src) \
  138. : Instruction(Type::OpTitleCase) \
  139. , m_dst(dst) \
  140. , m_src(src) \
  141. { \
  142. } \
  143. \
  144. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  145. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  146. \
  147. Operand dst() const { return m_dst; } \
  148. Operand src() const { return m_src; } \
  149. \
  150. private: \
  151. Operand m_dst; \
  152. Operand m_src; \
  153. };
  154. JS_ENUMERATE_COMMON_UNARY_OPS(JS_DECLARE_COMMON_UNARY_OP)
  155. #undef JS_DECLARE_COMMON_UNARY_OP
  156. class NewObject final : public Instruction {
  157. public:
  158. explicit NewObject(Operand dst)
  159. : Instruction(Type::NewObject)
  160. , m_dst(dst)
  161. {
  162. }
  163. void execute_impl(Bytecode::Interpreter&) const;
  164. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  165. Operand dst() const { return m_dst; }
  166. private:
  167. Operand m_dst;
  168. };
  169. class NewRegExp final : public Instruction {
  170. public:
  171. NewRegExp(Operand dst, StringTableIndex source_index, StringTableIndex flags_index, RegexTableIndex regex_index)
  172. : Instruction(Type::NewRegExp)
  173. , m_dst(dst)
  174. , m_source_index(source_index)
  175. , m_flags_index(flags_index)
  176. , m_regex_index(regex_index)
  177. {
  178. }
  179. void execute_impl(Bytecode::Interpreter&) const;
  180. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  181. Operand dst() const { return m_dst; }
  182. StringTableIndex source_index() const { return m_source_index; }
  183. StringTableIndex flags_index() const { return m_flags_index; }
  184. RegexTableIndex regex_index() const { return m_regex_index; }
  185. private:
  186. Operand m_dst;
  187. StringTableIndex m_source_index;
  188. StringTableIndex m_flags_index;
  189. RegexTableIndex m_regex_index;
  190. };
  191. #define JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(O) \
  192. O(TypeError)
  193. #define JS_DECLARE_NEW_BUILTIN_ERROR_OP(ErrorName) \
  194. class New##ErrorName final : public Instruction { \
  195. public: \
  196. New##ErrorName(Operand dst, StringTableIndex error_string) \
  197. : Instruction(Type::New##ErrorName) \
  198. , m_dst(dst) \
  199. , m_error_string(error_string) \
  200. { \
  201. } \
  202. \
  203. void execute_impl(Bytecode::Interpreter&) const; \
  204. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  205. \
  206. Operand dst() const { return m_dst; } \
  207. StringTableIndex error_string() const { return m_error_string; } \
  208. \
  209. private: \
  210. Operand m_dst; \
  211. StringTableIndex m_error_string; \
  212. };
  213. JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DECLARE_NEW_BUILTIN_ERROR_OP)
  214. #undef JS_DECLARE_NEW_BUILTIN_ERROR_OP
  215. // NOTE: This instruction is variable-width depending on the number of excluded names
  216. class CopyObjectExcludingProperties final : public Instruction {
  217. public:
  218. static constexpr bool IsVariableLength = true;
  219. CopyObjectExcludingProperties(Operand dst, Operand from_object, Vector<ScopedOperand> const& excluded_names)
  220. : Instruction(Type::CopyObjectExcludingProperties)
  221. , m_dst(dst)
  222. , m_from_object(from_object)
  223. , m_excluded_names_count(excluded_names.size())
  224. {
  225. for (size_t i = 0; i < m_excluded_names_count; i++)
  226. m_excluded_names[i] = excluded_names[i];
  227. }
  228. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  229. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  230. size_t length_impl() const
  231. {
  232. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_excluded_names_count);
  233. }
  234. Operand dst() const { return m_dst; }
  235. Operand from_object() const { return m_from_object; }
  236. size_t excluded_names_count() const { return m_excluded_names_count; }
  237. Operand const* excluded_names() const { return m_excluded_names; }
  238. private:
  239. Operand m_dst;
  240. Operand m_from_object;
  241. size_t m_excluded_names_count { 0 };
  242. Operand m_excluded_names[];
  243. };
  244. // NOTE: This instruction is variable-width depending on the number of elements!
  245. class NewArray final : public Instruction {
  246. public:
  247. static constexpr bool IsVariableLength = true;
  248. explicit NewArray(Operand dst)
  249. : Instruction(Type::NewArray)
  250. , m_dst(dst)
  251. , m_element_count(0)
  252. {
  253. }
  254. NewArray(Operand dst, ReadonlySpan<ScopedOperand> elements)
  255. : Instruction(Type::NewArray)
  256. , m_dst(dst)
  257. , m_element_count(elements.size())
  258. {
  259. for (size_t i = 0; i < m_element_count; ++i)
  260. m_elements[i] = elements[i];
  261. }
  262. void execute_impl(Bytecode::Interpreter&) const;
  263. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  264. Operand dst() const { return m_dst; }
  265. size_t length_impl() const
  266. {
  267. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_element_count);
  268. }
  269. size_t element_count() const { return m_element_count; }
  270. private:
  271. Operand m_dst;
  272. size_t m_element_count { 0 };
  273. Operand m_elements[];
  274. };
  275. class NewPrimitiveArray final : public Instruction {
  276. public:
  277. static constexpr bool IsVariableLength = true;
  278. NewPrimitiveArray(Operand dst, ReadonlySpan<Value> elements)
  279. : Instruction(Type::NewPrimitiveArray)
  280. , m_dst(dst)
  281. , m_element_count(elements.size())
  282. {
  283. for (size_t i = 0; i < m_element_count; ++i)
  284. m_elements[i] = elements[i];
  285. }
  286. size_t length_impl() const
  287. {
  288. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Value) * m_element_count);
  289. }
  290. void execute_impl(Bytecode::Interpreter&) const;
  291. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  292. Operand dst() const { return m_dst; }
  293. ReadonlySpan<Value> elements() const { return { m_elements, m_element_count }; }
  294. private:
  295. Operand m_dst;
  296. size_t m_element_count { 0 };
  297. Value m_elements[];
  298. };
  299. class ArrayAppend final : public Instruction {
  300. public:
  301. ArrayAppend(Operand dst, Operand src, bool is_spread)
  302. : Instruction(Type::ArrayAppend)
  303. , m_dst(dst)
  304. , m_src(src)
  305. , m_is_spread(is_spread)
  306. {
  307. }
  308. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  309. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  310. Operand dst() const { return m_dst; }
  311. Operand src() const { return m_src; }
  312. bool is_spread() const { return m_is_spread; }
  313. private:
  314. Operand m_dst;
  315. Operand m_src;
  316. bool m_is_spread = false;
  317. };
  318. class ImportCall final : public Instruction {
  319. public:
  320. ImportCall(Operand dst, Operand specifier, Operand options)
  321. : Instruction(Type::ImportCall)
  322. , m_dst(dst)
  323. , m_specifier(specifier)
  324. , m_options(options)
  325. {
  326. }
  327. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  328. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  329. Operand dst() const { return m_dst; }
  330. Operand specifier() const { return m_specifier; }
  331. Operand options() const { return m_options; }
  332. private:
  333. Operand m_dst;
  334. Operand m_specifier;
  335. Operand m_options;
  336. };
  337. class IteratorToArray final : public Instruction {
  338. public:
  339. explicit IteratorToArray(Operand dst, Operand iterator)
  340. : Instruction(Type::IteratorToArray)
  341. , m_dst(dst)
  342. , m_iterator(iterator)
  343. {
  344. }
  345. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  346. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  347. Operand dst() const { return m_dst; }
  348. Operand iterator() const { return m_iterator; }
  349. private:
  350. Operand m_dst;
  351. Operand m_iterator;
  352. };
  353. class ConcatString final : public Instruction {
  354. public:
  355. explicit ConcatString(Operand dst, Operand src)
  356. : Instruction(Type::ConcatString)
  357. , m_dst(dst)
  358. , m_src(src)
  359. {
  360. }
  361. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  362. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  363. Operand dst() const { return m_dst; }
  364. Operand src() const { return m_src; }
  365. private:
  366. Operand m_dst;
  367. Operand m_src;
  368. };
  369. enum class EnvironmentMode {
  370. Lexical,
  371. Var,
  372. };
  373. class CreateLexicalEnvironment final : public Instruction {
  374. public:
  375. explicit CreateLexicalEnvironment(u32 capacity = 0)
  376. : Instruction(Type::CreateLexicalEnvironment)
  377. , m_capacity(capacity)
  378. {
  379. }
  380. void execute_impl(Bytecode::Interpreter&) const;
  381. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  382. private:
  383. u32 m_capacity { 0 };
  384. };
  385. class CreateVariableEnvironment final : public Instruction {
  386. public:
  387. explicit CreateVariableEnvironment(u32 capacity = 0)
  388. : Instruction(Type::CreateVariableEnvironment)
  389. , m_capacity(capacity)
  390. {
  391. }
  392. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  393. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  394. private:
  395. u32 m_capacity { 0 };
  396. };
  397. class EnterObjectEnvironment final : public Instruction {
  398. public:
  399. explicit EnterObjectEnvironment(Operand object)
  400. : Instruction(Type::EnterObjectEnvironment)
  401. , m_object(object)
  402. {
  403. }
  404. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  405. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  406. Operand object() const { return m_object; }
  407. private:
  408. Operand m_object;
  409. };
  410. class Catch final : public Instruction {
  411. public:
  412. explicit Catch(Operand dst)
  413. : Instruction(Type::Catch)
  414. , m_dst(dst)
  415. {
  416. }
  417. void execute_impl(Bytecode::Interpreter&) const;
  418. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  419. Operand dst() const { return m_dst; }
  420. private:
  421. Operand m_dst;
  422. };
  423. class LeaveFinally final : public Instruction {
  424. public:
  425. explicit LeaveFinally()
  426. : Instruction(Type::LeaveFinally)
  427. {
  428. }
  429. void execute_impl(Bytecode::Interpreter&) const;
  430. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  431. };
  432. class RestoreScheduledJump final : public Instruction {
  433. public:
  434. explicit RestoreScheduledJump()
  435. : Instruction(Type::RestoreScheduledJump)
  436. {
  437. }
  438. void execute_impl(Bytecode::Interpreter&) const;
  439. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  440. };
  441. class CreateVariable final : public Instruction {
  442. public:
  443. explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false, bool is_strict = false)
  444. : Instruction(Type::CreateVariable)
  445. , m_identifier(identifier)
  446. , m_mode(mode)
  447. , m_is_immutable(is_immutable)
  448. , m_is_global(is_global)
  449. , m_is_strict(is_strict)
  450. {
  451. }
  452. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  453. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  454. IdentifierTableIndex identifier() const { return m_identifier; }
  455. EnvironmentMode mode() const { return m_mode; }
  456. bool is_immutable() const { return m_is_immutable; }
  457. bool is_global() const { return m_is_global; }
  458. bool is_strict() const { return m_is_strict; }
  459. private:
  460. IdentifierTableIndex m_identifier;
  461. EnvironmentMode m_mode;
  462. bool m_is_immutable : 4 { false };
  463. bool m_is_global : 4 { false };
  464. bool m_is_strict { false };
  465. };
  466. class SetVariable final : public Instruction {
  467. public:
  468. enum class InitializationMode {
  469. Initialize,
  470. Set,
  471. };
  472. explicit SetVariable(IdentifierTableIndex identifier, Operand src, u32 cache_index, InitializationMode initialization_mode = InitializationMode::Set, EnvironmentMode mode = EnvironmentMode::Lexical)
  473. : Instruction(Type::SetVariable)
  474. , m_identifier(identifier)
  475. , m_src(src)
  476. , m_mode(mode)
  477. , m_initialization_mode(initialization_mode)
  478. , m_cache_index(cache_index)
  479. {
  480. }
  481. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  482. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  483. IdentifierTableIndex identifier() const { return m_identifier; }
  484. Operand src() const { return m_src; }
  485. EnvironmentMode mode() const { return m_mode; }
  486. InitializationMode initialization_mode() const { return m_initialization_mode; }
  487. u32 cache_index() const { return m_cache_index; }
  488. private:
  489. IdentifierTableIndex m_identifier;
  490. Operand m_src;
  491. EnvironmentMode m_mode;
  492. InitializationMode m_initialization_mode { InitializationMode::Set };
  493. u32 m_cache_index { 0 };
  494. };
  495. class SetLocal final : public Instruction {
  496. public:
  497. SetLocal(size_t index, Operand src)
  498. : Instruction(Type::SetLocal)
  499. , m_index(index)
  500. , m_src(src)
  501. {
  502. }
  503. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  504. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  505. u32 index() const { return m_index; }
  506. Operand dst() const { return Operand(Operand::Type::Local, m_index); }
  507. Operand src() const { return m_src; }
  508. private:
  509. u32 m_index;
  510. Operand m_src;
  511. };
  512. class SetArgument final : public Instruction {
  513. public:
  514. SetArgument(size_t index, Operand src)
  515. : Instruction(Type::SetArgument)
  516. , m_index(index)
  517. , m_src(src)
  518. {
  519. }
  520. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  521. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  522. size_t index() const { return m_index; }
  523. Operand src() const { return m_src; }
  524. private:
  525. u32 m_index;
  526. Operand m_src;
  527. };
  528. class GetArgument final : public Instruction {
  529. public:
  530. GetArgument(Operand dst, size_t index)
  531. : Instruction(Type::GetArgument)
  532. , m_index(index)
  533. , m_dst(dst)
  534. {
  535. }
  536. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  537. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  538. u32 index() const { return m_index; }
  539. Operand dst() const { return m_dst; }
  540. private:
  541. u32 m_index;
  542. Operand m_dst;
  543. };
  544. class GetCalleeAndThisFromEnvironment final : public Instruction {
  545. public:
  546. explicit GetCalleeAndThisFromEnvironment(Operand callee, Operand this_value, IdentifierTableIndex identifier, u32 cache_index)
  547. : Instruction(Type::GetCalleeAndThisFromEnvironment)
  548. , m_identifier(identifier)
  549. , m_callee(callee)
  550. , m_this_value(this_value)
  551. , m_cache_index(cache_index)
  552. {
  553. }
  554. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  555. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  556. IdentifierTableIndex identifier() const { return m_identifier; }
  557. u32 cache_index() const { return m_cache_index; }
  558. Operand callee() const { return m_callee; }
  559. Operand this_() const { return m_this_value; }
  560. private:
  561. IdentifierTableIndex m_identifier;
  562. Operand m_callee;
  563. Operand m_this_value;
  564. u32 m_cache_index { 0 };
  565. };
  566. class GetVariable final : public Instruction {
  567. public:
  568. explicit GetVariable(Operand dst, IdentifierTableIndex identifier, u32 cache_index)
  569. : Instruction(Type::GetVariable)
  570. , m_dst(dst)
  571. , m_identifier(identifier)
  572. , m_cache_index(cache_index)
  573. {
  574. }
  575. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  576. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  577. Operand dst() const { return m_dst; }
  578. IdentifierTableIndex identifier() const { return m_identifier; }
  579. u32 cache_index() const { return m_cache_index; }
  580. private:
  581. Operand m_dst;
  582. IdentifierTableIndex m_identifier;
  583. u32 m_cache_index { 0 };
  584. };
  585. class GetGlobal final : public Instruction {
  586. public:
  587. GetGlobal(Operand dst, IdentifierTableIndex identifier, u32 cache_index)
  588. : Instruction(Type::GetGlobal)
  589. , m_dst(dst)
  590. , m_identifier(identifier)
  591. , m_cache_index(cache_index)
  592. {
  593. }
  594. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  595. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  596. Operand dst() const { return m_dst; }
  597. IdentifierTableIndex identifier() const { return m_identifier; }
  598. u32 cache_index() const { return m_cache_index; }
  599. private:
  600. Operand m_dst;
  601. IdentifierTableIndex m_identifier;
  602. u32 m_cache_index { 0 };
  603. };
  604. class DeleteVariable final : public Instruction {
  605. public:
  606. explicit DeleteVariable(Operand dst, IdentifierTableIndex identifier)
  607. : Instruction(Type::DeleteVariable)
  608. , m_dst(dst)
  609. , m_identifier(identifier)
  610. {
  611. }
  612. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  613. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  614. Operand dst() const { return m_dst; }
  615. IdentifierTableIndex identifier() const { return m_identifier; }
  616. private:
  617. Operand m_dst;
  618. IdentifierTableIndex m_identifier;
  619. };
  620. class GetById final : public Instruction {
  621. public:
  622. GetById(Operand dst, Operand base, IdentifierTableIndex property, Optional<IdentifierTableIndex> base_identifier, u32 cache_index)
  623. : Instruction(Type::GetById)
  624. , m_dst(dst)
  625. , m_base(base)
  626. , m_property(property)
  627. , m_base_identifier(move(base_identifier))
  628. , m_cache_index(cache_index)
  629. {
  630. }
  631. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  632. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  633. Operand dst() const { return m_dst; }
  634. Operand base() const { return m_base; }
  635. IdentifierTableIndex property() const { return m_property; }
  636. u32 cache_index() const { return m_cache_index; }
  637. private:
  638. Operand m_dst;
  639. Operand m_base;
  640. IdentifierTableIndex m_property;
  641. Optional<IdentifierTableIndex> m_base_identifier;
  642. u32 m_cache_index { 0 };
  643. };
  644. class GetByIdWithThis final : public Instruction {
  645. public:
  646. GetByIdWithThis(Operand dst, Operand base, IdentifierTableIndex property, Operand this_value, u32 cache_index)
  647. : Instruction(Type::GetByIdWithThis)
  648. , m_dst(dst)
  649. , m_base(base)
  650. , m_property(property)
  651. , m_this_value(this_value)
  652. , m_cache_index(cache_index)
  653. {
  654. }
  655. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  656. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  657. Operand dst() const { return m_dst; }
  658. Operand base() const { return m_base; }
  659. IdentifierTableIndex property() const { return m_property; }
  660. Operand this_value() const { return m_this_value; }
  661. u32 cache_index() const { return m_cache_index; }
  662. private:
  663. Operand m_dst;
  664. Operand m_base;
  665. IdentifierTableIndex m_property;
  666. Operand m_this_value;
  667. u32 m_cache_index { 0 };
  668. };
  669. class GetPrivateById final : public Instruction {
  670. public:
  671. explicit GetPrivateById(Operand dst, Operand base, IdentifierTableIndex property)
  672. : Instruction(Type::GetPrivateById)
  673. , m_dst(dst)
  674. , m_base(base)
  675. , m_property(property)
  676. {
  677. }
  678. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  679. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  680. Operand dst() const { return m_dst; }
  681. Operand base() const { return m_base; }
  682. IdentifierTableIndex property() const { return m_property; }
  683. private:
  684. Operand m_dst;
  685. Operand m_base;
  686. IdentifierTableIndex m_property;
  687. };
  688. class HasPrivateId final : public Instruction {
  689. public:
  690. HasPrivateId(Operand dst, Operand base, IdentifierTableIndex property)
  691. : Instruction(Type::HasPrivateId)
  692. , m_dst(dst)
  693. , m_base(base)
  694. , m_property(property)
  695. {
  696. }
  697. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  698. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  699. Operand dst() const { return m_dst; }
  700. Operand base() const { return m_base; }
  701. IdentifierTableIndex property() const { return m_property; }
  702. private:
  703. Operand m_dst;
  704. Operand m_base;
  705. IdentifierTableIndex m_property;
  706. };
  707. enum class PropertyKind {
  708. Getter,
  709. Setter,
  710. KeyValue,
  711. DirectKeyValue, // Used for Object expressions. Always sets an own property, never calls a setter.
  712. Spread,
  713. ProtoSetter,
  714. };
  715. class PutById final : public Instruction {
  716. public:
  717. explicit PutById(Operand base, IdentifierTableIndex property, Operand src, PropertyKind kind, u32 cache_index, Optional<IdentifierTableIndex> base_identifier = {})
  718. : Instruction(Type::PutById)
  719. , m_base(base)
  720. , m_property(property)
  721. , m_src(src)
  722. , m_kind(kind)
  723. , m_cache_index(cache_index)
  724. , m_base_identifier(move(base_identifier))
  725. {
  726. }
  727. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  728. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  729. Operand base() const { return m_base; }
  730. IdentifierTableIndex property() const { return m_property; }
  731. Operand src() const { return m_src; }
  732. PropertyKind kind() const { return m_kind; }
  733. u32 cache_index() const { return m_cache_index; }
  734. private:
  735. Operand m_base;
  736. IdentifierTableIndex m_property;
  737. Operand m_src;
  738. PropertyKind m_kind;
  739. u32 m_cache_index { 0 };
  740. Optional<IdentifierTableIndex> m_base_identifier {};
  741. };
  742. class PutByIdWithThis final : public Instruction {
  743. public:
  744. PutByIdWithThis(Operand base, Operand this_value, IdentifierTableIndex property, Operand src, PropertyKind kind, u32 cache_index)
  745. : Instruction(Type::PutByIdWithThis)
  746. , m_base(base)
  747. , m_this_value(this_value)
  748. , m_property(property)
  749. , m_src(src)
  750. , m_kind(kind)
  751. , m_cache_index(cache_index)
  752. {
  753. }
  754. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  755. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  756. Operand base() const { return m_base; }
  757. Operand this_value() const { return m_this_value; }
  758. IdentifierTableIndex property() const { return m_property; }
  759. Operand src() const { return m_src; }
  760. PropertyKind kind() const { return m_kind; }
  761. u32 cache_index() const { return m_cache_index; }
  762. private:
  763. Operand m_base;
  764. Operand m_this_value;
  765. IdentifierTableIndex m_property;
  766. Operand m_src;
  767. PropertyKind m_kind;
  768. u32 m_cache_index { 0 };
  769. };
  770. class PutPrivateById final : public Instruction {
  771. public:
  772. explicit PutPrivateById(Operand base, IdentifierTableIndex property, Operand src, PropertyKind kind = PropertyKind::KeyValue)
  773. : Instruction(Type::PutPrivateById)
  774. , m_base(base)
  775. , m_property(property)
  776. , m_src(src)
  777. , m_kind(kind)
  778. {
  779. }
  780. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  781. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  782. Operand base() const { return m_base; }
  783. IdentifierTableIndex property() const { return m_property; }
  784. Operand src() const { return m_src; }
  785. private:
  786. Operand m_base;
  787. IdentifierTableIndex m_property;
  788. Operand m_src;
  789. PropertyKind m_kind;
  790. };
  791. class DeleteById final : public Instruction {
  792. public:
  793. explicit DeleteById(Operand dst, Operand base, IdentifierTableIndex property)
  794. : Instruction(Type::DeleteById)
  795. , m_dst(dst)
  796. , m_base(base)
  797. , m_property(property)
  798. {
  799. }
  800. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  801. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  802. Operand dst() const { return m_dst; }
  803. Operand base() const { return m_base; }
  804. IdentifierTableIndex property() const { return m_property; }
  805. private:
  806. Operand m_dst;
  807. Operand m_base;
  808. IdentifierTableIndex m_property;
  809. };
  810. class DeleteByIdWithThis final : public Instruction {
  811. public:
  812. DeleteByIdWithThis(Operand dst, Operand base, Operand this_value, IdentifierTableIndex property)
  813. : Instruction(Type::DeleteByIdWithThis)
  814. , m_dst(dst)
  815. , m_base(base)
  816. , m_this_value(this_value)
  817. , m_property(property)
  818. {
  819. }
  820. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  821. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  822. Operand dst() const { return m_dst; }
  823. Operand base() const { return m_base; }
  824. Operand this_value() const { return m_this_value; }
  825. IdentifierTableIndex property() const { return m_property; }
  826. private:
  827. Operand m_dst;
  828. Operand m_base;
  829. Operand m_this_value;
  830. IdentifierTableIndex m_property;
  831. };
  832. class GetByValue final : public Instruction {
  833. public:
  834. GetByValue(Operand dst, Operand base, Operand property, Optional<IdentifierTableIndex> base_identifier = {})
  835. : Instruction(Type::GetByValue)
  836. , m_dst(dst)
  837. , m_base(base)
  838. , m_property(property)
  839. , m_base_identifier(move(base_identifier))
  840. {
  841. }
  842. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  843. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  844. Operand dst() const { return m_dst; }
  845. Operand base() const { return m_base; }
  846. Operand property() const { return m_property; }
  847. Optional<DeprecatedFlyString const&> base_identifier(Bytecode::Interpreter const&) const;
  848. private:
  849. Operand m_dst;
  850. Operand m_base;
  851. Operand m_property;
  852. Optional<IdentifierTableIndex> m_base_identifier;
  853. };
  854. class GetByValueWithThis final : public Instruction {
  855. public:
  856. GetByValueWithThis(Operand dst, Operand base, Operand property, Operand this_value)
  857. : Instruction(Type::GetByValueWithThis)
  858. , m_dst(dst)
  859. , m_base(base)
  860. , m_property(property)
  861. , m_this_value(this_value)
  862. {
  863. }
  864. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  865. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  866. Operand dst() const { return m_dst; }
  867. Operand base() const { return m_base; }
  868. Operand property() const { return m_property; }
  869. Operand this_value() const { return m_this_value; }
  870. private:
  871. Operand m_dst;
  872. Operand m_base;
  873. Operand m_property;
  874. Operand m_this_value;
  875. };
  876. class PutByValue final : public Instruction {
  877. public:
  878. PutByValue(Operand base, Operand property, Operand src, PropertyKind kind = PropertyKind::KeyValue, Optional<IdentifierTableIndex> base_identifier = {})
  879. : Instruction(Type::PutByValue)
  880. , m_base(base)
  881. , m_property(property)
  882. , m_src(src)
  883. , m_kind(kind)
  884. , m_base_identifier(move(base_identifier))
  885. {
  886. }
  887. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  888. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  889. Operand base() const { return m_base; }
  890. Operand property() const { return m_property; }
  891. Operand src() const { return m_src; }
  892. PropertyKind kind() const { return m_kind; }
  893. private:
  894. Operand m_base;
  895. Operand m_property;
  896. Operand m_src;
  897. PropertyKind m_kind;
  898. Optional<IdentifierTableIndex> m_base_identifier;
  899. };
  900. class PutByValueWithThis final : public Instruction {
  901. public:
  902. PutByValueWithThis(Operand base, Operand property, Operand this_value, Operand src, PropertyKind kind = PropertyKind::KeyValue)
  903. : Instruction(Type::PutByValueWithThis)
  904. , m_base(base)
  905. , m_property(property)
  906. , m_this_value(this_value)
  907. , m_src(src)
  908. , m_kind(kind)
  909. {
  910. }
  911. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  912. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  913. Operand base() const { return m_base; }
  914. Operand property() const { return m_property; }
  915. Operand this_value() const { return m_this_value; }
  916. Operand src() const { return m_src; }
  917. PropertyKind kind() const { return m_kind; }
  918. private:
  919. Operand m_base;
  920. Operand m_property;
  921. Operand m_this_value;
  922. Operand m_src;
  923. PropertyKind m_kind;
  924. };
  925. class DeleteByValue final : public Instruction {
  926. public:
  927. DeleteByValue(Operand dst, Operand base, Operand property)
  928. : Instruction(Type::DeleteByValue)
  929. , m_dst(dst)
  930. , m_base(base)
  931. , m_property(property)
  932. {
  933. }
  934. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  935. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  936. Operand dst() const { return m_dst; }
  937. Operand base() const { return m_base; }
  938. Operand property() const { return m_property; }
  939. private:
  940. Operand m_dst;
  941. Operand m_base;
  942. Operand m_property;
  943. };
  944. class DeleteByValueWithThis final : public Instruction {
  945. public:
  946. DeleteByValueWithThis(Operand dst, Operand base, Operand this_value, Operand property)
  947. : Instruction(Type::DeleteByValueWithThis)
  948. , m_dst(dst)
  949. , m_base(base)
  950. , m_this_value(this_value)
  951. , m_property(property)
  952. {
  953. }
  954. Operand dst() const { return m_dst; }
  955. Operand base() const { return m_base; }
  956. Operand this_value() const { return m_this_value; }
  957. Operand property() const { return m_property; }
  958. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  959. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  960. private:
  961. Operand m_dst;
  962. Operand m_base;
  963. Operand m_this_value;
  964. Operand m_property;
  965. };
  966. class Jump final : public Instruction {
  967. public:
  968. constexpr static bool IsTerminator = true;
  969. explicit Jump(Label target)
  970. : Instruction(Type::Jump)
  971. , m_target(target)
  972. {
  973. }
  974. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  975. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  976. void visit_labels_impl(Function<void(Label&)> visitor)
  977. {
  978. visitor(m_target);
  979. }
  980. auto& target() const { return m_target; }
  981. protected:
  982. Label m_target;
  983. };
  984. class JumpIf final : public Instruction {
  985. public:
  986. constexpr static bool IsTerminator = true;
  987. explicit JumpIf(Operand condition, Label true_target, Label false_target)
  988. : Instruction(Type::JumpIf)
  989. , m_condition(condition)
  990. , m_true_target(true_target)
  991. , m_false_target(false_target)
  992. {
  993. }
  994. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  995. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  996. void visit_labels_impl(Function<void(Label&)> visitor)
  997. {
  998. visitor(m_true_target);
  999. visitor(m_false_target);
  1000. }
  1001. Operand condition() const { return m_condition; }
  1002. auto& true_target() const { return m_true_target; }
  1003. auto& false_target() const { return m_false_target; }
  1004. private:
  1005. Operand m_condition;
  1006. Label m_true_target;
  1007. Label m_false_target;
  1008. };
  1009. class JumpTrue final : public Instruction {
  1010. public:
  1011. constexpr static bool IsTerminator = true;
  1012. explicit JumpTrue(Operand condition, Label target)
  1013. : Instruction(Type::JumpTrue)
  1014. , m_condition(condition)
  1015. , m_target(target)
  1016. {
  1017. }
  1018. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1019. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1020. void visit_labels_impl(Function<void(Label&)> visitor)
  1021. {
  1022. visitor(m_target);
  1023. }
  1024. Operand condition() const { return m_condition; }
  1025. auto& target() const { return m_target; }
  1026. private:
  1027. Operand m_condition;
  1028. Label m_target;
  1029. };
  1030. class JumpFalse final : public Instruction {
  1031. public:
  1032. constexpr static bool IsTerminator = true;
  1033. explicit JumpFalse(Operand condition, Label target)
  1034. : Instruction(Type::JumpFalse)
  1035. , m_condition(condition)
  1036. , m_target(target)
  1037. {
  1038. }
  1039. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1040. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1041. void visit_labels_impl(Function<void(Label&)> visitor)
  1042. {
  1043. visitor(m_target);
  1044. }
  1045. Operand condition() const { return m_condition; }
  1046. auto& target() const { return m_target; }
  1047. private:
  1048. Operand m_condition;
  1049. Label m_target;
  1050. };
  1051. #define JS_ENUMERATE_COMPARISON_OPS(X) \
  1052. X(LessThan, less_than) \
  1053. X(LessThanEquals, less_than_equals) \
  1054. X(GreaterThan, greater_than) \
  1055. X(GreaterThanEquals, greater_than_equals) \
  1056. X(LooselyEquals, loosely_equals) \
  1057. X(LooselyInequals, loosely_inequals) \
  1058. X(StrictlyEquals, strict_equals) \
  1059. X(StrictlyInequals, strict_inequals)
  1060. #define DECLARE_COMPARISON_OP(op_TitleCase, op_snake_case) \
  1061. class Jump##op_TitleCase final : public Instruction { \
  1062. public: \
  1063. constexpr static bool IsTerminator = true; \
  1064. \
  1065. explicit Jump##op_TitleCase(Operand lhs, Operand rhs, Label true_target, Label false_target) \
  1066. : Instruction(Type::Jump##op_TitleCase) \
  1067. , m_lhs(lhs) \
  1068. , m_rhs(rhs) \
  1069. , m_true_target(true_target) \
  1070. , m_false_target(false_target) \
  1071. { \
  1072. } \
  1073. \
  1074. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  1075. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  1076. void visit_labels_impl(Function<void(Label&)> visitor) \
  1077. { \
  1078. visitor(m_true_target); \
  1079. visitor(m_false_target); \
  1080. } \
  1081. \
  1082. Operand lhs() const { return m_lhs; } \
  1083. Operand rhs() const { return m_rhs; } \
  1084. auto& true_target() const { return m_true_target; } \
  1085. auto& false_target() const { return m_false_target; } \
  1086. \
  1087. private: \
  1088. Operand m_lhs; \
  1089. Operand m_rhs; \
  1090. Label m_true_target; \
  1091. Label m_false_target; \
  1092. };
  1093. JS_ENUMERATE_COMPARISON_OPS(DECLARE_COMPARISON_OP)
  1094. class JumpNullish final : public Instruction {
  1095. public:
  1096. constexpr static bool IsTerminator = true;
  1097. explicit JumpNullish(Operand condition, Label true_target, Label false_target)
  1098. : Instruction(Type::JumpNullish)
  1099. , m_condition(condition)
  1100. , m_true_target(true_target)
  1101. , m_false_target(false_target)
  1102. {
  1103. }
  1104. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1105. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1106. void visit_labels_impl(Function<void(Label&)> visitor)
  1107. {
  1108. visitor(m_true_target);
  1109. visitor(m_false_target);
  1110. }
  1111. Operand condition() const { return m_condition; }
  1112. auto& true_target() const { return m_true_target; }
  1113. auto& false_target() const { return m_false_target; }
  1114. private:
  1115. Operand m_condition;
  1116. Label m_true_target;
  1117. Label m_false_target;
  1118. };
  1119. class JumpUndefined final : public Instruction {
  1120. public:
  1121. constexpr static bool IsTerminator = true;
  1122. explicit JumpUndefined(Operand condition, Label true_target, Label false_target)
  1123. : Instruction(Type::JumpUndefined)
  1124. , m_condition(condition)
  1125. , m_true_target(true_target)
  1126. , m_false_target(false_target)
  1127. {
  1128. }
  1129. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1130. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1131. void visit_labels_impl(Function<void(Label&)> visitor)
  1132. {
  1133. visitor(m_true_target);
  1134. visitor(m_false_target);
  1135. }
  1136. Operand condition() const { return m_condition; }
  1137. auto& true_target() const { return m_true_target; }
  1138. auto& false_target() const { return m_false_target; }
  1139. private:
  1140. Operand m_condition;
  1141. Label m_true_target;
  1142. Label m_false_target;
  1143. };
  1144. enum class CallType : u8 {
  1145. Call,
  1146. Construct,
  1147. DirectEval,
  1148. };
  1149. class Call final : public Instruction {
  1150. public:
  1151. static constexpr bool IsVariableLength = true;
  1152. Call(CallType type, Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {}, Optional<Builtin> builtin = {})
  1153. : Instruction(Type::Call)
  1154. , m_dst(dst)
  1155. , m_callee(callee)
  1156. , m_this_value(this_value)
  1157. , m_argument_count(arguments.size())
  1158. , m_type(type)
  1159. , m_builtin(builtin)
  1160. , m_expression_string(expression_string)
  1161. {
  1162. for (size_t i = 0; i < arguments.size(); ++i)
  1163. m_arguments[i] = arguments[i];
  1164. }
  1165. size_t length_impl() const
  1166. {
  1167. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
  1168. }
  1169. CallType call_type() const { return m_type; }
  1170. Operand dst() const { return m_dst; }
  1171. Operand callee() const { return m_callee; }
  1172. Operand this_value() const { return m_this_value; }
  1173. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1174. u32 argument_count() const { return m_argument_count; }
  1175. Optional<Builtin> const& builtin() const { return m_builtin; }
  1176. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1177. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1178. private:
  1179. Operand m_dst;
  1180. Operand m_callee;
  1181. Operand m_this_value;
  1182. u32 m_argument_count { 0 };
  1183. CallType m_type;
  1184. Optional<Builtin> m_builtin;
  1185. Optional<StringTableIndex> m_expression_string;
  1186. Operand m_arguments[];
  1187. };
  1188. class CallWithArgumentArray final : public Instruction {
  1189. public:
  1190. CallWithArgumentArray(CallType type, Operand dst, Operand callee, Operand this_value, Operand arguments, Optional<StringTableIndex> expression_string = {})
  1191. : Instruction(Type::CallWithArgumentArray)
  1192. , m_dst(dst)
  1193. , m_callee(callee)
  1194. , m_this_value(this_value)
  1195. , m_arguments(arguments)
  1196. , m_type(type)
  1197. , m_expression_string(expression_string)
  1198. {
  1199. }
  1200. Operand dst() const { return m_dst; }
  1201. CallType call_type() const { return m_type; }
  1202. Operand callee() const { return m_callee; }
  1203. Operand this_value() const { return m_this_value; }
  1204. Operand arguments() const { return m_arguments; }
  1205. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1206. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1207. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1208. private:
  1209. Operand m_dst;
  1210. Operand m_callee;
  1211. Operand m_this_value;
  1212. Operand m_arguments;
  1213. CallType m_type;
  1214. Optional<StringTableIndex> m_expression_string;
  1215. };
  1216. class SuperCallWithArgumentArray : public Instruction {
  1217. public:
  1218. explicit SuperCallWithArgumentArray(Operand dst, Operand arguments, bool is_synthetic)
  1219. : Instruction(Type::SuperCallWithArgumentArray)
  1220. , m_dst(dst)
  1221. , m_arguments(arguments)
  1222. , m_is_synthetic(is_synthetic)
  1223. {
  1224. }
  1225. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1226. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1227. Operand dst() const { return m_dst; }
  1228. Operand arguments() const { return m_arguments; }
  1229. bool is_synthetic() const { return m_is_synthetic; }
  1230. private:
  1231. Operand m_dst;
  1232. Operand m_arguments;
  1233. bool m_is_synthetic;
  1234. };
  1235. class NewClass final : public Instruction {
  1236. public:
  1237. explicit NewClass(Operand dst, Optional<Operand> super_class, ClassExpression const& class_expression, Optional<IdentifierTableIndex> lhs_name)
  1238. : Instruction(Type::NewClass)
  1239. , m_dst(dst)
  1240. , m_super_class(super_class)
  1241. , m_class_expression(class_expression)
  1242. , m_lhs_name(lhs_name)
  1243. {
  1244. }
  1245. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1246. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1247. Operand dst() const { return m_dst; }
  1248. Optional<Operand> const& super_class() const { return m_super_class; }
  1249. ClassExpression const& class_expression() const { return m_class_expression; }
  1250. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  1251. private:
  1252. Operand m_dst;
  1253. Optional<Operand> m_super_class;
  1254. ClassExpression const& m_class_expression;
  1255. Optional<IdentifierTableIndex> m_lhs_name;
  1256. };
  1257. class NewFunction final : public Instruction {
  1258. public:
  1259. explicit NewFunction(Operand dst, FunctionNode const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Operand> home_object = {})
  1260. : Instruction(Type::NewFunction)
  1261. , m_dst(dst)
  1262. , m_function_node(function_node)
  1263. , m_lhs_name(lhs_name)
  1264. , m_home_object(move(home_object))
  1265. {
  1266. }
  1267. void execute_impl(Bytecode::Interpreter&) const;
  1268. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1269. Operand dst() const { return m_dst; }
  1270. FunctionNode const& function_node() const { return m_function_node; }
  1271. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  1272. Optional<Operand> const& home_object() const { return m_home_object; }
  1273. private:
  1274. Operand m_dst;
  1275. FunctionNode const& m_function_node;
  1276. Optional<IdentifierTableIndex> m_lhs_name;
  1277. Optional<Operand> m_home_object;
  1278. };
  1279. class BlockDeclarationInstantiation final : public Instruction {
  1280. public:
  1281. explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
  1282. : Instruction(Type::BlockDeclarationInstantiation)
  1283. , m_scope_node(scope_node)
  1284. {
  1285. }
  1286. void execute_impl(Bytecode::Interpreter&) const;
  1287. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1288. ScopeNode const& scope_node() const { return m_scope_node; }
  1289. private:
  1290. ScopeNode const& m_scope_node;
  1291. };
  1292. class Return final : public Instruction {
  1293. public:
  1294. constexpr static bool IsTerminator = true;
  1295. explicit Return(Optional<Operand> value = {})
  1296. : Instruction(Type::Return)
  1297. , m_value(value)
  1298. {
  1299. }
  1300. void execute_impl(Bytecode::Interpreter&) const;
  1301. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1302. Optional<Operand> const& value() const { return m_value; }
  1303. private:
  1304. Optional<Operand> m_value;
  1305. };
  1306. class Increment final : public Instruction {
  1307. public:
  1308. explicit Increment(Operand dst)
  1309. : Instruction(Type::Increment)
  1310. , m_dst(dst)
  1311. {
  1312. }
  1313. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1314. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1315. Operand dst() const { return m_dst; }
  1316. private:
  1317. Operand m_dst;
  1318. };
  1319. class PostfixIncrement final : public Instruction {
  1320. public:
  1321. explicit PostfixIncrement(Operand dst, Operand src)
  1322. : Instruction(Type::PostfixIncrement)
  1323. , m_dst(dst)
  1324. , m_src(src)
  1325. {
  1326. }
  1327. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1328. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1329. Operand dst() const { return m_dst; }
  1330. Operand src() const { return m_src; }
  1331. private:
  1332. Operand m_dst;
  1333. Operand m_src;
  1334. };
  1335. class Decrement final : public Instruction {
  1336. public:
  1337. explicit Decrement(Operand dst)
  1338. : Instruction(Type::Decrement)
  1339. , m_dst(dst)
  1340. {
  1341. }
  1342. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1343. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1344. Operand dst() const { return m_dst; }
  1345. private:
  1346. Operand m_dst;
  1347. };
  1348. class PostfixDecrement final : public Instruction {
  1349. public:
  1350. explicit PostfixDecrement(Operand dst, Operand src)
  1351. : Instruction(Type::PostfixDecrement)
  1352. , m_dst(dst)
  1353. , m_src(src)
  1354. {
  1355. }
  1356. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1357. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1358. Operand dst() const { return m_dst; }
  1359. Operand src() const { return m_src; }
  1360. private:
  1361. Operand m_dst;
  1362. Operand m_src;
  1363. };
  1364. class Throw final : public Instruction {
  1365. public:
  1366. constexpr static bool IsTerminator = true;
  1367. explicit Throw(Operand src)
  1368. : Instruction(Type::Throw)
  1369. , m_src(src)
  1370. {
  1371. }
  1372. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1373. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1374. Operand src() const { return m_src; }
  1375. private:
  1376. Operand m_src;
  1377. };
  1378. class ThrowIfNotObject final : public Instruction {
  1379. public:
  1380. ThrowIfNotObject(Operand src)
  1381. : Instruction(Type::ThrowIfNotObject)
  1382. , m_src(src)
  1383. {
  1384. }
  1385. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1386. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1387. Operand src() const { return m_src; }
  1388. private:
  1389. Operand m_src;
  1390. };
  1391. class ThrowIfNullish final : public Instruction {
  1392. public:
  1393. explicit ThrowIfNullish(Operand src)
  1394. : Instruction(Type::ThrowIfNullish)
  1395. , m_src(src)
  1396. {
  1397. }
  1398. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1399. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1400. Operand src() const { return m_src; }
  1401. private:
  1402. Operand m_src;
  1403. };
  1404. class ThrowIfTDZ final : public Instruction {
  1405. public:
  1406. explicit ThrowIfTDZ(Operand src)
  1407. : Instruction(Type::ThrowIfTDZ)
  1408. , m_src(src)
  1409. {
  1410. }
  1411. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1412. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1413. Operand src() const { return m_src; }
  1414. private:
  1415. Operand m_src;
  1416. };
  1417. class EnterUnwindContext final : public Instruction {
  1418. public:
  1419. constexpr static bool IsTerminator = true;
  1420. EnterUnwindContext(Label entry_point)
  1421. : Instruction(Type::EnterUnwindContext)
  1422. , m_entry_point(move(entry_point))
  1423. {
  1424. }
  1425. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1426. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1427. void visit_labels_impl(Function<void(Label&)> visitor)
  1428. {
  1429. visitor(m_entry_point);
  1430. }
  1431. auto& entry_point() const { return m_entry_point; }
  1432. private:
  1433. Label m_entry_point;
  1434. };
  1435. class ScheduleJump final : public Instruction {
  1436. public:
  1437. // Note: We use this instruction to tell the next `finally` block to
  1438. // continue execution with a specific break/continue target;
  1439. constexpr static bool IsTerminator = true;
  1440. ScheduleJump(Label target)
  1441. : Instruction(Type::ScheduleJump)
  1442. , m_target(target)
  1443. {
  1444. }
  1445. Label target() const { return m_target; }
  1446. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1447. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1448. void visit_labels_impl(Function<void(Label&)> visitor)
  1449. {
  1450. visitor(m_target);
  1451. }
  1452. private:
  1453. Label m_target;
  1454. };
  1455. class LeaveLexicalEnvironment final : public Instruction {
  1456. public:
  1457. LeaveLexicalEnvironment()
  1458. : Instruction(Type::LeaveLexicalEnvironment)
  1459. {
  1460. }
  1461. void execute_impl(Bytecode::Interpreter&) const;
  1462. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1463. };
  1464. class LeaveUnwindContext final : public Instruction {
  1465. public:
  1466. LeaveUnwindContext()
  1467. : Instruction(Type::LeaveUnwindContext)
  1468. {
  1469. }
  1470. void execute_impl(Bytecode::Interpreter&) const;
  1471. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1472. };
  1473. class ContinuePendingUnwind final : public Instruction {
  1474. public:
  1475. constexpr static bool IsTerminator = true;
  1476. explicit ContinuePendingUnwind(Label resume_target)
  1477. : Instruction(Type::ContinuePendingUnwind)
  1478. , m_resume_target(resume_target)
  1479. {
  1480. }
  1481. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1482. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1483. void visit_labels_impl(Function<void(Label&)> visitor)
  1484. {
  1485. visitor(m_resume_target);
  1486. }
  1487. auto& resume_target() const { return m_resume_target; }
  1488. private:
  1489. Label m_resume_target;
  1490. };
  1491. class Yield final : public Instruction {
  1492. public:
  1493. constexpr static bool IsTerminator = true;
  1494. explicit Yield(Label continuation_label, Operand value)
  1495. : Instruction(Type::Yield)
  1496. , m_continuation_label(continuation_label)
  1497. , m_value(value)
  1498. {
  1499. }
  1500. explicit Yield(nullptr_t, Operand value)
  1501. : Instruction(Type::Yield)
  1502. , m_value(value)
  1503. {
  1504. }
  1505. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1506. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1507. void visit_labels_impl(Function<void(Label&)> visitor)
  1508. {
  1509. if (m_continuation_label.has_value())
  1510. visitor(m_continuation_label.value());
  1511. }
  1512. auto& continuation() const { return m_continuation_label; }
  1513. Operand value() const { return m_value; }
  1514. private:
  1515. Optional<Label> m_continuation_label;
  1516. Operand m_value;
  1517. };
  1518. class Await final : public Instruction {
  1519. public:
  1520. constexpr static bool IsTerminator = true;
  1521. explicit Await(Label continuation_label, Operand argument)
  1522. : Instruction(Type::Await)
  1523. , m_continuation_label(continuation_label)
  1524. , m_argument(argument)
  1525. {
  1526. }
  1527. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1528. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1529. void visit_labels_impl(Function<void(Label&)> visitor)
  1530. {
  1531. visitor(m_continuation_label);
  1532. }
  1533. auto& continuation() const { return m_continuation_label; }
  1534. Operand argument() const { return m_argument; }
  1535. private:
  1536. Label m_continuation_label;
  1537. Operand m_argument;
  1538. };
  1539. class GetIterator final : public Instruction {
  1540. public:
  1541. GetIterator(Operand dst, Operand iterable, IteratorHint hint = IteratorHint::Sync)
  1542. : Instruction(Type::GetIterator)
  1543. , m_dst(dst)
  1544. , m_iterable(iterable)
  1545. , m_hint(hint)
  1546. {
  1547. }
  1548. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1549. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1550. Operand dst() const { return m_dst; }
  1551. Operand iterable() const { return m_iterable; }
  1552. IteratorHint hint() const { return m_hint; }
  1553. private:
  1554. Operand m_dst;
  1555. Operand m_iterable;
  1556. IteratorHint m_hint { IteratorHint::Sync };
  1557. };
  1558. class GetObjectFromIteratorRecord final : public Instruction {
  1559. public:
  1560. GetObjectFromIteratorRecord(Operand object, Operand iterator_record)
  1561. : Instruction(Type::GetObjectFromIteratorRecord)
  1562. , m_object(object)
  1563. , m_iterator_record(iterator_record)
  1564. {
  1565. }
  1566. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1567. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1568. Operand object() const { return m_object; }
  1569. Operand iterator_record() const { return m_iterator_record; }
  1570. private:
  1571. Operand m_object;
  1572. Operand m_iterator_record;
  1573. };
  1574. class GetNextMethodFromIteratorRecord final : public Instruction {
  1575. public:
  1576. GetNextMethodFromIteratorRecord(Operand next_method, Operand iterator_record)
  1577. : Instruction(Type::GetNextMethodFromIteratorRecord)
  1578. , m_next_method(next_method)
  1579. , m_iterator_record(iterator_record)
  1580. {
  1581. }
  1582. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1583. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1584. Operand next_method() const { return m_next_method; }
  1585. Operand iterator_record() const { return m_iterator_record; }
  1586. private:
  1587. Operand m_next_method;
  1588. Operand m_iterator_record;
  1589. };
  1590. class GetMethod final : public Instruction {
  1591. public:
  1592. GetMethod(Operand dst, Operand object, IdentifierTableIndex property)
  1593. : Instruction(Type::GetMethod)
  1594. , m_dst(dst)
  1595. , m_object(object)
  1596. , m_property(property)
  1597. {
  1598. }
  1599. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1600. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1601. Operand dst() const { return m_dst; }
  1602. Operand object() const { return m_object; }
  1603. IdentifierTableIndex property() const { return m_property; }
  1604. private:
  1605. Operand m_dst;
  1606. Operand m_object;
  1607. IdentifierTableIndex m_property;
  1608. };
  1609. class GetObjectPropertyIterator final : public Instruction {
  1610. public:
  1611. GetObjectPropertyIterator(Operand dst, Operand object)
  1612. : Instruction(Type::GetObjectPropertyIterator)
  1613. , m_dst(dst)
  1614. , m_object(object)
  1615. {
  1616. }
  1617. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1618. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1619. Operand dst() const { return m_dst; }
  1620. Operand object() const { return m_object; }
  1621. private:
  1622. Operand m_dst;
  1623. Operand m_object;
  1624. };
  1625. class IteratorClose final : public Instruction {
  1626. public:
  1627. IteratorClose(Operand iterator_record, Completion::Type completion_type, Optional<Value> completion_value)
  1628. : Instruction(Type::IteratorClose)
  1629. , m_iterator_record(iterator_record)
  1630. , m_completion_type(completion_type)
  1631. , m_completion_value(completion_value)
  1632. {
  1633. }
  1634. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1635. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1636. Operand iterator_record() const { return m_iterator_record; }
  1637. Completion::Type completion_type() const { return m_completion_type; }
  1638. Optional<Value> const& completion_value() const { return m_completion_value; }
  1639. private:
  1640. Operand m_iterator_record;
  1641. Completion::Type m_completion_type { Completion::Type::Normal };
  1642. Optional<Value> m_completion_value;
  1643. };
  1644. class AsyncIteratorClose final : public Instruction {
  1645. public:
  1646. AsyncIteratorClose(Operand iterator_record, Completion::Type completion_type, Optional<Value> completion_value)
  1647. : Instruction(Type::AsyncIteratorClose)
  1648. , m_iterator_record(iterator_record)
  1649. , m_completion_type(completion_type)
  1650. , m_completion_value(completion_value)
  1651. {
  1652. }
  1653. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1654. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1655. Operand iterator_record() const { return m_iterator_record; }
  1656. Completion::Type completion_type() const { return m_completion_type; }
  1657. Optional<Value> const& completion_value() const { return m_completion_value; }
  1658. private:
  1659. Operand m_iterator_record;
  1660. Completion::Type m_completion_type { Completion::Type::Normal };
  1661. Optional<Value> m_completion_value;
  1662. };
  1663. class IteratorNext final : public Instruction {
  1664. public:
  1665. IteratorNext(Operand dst, Operand iterator_record)
  1666. : Instruction(Type::IteratorNext)
  1667. , m_dst(dst)
  1668. , m_iterator_record(iterator_record)
  1669. {
  1670. }
  1671. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1672. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1673. Operand dst() const { return m_dst; }
  1674. Operand iterator_record() const { return m_iterator_record; }
  1675. private:
  1676. Operand m_dst;
  1677. Operand m_iterator_record;
  1678. };
  1679. class ResolveThisBinding final : public Instruction {
  1680. public:
  1681. explicit ResolveThisBinding(Operand dst)
  1682. : Instruction(Type::ResolveThisBinding)
  1683. , m_dst(dst)
  1684. {
  1685. }
  1686. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1687. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1688. Operand dst() const { return m_dst; }
  1689. private:
  1690. Operand m_dst;
  1691. };
  1692. class ResolveSuperBase final : public Instruction {
  1693. public:
  1694. explicit ResolveSuperBase(Operand dst)
  1695. : Instruction(Type::ResolveSuperBase)
  1696. , m_dst(dst)
  1697. {
  1698. }
  1699. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1700. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1701. Operand dst() const { return m_dst; }
  1702. private:
  1703. Operand m_dst;
  1704. };
  1705. class GetNewTarget final : public Instruction {
  1706. public:
  1707. explicit GetNewTarget(Operand dst)
  1708. : Instruction(Type::GetNewTarget)
  1709. , m_dst(dst)
  1710. {
  1711. }
  1712. void execute_impl(Bytecode::Interpreter&) const;
  1713. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1714. Operand dst() const { return m_dst; }
  1715. private:
  1716. Operand m_dst;
  1717. };
  1718. class GetImportMeta final : public Instruction {
  1719. public:
  1720. explicit GetImportMeta(Operand dst)
  1721. : Instruction(Type::GetImportMeta)
  1722. , m_dst(dst)
  1723. {
  1724. }
  1725. void execute_impl(Bytecode::Interpreter&) const;
  1726. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1727. Operand dst() const { return m_dst; }
  1728. private:
  1729. Operand m_dst;
  1730. };
  1731. class TypeofVariable final : public Instruction {
  1732. public:
  1733. TypeofVariable(Operand dst, IdentifierTableIndex identifier)
  1734. : Instruction(Type::TypeofVariable)
  1735. , m_dst(dst)
  1736. , m_identifier(identifier)
  1737. {
  1738. }
  1739. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1740. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1741. Operand dst() const { return m_dst; }
  1742. IdentifierTableIndex identifier() const { return m_identifier; }
  1743. private:
  1744. Operand m_dst;
  1745. IdentifierTableIndex m_identifier;
  1746. };
  1747. class End final : public Instruction {
  1748. public:
  1749. constexpr static bool IsTerminator = true;
  1750. explicit End(Operand value)
  1751. : Instruction(Type::End)
  1752. , m_value(value)
  1753. {
  1754. }
  1755. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1756. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1757. Operand value() const { return m_value; }
  1758. private:
  1759. Operand m_value;
  1760. };
  1761. class Dump final : public Instruction {
  1762. public:
  1763. explicit Dump(StringView text, Operand value)
  1764. : Instruction(Type::Dump)
  1765. , m_text(text)
  1766. , m_value(value)
  1767. {
  1768. }
  1769. void execute_impl(Bytecode::Interpreter&) const;
  1770. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1771. private:
  1772. StringView m_text;
  1773. Operand m_value;
  1774. };
  1775. }