Op.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479
  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/StdLibExtras.h>
  10. #include <LibCrypto/BigInt/SignedBigInteger.h>
  11. #include <LibJS/Bytecode/IdentifierTable.h>
  12. #include <LibJS/Bytecode/Instruction.h>
  13. #include <LibJS/Bytecode/Label.h>
  14. #include <LibJS/Bytecode/RegexTable.h>
  15. #include <LibJS/Bytecode/Register.h>
  16. #include <LibJS/Bytecode/StringTable.h>
  17. #include <LibJS/Heap/Cell.h>
  18. #include <LibJS/Runtime/Environment.h>
  19. #include <LibJS/Runtime/Iterator.h>
  20. #include <LibJS/Runtime/Value.h>
  21. #include <LibJS/Runtime/ValueTraits.h>
  22. namespace JS {
  23. class FunctionExpression;
  24. }
  25. namespace JS::Bytecode::Op {
  26. class Load final : public Instruction {
  27. public:
  28. explicit Load(Register src)
  29. : Instruction(Type::Load, sizeof(*this))
  30. , m_src(src)
  31. {
  32. }
  33. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  34. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  35. Register src() const { return m_src; }
  36. private:
  37. Register m_src;
  38. };
  39. class LoadImmediate final : public Instruction {
  40. public:
  41. explicit LoadImmediate(Value value)
  42. : Instruction(Type::LoadImmediate, sizeof(*this))
  43. , m_value(value)
  44. {
  45. }
  46. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  47. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  48. Value value() const { return m_value; }
  49. private:
  50. Value m_value;
  51. };
  52. class Store final : public Instruction {
  53. public:
  54. explicit Store(Register dst)
  55. : Instruction(Type::Store, sizeof(*this))
  56. , m_dst(dst)
  57. {
  58. }
  59. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  60. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  61. Register dst() const { return m_dst; }
  62. private:
  63. Register m_dst;
  64. };
  65. #define JS_ENUMERATE_COMMON_BINARY_OPS(O) \
  66. O(Add, add) \
  67. O(Sub, sub) \
  68. O(Mul, mul) \
  69. O(Div, div) \
  70. O(Exp, exp) \
  71. O(Mod, mod) \
  72. O(In, in) \
  73. O(InstanceOf, instance_of) \
  74. O(GreaterThan, greater_than) \
  75. O(GreaterThanEquals, greater_than_equals) \
  76. O(LessThan, less_than) \
  77. O(LessThanEquals, less_than_equals) \
  78. O(LooselyInequals, abstract_inequals) \
  79. O(LooselyEquals, abstract_equals) \
  80. O(StrictlyInequals, typed_inequals) \
  81. O(StrictlyEquals, typed_equals) \
  82. O(BitwiseAnd, bitwise_and) \
  83. O(BitwiseOr, bitwise_or) \
  84. O(BitwiseXor, bitwise_xor) \
  85. O(LeftShift, left_shift) \
  86. O(RightShift, right_shift) \
  87. O(UnsignedRightShift, unsigned_right_shift)
  88. #define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
  89. class OpTitleCase final : public Instruction { \
  90. public: \
  91. explicit OpTitleCase(Register lhs_reg) \
  92. : Instruction(Type::OpTitleCase, sizeof(*this)) \
  93. , m_lhs_reg(lhs_reg) \
  94. { \
  95. } \
  96. \
  97. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  98. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
  99. \
  100. Register lhs() const { return m_lhs_reg; } \
  101. \
  102. private: \
  103. Register m_lhs_reg; \
  104. };
  105. JS_ENUMERATE_COMMON_BINARY_OPS(JS_DECLARE_COMMON_BINARY_OP)
  106. #undef JS_DECLARE_COMMON_BINARY_OP
  107. #define JS_ENUMERATE_COMMON_UNARY_OPS(O) \
  108. O(BitwiseNot, bitwise_not) \
  109. O(Not, not_) \
  110. O(UnaryPlus, unary_plus) \
  111. O(UnaryMinus, unary_minus) \
  112. O(Typeof, typeof_)
  113. #define JS_DECLARE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
  114. class OpTitleCase final : public Instruction { \
  115. public: \
  116. OpTitleCase() \
  117. : Instruction(Type::OpTitleCase, sizeof(*this)) \
  118. { \
  119. } \
  120. \
  121. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  122. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
  123. };
  124. JS_ENUMERATE_COMMON_UNARY_OPS(JS_DECLARE_COMMON_UNARY_OP)
  125. #undef JS_DECLARE_COMMON_UNARY_OP
  126. class NewString final : public Instruction {
  127. public:
  128. explicit NewString(StringTableIndex string)
  129. : Instruction(Type::NewString, sizeof(*this))
  130. , m_string(string)
  131. {
  132. }
  133. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  134. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  135. StringTableIndex index() const { return m_string; }
  136. private:
  137. StringTableIndex m_string;
  138. };
  139. class NewObject final : public Instruction {
  140. public:
  141. NewObject()
  142. : Instruction(Type::NewObject, sizeof(*this))
  143. {
  144. }
  145. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  146. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  147. };
  148. class NewRegExp final : public Instruction {
  149. public:
  150. NewRegExp(StringTableIndex source_index, StringTableIndex flags_index, RegexTableIndex regex_index)
  151. : Instruction(Type::NewRegExp, sizeof(*this))
  152. , m_source_index(source_index)
  153. , m_flags_index(flags_index)
  154. , m_regex_index(regex_index)
  155. {
  156. }
  157. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  158. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  159. StringTableIndex source_index() const { return m_source_index; }
  160. StringTableIndex flags_index() const { return m_flags_index; }
  161. RegexTableIndex regex_index() const { return m_regex_index; }
  162. private:
  163. StringTableIndex m_source_index;
  164. StringTableIndex m_flags_index;
  165. RegexTableIndex m_regex_index;
  166. };
  167. #define JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(O) \
  168. O(TypeError)
  169. #define JS_DECLARE_NEW_BUILTIN_ERROR_OP(ErrorName) \
  170. class New##ErrorName final : public Instruction { \
  171. public: \
  172. explicit New##ErrorName(StringTableIndex error_string) \
  173. : Instruction(Type::New##ErrorName, sizeof(*this)) \
  174. , m_error_string(error_string) \
  175. { \
  176. } \
  177. \
  178. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  179. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
  180. \
  181. private: \
  182. StringTableIndex m_error_string; \
  183. };
  184. JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DECLARE_NEW_BUILTIN_ERROR_OP)
  185. #undef JS_DECLARE_NEW_BUILTIN_ERROR_OP
  186. // NOTE: This instruction is variable-width depending on the number of excluded names
  187. class CopyObjectExcludingProperties final : public Instruction {
  188. public:
  189. CopyObjectExcludingProperties(Register from_object, Vector<Register> const& excluded_names)
  190. : Instruction(Type::CopyObjectExcludingProperties, length_impl(excluded_names.size()))
  191. , m_from_object(from_object)
  192. , m_excluded_names_count(excluded_names.size())
  193. {
  194. for (size_t i = 0; i < m_excluded_names_count; i++)
  195. m_excluded_names[i] = excluded_names[i];
  196. }
  197. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  198. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  199. size_t length_impl(size_t excluded_names_count) const
  200. {
  201. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Register) * excluded_names_count);
  202. }
  203. private:
  204. Register m_from_object;
  205. size_t m_excluded_names_count { 0 };
  206. Register m_excluded_names[];
  207. };
  208. class NewBigInt final : public Instruction {
  209. public:
  210. explicit NewBigInt(Crypto::SignedBigInteger bigint)
  211. : Instruction(Type::NewBigInt, sizeof(*this))
  212. , m_bigint(move(bigint))
  213. {
  214. }
  215. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  216. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  217. private:
  218. Crypto::SignedBigInteger m_bigint;
  219. };
  220. // NOTE: This instruction is variable-width depending on the number of elements!
  221. class NewArray final : public Instruction {
  222. public:
  223. NewArray()
  224. : Instruction(Type::NewArray, length_impl(0))
  225. , m_element_count(0)
  226. {
  227. }
  228. explicit NewArray(AK::Array<Register, 2> const& elements_range)
  229. : Instruction(Type::NewArray, length_impl(elements_range[1].index() - elements_range[0].index() + 1))
  230. , m_element_count(elements_range[1].index() - elements_range[0].index() + 1)
  231. {
  232. m_elements[0] = elements_range[0];
  233. m_elements[1] = elements_range[1];
  234. }
  235. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  236. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  237. size_t length_impl(size_t element_count) const
  238. {
  239. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Register) * (element_count == 0 ? 0 : 2));
  240. }
  241. Register start() const
  242. {
  243. VERIFY(m_element_count);
  244. return m_elements[0];
  245. }
  246. Register end() const
  247. {
  248. VERIFY(m_element_count);
  249. return m_elements[1];
  250. }
  251. size_t element_count() const { return m_element_count; }
  252. private:
  253. size_t m_element_count { 0 };
  254. Register m_elements[];
  255. };
  256. class Append final : public Instruction {
  257. public:
  258. Append(Register lhs, bool is_spread)
  259. : Instruction(Type::Append, sizeof(*this))
  260. , m_lhs(lhs)
  261. , m_is_spread(is_spread)
  262. {
  263. }
  264. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  265. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  266. private:
  267. Register m_lhs;
  268. bool m_is_spread = false;
  269. };
  270. class ImportCall final : public Instruction {
  271. public:
  272. ImportCall(Register specifier, Register options)
  273. : Instruction(Type::ImportCall, sizeof(*this))
  274. , m_specifier(specifier)
  275. , m_options(options)
  276. {
  277. }
  278. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  279. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  280. private:
  281. Register m_specifier;
  282. Register m_options;
  283. };
  284. class IteratorToArray final : public Instruction {
  285. public:
  286. IteratorToArray()
  287. : Instruction(Type::IteratorToArray, sizeof(*this))
  288. {
  289. }
  290. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  291. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  292. };
  293. class ConcatString final : public Instruction {
  294. public:
  295. explicit ConcatString(Register lhs)
  296. : Instruction(Type::ConcatString, sizeof(*this))
  297. , m_lhs(lhs)
  298. {
  299. }
  300. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  301. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  302. private:
  303. Register m_lhs;
  304. };
  305. enum class EnvironmentMode {
  306. Lexical,
  307. Var,
  308. };
  309. class CreateLexicalEnvironment final : public Instruction {
  310. public:
  311. explicit CreateLexicalEnvironment()
  312. : Instruction(Type::CreateLexicalEnvironment, sizeof(*this))
  313. {
  314. }
  315. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  316. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  317. };
  318. class EnterObjectEnvironment final : public Instruction {
  319. public:
  320. explicit EnterObjectEnvironment()
  321. : Instruction(Type::EnterObjectEnvironment, sizeof(*this))
  322. {
  323. }
  324. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  325. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  326. };
  327. class CreateVariable final : public Instruction {
  328. public:
  329. explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false, bool is_strict = false)
  330. : Instruction(Type::CreateVariable, sizeof(*this))
  331. , m_identifier(identifier)
  332. , m_mode(mode)
  333. , m_is_immutable(is_immutable)
  334. , m_is_global(is_global)
  335. , m_is_strict(is_strict)
  336. {
  337. }
  338. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  339. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  340. private:
  341. IdentifierTableIndex m_identifier;
  342. EnvironmentMode m_mode;
  343. bool m_is_immutable : 4 { false };
  344. bool m_is_global : 4 { false };
  345. bool m_is_strict { false };
  346. };
  347. class SetVariable final : public Instruction {
  348. public:
  349. enum class InitializationMode {
  350. Initialize,
  351. Set,
  352. };
  353. explicit SetVariable(IdentifierTableIndex identifier, InitializationMode initialization_mode = InitializationMode::Set, EnvironmentMode mode = EnvironmentMode::Lexical)
  354. : Instruction(Type::SetVariable, sizeof(*this))
  355. , m_identifier(identifier)
  356. , m_mode(mode)
  357. , m_initialization_mode(initialization_mode)
  358. {
  359. }
  360. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  361. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  362. IdentifierTableIndex identifier() const { return m_identifier; }
  363. EnvironmentMode mode() const { return m_mode; }
  364. InitializationMode initialization_mode() const { return m_initialization_mode; }
  365. private:
  366. IdentifierTableIndex m_identifier;
  367. EnvironmentMode m_mode;
  368. InitializationMode m_initialization_mode { InitializationMode::Set };
  369. };
  370. class SetLocal final : public Instruction {
  371. public:
  372. explicit SetLocal(size_t index)
  373. : Instruction(Type::SetLocal, sizeof(*this))
  374. , m_index(index)
  375. {
  376. }
  377. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  378. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  379. size_t index() const { return m_index; }
  380. private:
  381. size_t m_index;
  382. };
  383. class GetCalleeAndThisFromEnvironment final : public Instruction {
  384. public:
  385. explicit GetCalleeAndThisFromEnvironment(IdentifierTableIndex identifier, Register callee_reg, Register this_reg, u32 cache_index)
  386. : Instruction(Type::GetCalleeAndThisFromEnvironment, sizeof(*this))
  387. , m_identifier(identifier)
  388. , m_callee_reg(callee_reg)
  389. , m_this_reg(this_reg)
  390. , m_cache_index(cache_index)
  391. {
  392. }
  393. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  394. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  395. IdentifierTableIndex identifier() const { return m_identifier; }
  396. u32 cache_index() const { return m_cache_index; }
  397. Register callee() const { return m_callee_reg; }
  398. Register this_() const { return m_this_reg; }
  399. private:
  400. IdentifierTableIndex m_identifier;
  401. Register m_callee_reg;
  402. Register m_this_reg;
  403. u32 m_cache_index { 0 };
  404. };
  405. class GetVariable final : public Instruction {
  406. public:
  407. explicit GetVariable(IdentifierTableIndex identifier, u32 cache_index)
  408. : Instruction(Type::GetVariable, sizeof(*this))
  409. , m_identifier(identifier)
  410. , m_cache_index(cache_index)
  411. {
  412. }
  413. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  414. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  415. IdentifierTableIndex identifier() const { return m_identifier; }
  416. u32 cache_index() const { return m_cache_index; }
  417. private:
  418. IdentifierTableIndex m_identifier;
  419. u32 m_cache_index { 0 };
  420. };
  421. class GetGlobal final : public Instruction {
  422. public:
  423. explicit GetGlobal(IdentifierTableIndex identifier, u32 cache_index)
  424. : Instruction(Type::GetGlobal, sizeof(*this))
  425. , m_identifier(identifier)
  426. , m_cache_index(cache_index)
  427. {
  428. }
  429. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  430. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  431. IdentifierTableIndex identifier() const { return m_identifier; }
  432. u32 cache_index() const { return m_cache_index; }
  433. private:
  434. IdentifierTableIndex m_identifier;
  435. u32 m_cache_index { 0 };
  436. };
  437. class GetLocal final : public Instruction {
  438. public:
  439. explicit GetLocal(size_t index)
  440. : Instruction(Type::GetLocal, sizeof(*this))
  441. , m_index(index)
  442. {
  443. }
  444. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  445. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  446. size_t index() const { return m_index; }
  447. private:
  448. size_t m_index;
  449. };
  450. class DeleteVariable final : public Instruction {
  451. public:
  452. explicit DeleteVariable(IdentifierTableIndex identifier)
  453. : Instruction(Type::DeleteVariable, sizeof(*this))
  454. , m_identifier(identifier)
  455. {
  456. }
  457. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  458. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  459. IdentifierTableIndex identifier() const { return m_identifier; }
  460. private:
  461. IdentifierTableIndex m_identifier;
  462. };
  463. class GetById final : public Instruction {
  464. public:
  465. GetById(IdentifierTableIndex property, u32 cache_index)
  466. : Instruction(Type::GetById, sizeof(*this))
  467. , m_property(property)
  468. , m_cache_index(cache_index)
  469. {
  470. }
  471. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  472. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  473. IdentifierTableIndex property() const { return m_property; }
  474. u32 cache_index() const { return m_cache_index; }
  475. private:
  476. IdentifierTableIndex m_property;
  477. u32 m_cache_index { 0 };
  478. };
  479. class GetByIdWithThis final : public Instruction {
  480. public:
  481. GetByIdWithThis(IdentifierTableIndex property, Register this_value, u32 cache_index)
  482. : Instruction(Type::GetByIdWithThis, sizeof(*this))
  483. , m_property(property)
  484. , m_this_value(this_value)
  485. , m_cache_index(cache_index)
  486. {
  487. }
  488. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  489. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  490. private:
  491. IdentifierTableIndex m_property;
  492. Register m_this_value;
  493. u32 m_cache_index { 0 };
  494. };
  495. class GetPrivateById final : public Instruction {
  496. public:
  497. explicit GetPrivateById(IdentifierTableIndex property)
  498. : Instruction(Type::GetPrivateById, sizeof(*this))
  499. , m_property(property)
  500. {
  501. }
  502. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  503. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  504. private:
  505. IdentifierTableIndex m_property;
  506. };
  507. class HasPrivateId final : public Instruction {
  508. public:
  509. explicit HasPrivateId(IdentifierTableIndex property)
  510. : Instruction(Type::HasPrivateId, sizeof(*this))
  511. , m_property(property)
  512. {
  513. }
  514. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  515. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  516. private:
  517. IdentifierTableIndex m_property;
  518. };
  519. enum class PropertyKind {
  520. Getter,
  521. Setter,
  522. KeyValue,
  523. DirectKeyValue, // Used for Object expressions. Always sets an own property, never calls a setter.
  524. Spread,
  525. ProtoSetter,
  526. };
  527. class PutById final : public Instruction {
  528. public:
  529. explicit PutById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
  530. : Instruction(Type::PutById, sizeof(*this))
  531. , m_base(base)
  532. , m_property(property)
  533. , m_kind(kind)
  534. {
  535. }
  536. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  537. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  538. Register base() const { return m_base; }
  539. IdentifierTableIndex property() const { return m_property; }
  540. PropertyKind kind() const { return m_kind; }
  541. private:
  542. Register m_base;
  543. IdentifierTableIndex m_property;
  544. PropertyKind m_kind;
  545. };
  546. class PutByIdWithThis final : public Instruction {
  547. public:
  548. PutByIdWithThis(Register base, Register this_value, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
  549. : Instruction(Type::PutByIdWithThis, sizeof(*this))
  550. , m_base(base)
  551. , m_this_value(this_value)
  552. , m_property(property)
  553. , m_kind(kind)
  554. {
  555. }
  556. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  557. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  558. private:
  559. Register m_base;
  560. Register m_this_value;
  561. IdentifierTableIndex m_property;
  562. PropertyKind m_kind;
  563. };
  564. class PutPrivateById final : public Instruction {
  565. public:
  566. explicit PutPrivateById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
  567. : Instruction(Type::PutPrivateById, sizeof(*this))
  568. , m_base(base)
  569. , m_property(property)
  570. , m_kind(kind)
  571. {
  572. }
  573. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  574. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  575. private:
  576. Register m_base;
  577. IdentifierTableIndex m_property;
  578. PropertyKind m_kind;
  579. };
  580. class DeleteById final : public Instruction {
  581. public:
  582. explicit DeleteById(IdentifierTableIndex property)
  583. : Instruction(Type::DeleteById, sizeof(*this))
  584. , m_property(property)
  585. {
  586. }
  587. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  588. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  589. private:
  590. IdentifierTableIndex m_property;
  591. };
  592. class DeleteByIdWithThis final : public Instruction {
  593. public:
  594. DeleteByIdWithThis(Register this_value, IdentifierTableIndex property)
  595. : Instruction(Type::DeleteByIdWithThis, sizeof(*this))
  596. , m_this_value(this_value)
  597. , m_property(property)
  598. {
  599. }
  600. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  601. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  602. private:
  603. Register m_this_value;
  604. IdentifierTableIndex m_property;
  605. };
  606. class GetByValue final : public Instruction {
  607. public:
  608. explicit GetByValue(Register base)
  609. : Instruction(Type::GetByValue, sizeof(*this))
  610. , m_base(base)
  611. {
  612. }
  613. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  614. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  615. Register base() const { return m_base; }
  616. private:
  617. Register m_base;
  618. };
  619. class GetByValueWithThis final : public Instruction {
  620. public:
  621. GetByValueWithThis(Register base, Register this_value)
  622. : Instruction(Type::GetByValueWithThis, sizeof(*this))
  623. , m_base(base)
  624. , m_this_value(this_value)
  625. {
  626. }
  627. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  628. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  629. private:
  630. Register m_base;
  631. Register m_this_value;
  632. };
  633. class PutByValue final : public Instruction {
  634. public:
  635. PutByValue(Register base, Register property, PropertyKind kind = PropertyKind::KeyValue)
  636. : Instruction(Type::PutByValue, sizeof(*this))
  637. , m_base(base)
  638. , m_property(property)
  639. , m_kind(kind)
  640. {
  641. }
  642. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  643. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  644. Register base() const { return m_base; }
  645. Register property() const { return m_property; }
  646. PropertyKind kind() const { return m_kind; }
  647. private:
  648. Register m_base;
  649. Register m_property;
  650. PropertyKind m_kind;
  651. };
  652. class PutByValueWithThis final : public Instruction {
  653. public:
  654. PutByValueWithThis(Register base, Register property, Register this_value, PropertyKind kind = PropertyKind::KeyValue)
  655. : Instruction(Type::PutByValueWithThis, sizeof(*this))
  656. , m_base(base)
  657. , m_property(property)
  658. , m_this_value(this_value)
  659. , m_kind(kind)
  660. {
  661. }
  662. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  663. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  664. private:
  665. Register m_base;
  666. Register m_property;
  667. Register m_this_value;
  668. PropertyKind m_kind;
  669. };
  670. class DeleteByValue final : public Instruction {
  671. public:
  672. DeleteByValue(Register base)
  673. : Instruction(Type::DeleteByValue, sizeof(*this))
  674. , m_base(base)
  675. {
  676. }
  677. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  678. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  679. private:
  680. Register m_base;
  681. };
  682. class DeleteByValueWithThis final : public Instruction {
  683. public:
  684. DeleteByValueWithThis(Register base, Register this_value)
  685. : Instruction(Type::DeleteByValueWithThis, sizeof(*this))
  686. , m_base(base)
  687. , m_this_value(this_value)
  688. {
  689. }
  690. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  691. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  692. private:
  693. Register m_base;
  694. Register m_this_value;
  695. };
  696. class Jump : public Instruction {
  697. public:
  698. constexpr static bool IsTerminator = true;
  699. explicit Jump(Type type, Label taken_target, Optional<Label> nontaken_target = {})
  700. : Instruction(type, sizeof(*this))
  701. , m_true_target(move(taken_target))
  702. , m_false_target(move(nontaken_target))
  703. {
  704. }
  705. explicit Jump(Label taken_target, Optional<Label> nontaken_target = {})
  706. : Instruction(Type::Jump, sizeof(*this))
  707. , m_true_target(move(taken_target))
  708. , m_false_target(move(nontaken_target))
  709. {
  710. }
  711. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  712. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  713. auto& true_target() const { return m_true_target; }
  714. auto& false_target() const { return m_false_target; }
  715. protected:
  716. Optional<Label> m_true_target;
  717. Optional<Label> m_false_target;
  718. };
  719. class JumpConditional final : public Jump {
  720. public:
  721. explicit JumpConditional(Label true_target, Label false_target)
  722. : Jump(Type::JumpConditional, move(true_target), move(false_target))
  723. {
  724. }
  725. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  726. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  727. };
  728. class JumpNullish final : public Jump {
  729. public:
  730. explicit JumpNullish(Label true_target, Label false_target)
  731. : Jump(Type::JumpNullish, move(true_target), move(false_target))
  732. {
  733. }
  734. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  735. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  736. };
  737. class JumpUndefined final : public Jump {
  738. public:
  739. explicit JumpUndefined(Label true_target, Label false_target)
  740. : Jump(Type::JumpUndefined, move(true_target), move(false_target))
  741. {
  742. }
  743. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  744. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  745. };
  746. enum class CallType {
  747. Call,
  748. Construct,
  749. DirectEval,
  750. };
  751. class Call final : public Instruction {
  752. public:
  753. Call(CallType type, Register callee, Register this_value, Register first_argument, u32 argument_count, Optional<StringTableIndex> expression_string = {})
  754. : Instruction(Type::Call, sizeof(*this))
  755. , m_callee(callee)
  756. , m_this_value(this_value)
  757. , m_first_argument(first_argument)
  758. , m_argument_count(argument_count)
  759. , m_type(type)
  760. , m_expression_string(expression_string)
  761. {
  762. }
  763. CallType call_type() const { return m_type; }
  764. Register callee() const { return m_callee; }
  765. Register this_value() const { return m_this_value; }
  766. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  767. Register first_argument() const { return m_first_argument; }
  768. u32 argument_count() const { return m_argument_count; }
  769. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  770. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  771. private:
  772. Register m_callee;
  773. Register m_this_value;
  774. Register m_first_argument;
  775. u32 m_argument_count { 0 };
  776. CallType m_type;
  777. Optional<StringTableIndex> m_expression_string;
  778. };
  779. class CallWithArgumentArray final : public Instruction {
  780. public:
  781. CallWithArgumentArray(CallType type, Register callee, Register this_value, Optional<StringTableIndex> expression_string = {})
  782. : Instruction(Type::CallWithArgumentArray, sizeof(*this))
  783. , m_callee(callee)
  784. , m_this_value(this_value)
  785. , m_type(type)
  786. , m_expression_string(expression_string)
  787. {
  788. }
  789. CallType call_type() const { return m_type; }
  790. Register callee() const { return m_callee; }
  791. Register this_value() const { return m_this_value; }
  792. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  793. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  794. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  795. private:
  796. Register m_callee;
  797. Register m_this_value;
  798. CallType m_type;
  799. Optional<StringTableIndex> m_expression_string;
  800. };
  801. class SuperCallWithArgumentArray : public Instruction {
  802. public:
  803. explicit SuperCallWithArgumentArray(bool is_synthetic)
  804. : Instruction(Type::SuperCallWithArgumentArray, sizeof(*this))
  805. , m_is_synthetic(is_synthetic)
  806. {
  807. }
  808. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  809. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  810. private:
  811. bool m_is_synthetic;
  812. };
  813. class NewClass final : public Instruction {
  814. public:
  815. explicit NewClass(ClassExpression const& class_expression, Optional<IdentifierTableIndex> lhs_name)
  816. : Instruction(Type::NewClass, sizeof(*this))
  817. , m_class_expression(class_expression)
  818. , m_lhs_name(lhs_name)
  819. {
  820. }
  821. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  822. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  823. private:
  824. ClassExpression const& m_class_expression;
  825. Optional<IdentifierTableIndex> m_lhs_name;
  826. };
  827. class NewFunction final : public Instruction {
  828. public:
  829. explicit NewFunction(FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Register> home_object = {})
  830. : Instruction(Type::NewFunction, sizeof(*this))
  831. , m_function_node(function_node)
  832. , m_lhs_name(lhs_name)
  833. , m_home_object(move(home_object))
  834. {
  835. }
  836. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  837. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  838. FunctionExpression const& function_node() const { return m_function_node; }
  839. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  840. Optional<Register> const& home_object() const { return m_home_object; }
  841. private:
  842. FunctionExpression const& m_function_node;
  843. Optional<IdentifierTableIndex> m_lhs_name;
  844. Optional<Register> m_home_object;
  845. };
  846. class BlockDeclarationInstantiation final : public Instruction {
  847. public:
  848. explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
  849. : Instruction(Type::BlockDeclarationInstantiation, sizeof(*this))
  850. , m_scope_node(scope_node)
  851. {
  852. }
  853. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  854. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  855. private:
  856. ScopeNode const& m_scope_node;
  857. };
  858. class Return final : public Instruction {
  859. public:
  860. constexpr static bool IsTerminator = true;
  861. Return()
  862. : Instruction(Type::Return, sizeof(*this))
  863. {
  864. }
  865. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  866. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  867. };
  868. class Increment final : public Instruction {
  869. public:
  870. Increment()
  871. : Instruction(Type::Increment, sizeof(*this))
  872. {
  873. }
  874. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  875. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  876. };
  877. class Decrement final : public Instruction {
  878. public:
  879. Decrement()
  880. : Instruction(Type::Decrement, sizeof(*this))
  881. {
  882. }
  883. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  884. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  885. };
  886. class ToNumeric final : public Instruction {
  887. public:
  888. ToNumeric()
  889. : Instruction(Type::ToNumeric, sizeof(*this))
  890. {
  891. }
  892. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  893. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  894. };
  895. class Throw final : public Instruction {
  896. public:
  897. constexpr static bool IsTerminator = true;
  898. Throw()
  899. : Instruction(Type::Throw, sizeof(*this))
  900. {
  901. }
  902. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  903. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  904. };
  905. class ThrowIfNotObject final : public Instruction {
  906. public:
  907. ThrowIfNotObject()
  908. : Instruction(Type::ThrowIfNotObject, sizeof(*this))
  909. {
  910. }
  911. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  912. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  913. };
  914. class ThrowIfNullish final : public Instruction {
  915. public:
  916. ThrowIfNullish()
  917. : Instruction(Type::ThrowIfNullish, sizeof(*this))
  918. {
  919. }
  920. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  921. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  922. };
  923. class EnterUnwindContext final : public Instruction {
  924. public:
  925. constexpr static bool IsTerminator = true;
  926. EnterUnwindContext(Label entry_point, Optional<Label> handler_target, Optional<Label> finalizer_target)
  927. : Instruction(Type::EnterUnwindContext, sizeof(*this))
  928. , m_entry_point(move(entry_point))
  929. , m_handler_target(move(handler_target))
  930. , m_finalizer_target(move(finalizer_target))
  931. {
  932. }
  933. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  934. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  935. auto& entry_point() const { return m_entry_point; }
  936. auto& handler_target() const { return m_handler_target; }
  937. auto& finalizer_target() const { return m_finalizer_target; }
  938. private:
  939. Label m_entry_point;
  940. Optional<Label> m_handler_target;
  941. Optional<Label> m_finalizer_target;
  942. };
  943. class ScheduleJump final : public Instruction {
  944. public:
  945. // Note: We use this instruction to tell the next `finally` block to
  946. // continue execution with a specific break/continue target;
  947. // FIXME: We currently don't clear the interpreter internal flag, when we change
  948. // the control-flow (`break`, `continue`) in a finally-block,
  949. // FIXME: .NET on x86_64 uses a call to the finally instead, which could make this
  950. // easier, at the cost of making control-flow changes (`break`, `continue`, `return`)
  951. // in the finally-block more difficult, but as stated above, those
  952. // aren't handled 100% correctly at the moment anyway
  953. // It might be worth investigating a similar mechanism
  954. constexpr static bool IsTerminator = true;
  955. ScheduleJump(Label target)
  956. : Instruction(Type::ScheduleJump, sizeof(*this))
  957. , m_target(target)
  958. {
  959. }
  960. Label target() const { return m_target; }
  961. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  962. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  963. private:
  964. Label m_target;
  965. };
  966. class LeaveLexicalEnvironment final : public Instruction {
  967. public:
  968. LeaveLexicalEnvironment()
  969. : Instruction(Type::LeaveLexicalEnvironment, sizeof(*this))
  970. {
  971. }
  972. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  973. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  974. };
  975. class LeaveUnwindContext final : public Instruction {
  976. public:
  977. LeaveUnwindContext()
  978. : Instruction(Type::LeaveUnwindContext, sizeof(*this))
  979. {
  980. }
  981. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  982. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  983. };
  984. class ContinuePendingUnwind final : public Instruction {
  985. public:
  986. constexpr static bool IsTerminator = true;
  987. explicit ContinuePendingUnwind(Label resume_target)
  988. : Instruction(Type::ContinuePendingUnwind, sizeof(*this))
  989. , m_resume_target(resume_target)
  990. {
  991. }
  992. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  993. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  994. auto& resume_target() const { return m_resume_target; }
  995. private:
  996. Label m_resume_target;
  997. };
  998. class Yield final : public Instruction {
  999. public:
  1000. constexpr static bool IsTerminator = true;
  1001. explicit Yield(Label continuation_label)
  1002. : Instruction(Type::Yield, sizeof(*this))
  1003. , m_continuation_label(continuation_label)
  1004. {
  1005. }
  1006. explicit Yield(nullptr_t)
  1007. : Instruction(Type::Yield, sizeof(*this))
  1008. {
  1009. }
  1010. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1011. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1012. auto& continuation() const { return m_continuation_label; }
  1013. private:
  1014. Optional<Label> m_continuation_label;
  1015. };
  1016. class Await final : public Instruction {
  1017. public:
  1018. constexpr static bool IsTerminator = true;
  1019. explicit Await(Label continuation_label)
  1020. : Instruction(Type::Await, sizeof(*this))
  1021. , m_continuation_label(continuation_label)
  1022. {
  1023. }
  1024. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1025. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1026. auto& continuation() const { return m_continuation_label; }
  1027. private:
  1028. Label m_continuation_label;
  1029. };
  1030. class PushDeclarativeEnvironment final : public Instruction {
  1031. public:
  1032. explicit PushDeclarativeEnvironment(HashMap<u32, Variable> variables)
  1033. : Instruction(Type::PushDeclarativeEnvironment, sizeof(*this))
  1034. , m_variables(move(variables))
  1035. {
  1036. }
  1037. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1038. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1039. private:
  1040. HashMap<u32, Variable> m_variables;
  1041. };
  1042. class GetIterator final : public Instruction {
  1043. public:
  1044. GetIterator(IteratorHint hint = IteratorHint::Sync)
  1045. : Instruction(Type::GetIterator, sizeof(*this))
  1046. , m_hint(hint)
  1047. {
  1048. }
  1049. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1050. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1051. private:
  1052. IteratorHint m_hint { IteratorHint::Sync };
  1053. };
  1054. class GetMethod final : public Instruction {
  1055. public:
  1056. GetMethod(IdentifierTableIndex property)
  1057. : Instruction(Type::GetMethod, sizeof(*this))
  1058. , m_property(property)
  1059. {
  1060. }
  1061. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1062. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1063. private:
  1064. IdentifierTableIndex m_property;
  1065. };
  1066. class GetObjectPropertyIterator final : public Instruction {
  1067. public:
  1068. GetObjectPropertyIterator()
  1069. : Instruction(Type::GetObjectPropertyIterator, sizeof(*this))
  1070. {
  1071. }
  1072. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1073. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1074. };
  1075. class IteratorClose final : public Instruction {
  1076. public:
  1077. IteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
  1078. : Instruction(Type::IteratorClose, sizeof(*this))
  1079. , m_completion_type(completion_type)
  1080. , m_completion_value(completion_value)
  1081. {
  1082. }
  1083. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1084. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1085. private:
  1086. Completion::Type m_completion_type { Completion::Type::Normal };
  1087. Optional<Value> m_completion_value;
  1088. };
  1089. class AsyncIteratorClose final : public Instruction {
  1090. public:
  1091. AsyncIteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
  1092. : Instruction(Type::AsyncIteratorClose, sizeof(*this))
  1093. , m_completion_type(completion_type)
  1094. , m_completion_value(completion_value)
  1095. {
  1096. }
  1097. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1098. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1099. private:
  1100. Completion::Type m_completion_type { Completion::Type::Normal };
  1101. Optional<Value> m_completion_value;
  1102. };
  1103. class IteratorNext final : public Instruction {
  1104. public:
  1105. IteratorNext()
  1106. : Instruction(Type::IteratorNext, sizeof(*this))
  1107. {
  1108. }
  1109. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1110. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1111. };
  1112. class IteratorResultDone final : public Instruction {
  1113. public:
  1114. IteratorResultDone()
  1115. : Instruction(Type::IteratorResultDone, sizeof(*this))
  1116. {
  1117. }
  1118. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1119. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1120. };
  1121. class IteratorResultValue final : public Instruction {
  1122. public:
  1123. IteratorResultValue()
  1124. : Instruction(Type::IteratorResultValue, sizeof(*this))
  1125. {
  1126. }
  1127. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1128. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1129. };
  1130. class ResolveThisBinding final : public Instruction {
  1131. public:
  1132. explicit ResolveThisBinding()
  1133. : Instruction(Type::ResolveThisBinding, sizeof(*this))
  1134. {
  1135. }
  1136. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1137. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1138. };
  1139. class ResolveSuperBase final : public Instruction {
  1140. public:
  1141. explicit ResolveSuperBase()
  1142. : Instruction(Type::ResolveSuperBase, sizeof(*this))
  1143. {
  1144. }
  1145. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1146. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1147. };
  1148. class GetNewTarget final : public Instruction {
  1149. public:
  1150. explicit GetNewTarget()
  1151. : Instruction(Type::GetNewTarget, sizeof(*this))
  1152. {
  1153. }
  1154. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1155. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1156. };
  1157. class GetImportMeta final : public Instruction {
  1158. public:
  1159. explicit GetImportMeta()
  1160. : Instruction(Type::GetImportMeta, sizeof(*this))
  1161. {
  1162. }
  1163. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1164. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1165. };
  1166. class TypeofVariable final : public Instruction {
  1167. public:
  1168. explicit TypeofVariable(IdentifierTableIndex identifier)
  1169. : Instruction(Type::TypeofVariable, sizeof(*this))
  1170. , m_identifier(identifier)
  1171. {
  1172. }
  1173. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1174. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1175. IdentifierTableIndex identifier() const { return m_identifier; }
  1176. private:
  1177. IdentifierTableIndex m_identifier;
  1178. };
  1179. class TypeofLocal final : public Instruction {
  1180. public:
  1181. explicit TypeofLocal(size_t index)
  1182. : Instruction(Type::TypeofLocal, sizeof(*this))
  1183. , m_index(index)
  1184. {
  1185. }
  1186. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1187. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1188. size_t index() const { return m_index; }
  1189. private:
  1190. size_t m_index;
  1191. };
  1192. }
  1193. namespace JS::Bytecode {
  1194. ALWAYS_INLINE ThrowCompletionOr<void> Instruction::execute(Bytecode::Interpreter& interpreter) const
  1195. {
  1196. #define __BYTECODE_OP(op) \
  1197. case Instruction::Type::op: \
  1198. return static_cast<Bytecode::Op::op const&>(*this).execute_impl(interpreter);
  1199. switch (type()) {
  1200. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1201. default:
  1202. VERIFY_NOT_REACHED();
  1203. }
  1204. #undef __BYTECODE_OP
  1205. }
  1206. }