Op.h 64 KB

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