Op.h 62 KB

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