Op.h 61 KB

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