Op.h 68 KB

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