Op.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  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. Crypto::SignedBigInteger const& bigint() const { return m_bigint; }
  218. private:
  219. Crypto::SignedBigInteger m_bigint;
  220. };
  221. // NOTE: This instruction is variable-width depending on the number of elements!
  222. class NewArray final : public Instruction {
  223. public:
  224. NewArray()
  225. : Instruction(Type::NewArray, length_impl(0))
  226. , m_element_count(0)
  227. {
  228. }
  229. explicit NewArray(AK::Array<Register, 2> const& elements_range)
  230. : Instruction(Type::NewArray, length_impl(elements_range[1].index() - elements_range[0].index() + 1))
  231. , m_element_count(elements_range[1].index() - elements_range[0].index() + 1)
  232. {
  233. m_elements[0] = elements_range[0];
  234. m_elements[1] = elements_range[1];
  235. }
  236. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  237. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  238. size_t length_impl(size_t element_count) const
  239. {
  240. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Register) * (element_count == 0 ? 0 : 2));
  241. }
  242. Register start() const
  243. {
  244. VERIFY(m_element_count);
  245. return m_elements[0];
  246. }
  247. Register end() const
  248. {
  249. VERIFY(m_element_count);
  250. return m_elements[1];
  251. }
  252. size_t element_count() const { return m_element_count; }
  253. private:
  254. size_t m_element_count { 0 };
  255. Register m_elements[];
  256. };
  257. class Append final : public Instruction {
  258. public:
  259. Append(Register lhs, bool is_spread)
  260. : Instruction(Type::Append, sizeof(*this))
  261. , m_lhs(lhs)
  262. , m_is_spread(is_spread)
  263. {
  264. }
  265. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  266. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  267. Register lhs() const { return m_lhs; }
  268. bool is_spread() const { return m_is_spread; }
  269. private:
  270. Register m_lhs;
  271. bool m_is_spread = false;
  272. };
  273. class ImportCall final : public Instruction {
  274. public:
  275. ImportCall(Register specifier, Register options)
  276. : Instruction(Type::ImportCall, sizeof(*this))
  277. , m_specifier(specifier)
  278. , m_options(options)
  279. {
  280. }
  281. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  282. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  283. private:
  284. Register m_specifier;
  285. Register m_options;
  286. };
  287. class IteratorToArray final : public Instruction {
  288. public:
  289. IteratorToArray()
  290. : Instruction(Type::IteratorToArray, sizeof(*this))
  291. {
  292. }
  293. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  294. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  295. };
  296. class ConcatString final : public Instruction {
  297. public:
  298. explicit ConcatString(Register lhs)
  299. : Instruction(Type::ConcatString, sizeof(*this))
  300. , m_lhs(lhs)
  301. {
  302. }
  303. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  304. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  305. Register lhs() const { return m_lhs; }
  306. private:
  307. Register m_lhs;
  308. };
  309. enum class EnvironmentMode {
  310. Lexical,
  311. Var,
  312. };
  313. class CreateLexicalEnvironment final : public Instruction {
  314. public:
  315. explicit CreateLexicalEnvironment()
  316. : Instruction(Type::CreateLexicalEnvironment, sizeof(*this))
  317. {
  318. }
  319. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  320. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  321. };
  322. class EnterObjectEnvironment final : public Instruction {
  323. public:
  324. explicit EnterObjectEnvironment()
  325. : Instruction(Type::EnterObjectEnvironment, sizeof(*this))
  326. {
  327. }
  328. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  329. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  330. };
  331. class CreateVariable final : public Instruction {
  332. public:
  333. explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false, bool is_strict = false)
  334. : Instruction(Type::CreateVariable, sizeof(*this))
  335. , m_identifier(identifier)
  336. , m_mode(mode)
  337. , m_is_immutable(is_immutable)
  338. , m_is_global(is_global)
  339. , m_is_strict(is_strict)
  340. {
  341. }
  342. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  343. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  344. IdentifierTableIndex identifier() const { return m_identifier; }
  345. EnvironmentMode mode() const { return m_mode; }
  346. bool is_immutable() const { return m_is_immutable; }
  347. bool is_global() const { return m_is_global; }
  348. bool is_strict() const { return m_is_strict; }
  349. private:
  350. IdentifierTableIndex m_identifier;
  351. EnvironmentMode m_mode;
  352. bool m_is_immutable : 4 { false };
  353. bool m_is_global : 4 { false };
  354. bool m_is_strict { false };
  355. };
  356. class SetVariable final : public Instruction {
  357. public:
  358. enum class InitializationMode {
  359. Initialize,
  360. Set,
  361. };
  362. explicit SetVariable(IdentifierTableIndex identifier, InitializationMode initialization_mode = InitializationMode::Set, EnvironmentMode mode = EnvironmentMode::Lexical)
  363. : Instruction(Type::SetVariable, sizeof(*this))
  364. , m_identifier(identifier)
  365. , m_mode(mode)
  366. , m_initialization_mode(initialization_mode)
  367. {
  368. }
  369. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  370. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  371. IdentifierTableIndex identifier() const { return m_identifier; }
  372. EnvironmentMode mode() const { return m_mode; }
  373. InitializationMode initialization_mode() const { return m_initialization_mode; }
  374. private:
  375. IdentifierTableIndex m_identifier;
  376. EnvironmentMode m_mode;
  377. InitializationMode m_initialization_mode { InitializationMode::Set };
  378. };
  379. class SetLocal final : public Instruction {
  380. public:
  381. explicit SetLocal(size_t index)
  382. : Instruction(Type::SetLocal, sizeof(*this))
  383. , m_index(index)
  384. {
  385. }
  386. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  387. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  388. size_t index() const { return m_index; }
  389. private:
  390. size_t m_index;
  391. };
  392. class GetCalleeAndThisFromEnvironment final : public Instruction {
  393. public:
  394. explicit GetCalleeAndThisFromEnvironment(IdentifierTableIndex identifier, Register callee_reg, Register this_reg, u32 cache_index)
  395. : Instruction(Type::GetCalleeAndThisFromEnvironment, sizeof(*this))
  396. , m_identifier(identifier)
  397. , m_callee_reg(callee_reg)
  398. , m_this_reg(this_reg)
  399. , m_cache_index(cache_index)
  400. {
  401. }
  402. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  403. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  404. IdentifierTableIndex identifier() const { return m_identifier; }
  405. u32 cache_index() const { return m_cache_index; }
  406. Register callee() const { return m_callee_reg; }
  407. Register this_() const { return m_this_reg; }
  408. private:
  409. IdentifierTableIndex m_identifier;
  410. Register m_callee_reg;
  411. Register m_this_reg;
  412. u32 m_cache_index { 0 };
  413. };
  414. class GetVariable final : public Instruction {
  415. public:
  416. explicit GetVariable(IdentifierTableIndex identifier, u32 cache_index)
  417. : Instruction(Type::GetVariable, sizeof(*this))
  418. , m_identifier(identifier)
  419. , m_cache_index(cache_index)
  420. {
  421. }
  422. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  423. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  424. IdentifierTableIndex identifier() const { return m_identifier; }
  425. u32 cache_index() const { return m_cache_index; }
  426. private:
  427. IdentifierTableIndex m_identifier;
  428. u32 m_cache_index { 0 };
  429. };
  430. class GetGlobal final : public Instruction {
  431. public:
  432. explicit GetGlobal(IdentifierTableIndex identifier, u32 cache_index)
  433. : Instruction(Type::GetGlobal, sizeof(*this))
  434. , m_identifier(identifier)
  435. , m_cache_index(cache_index)
  436. {
  437. }
  438. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  439. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  440. IdentifierTableIndex identifier() const { return m_identifier; }
  441. u32 cache_index() const { return m_cache_index; }
  442. private:
  443. IdentifierTableIndex m_identifier;
  444. u32 m_cache_index { 0 };
  445. };
  446. class GetLocal final : public Instruction {
  447. public:
  448. explicit GetLocal(size_t index)
  449. : Instruction(Type::GetLocal, sizeof(*this))
  450. , m_index(index)
  451. {
  452. }
  453. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  454. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  455. size_t index() const { return m_index; }
  456. private:
  457. size_t m_index;
  458. };
  459. class DeleteVariable final : public Instruction {
  460. public:
  461. explicit DeleteVariable(IdentifierTableIndex identifier)
  462. : Instruction(Type::DeleteVariable, sizeof(*this))
  463. , m_identifier(identifier)
  464. {
  465. }
  466. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  467. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  468. IdentifierTableIndex identifier() const { return m_identifier; }
  469. private:
  470. IdentifierTableIndex m_identifier;
  471. };
  472. class GetById final : public Instruction {
  473. public:
  474. GetById(IdentifierTableIndex property, u32 cache_index)
  475. : Instruction(Type::GetById, sizeof(*this))
  476. , m_property(property)
  477. , m_cache_index(cache_index)
  478. {
  479. }
  480. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  481. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  482. IdentifierTableIndex property() const { return m_property; }
  483. u32 cache_index() const { return m_cache_index; }
  484. private:
  485. IdentifierTableIndex m_property;
  486. u32 m_cache_index { 0 };
  487. };
  488. class GetByIdWithThis final : public Instruction {
  489. public:
  490. GetByIdWithThis(IdentifierTableIndex property, Register this_value, u32 cache_index)
  491. : Instruction(Type::GetByIdWithThis, sizeof(*this))
  492. , m_property(property)
  493. , m_this_value(this_value)
  494. , m_cache_index(cache_index)
  495. {
  496. }
  497. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  498. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  499. private:
  500. IdentifierTableIndex m_property;
  501. Register m_this_value;
  502. u32 m_cache_index { 0 };
  503. };
  504. class GetPrivateById final : public Instruction {
  505. public:
  506. explicit GetPrivateById(IdentifierTableIndex property)
  507. : Instruction(Type::GetPrivateById, sizeof(*this))
  508. , m_property(property)
  509. {
  510. }
  511. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  512. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  513. private:
  514. IdentifierTableIndex m_property;
  515. };
  516. class HasPrivateId final : public Instruction {
  517. public:
  518. explicit HasPrivateId(IdentifierTableIndex property)
  519. : Instruction(Type::HasPrivateId, sizeof(*this))
  520. , m_property(property)
  521. {
  522. }
  523. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  524. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  525. private:
  526. IdentifierTableIndex m_property;
  527. };
  528. enum class PropertyKind {
  529. Getter,
  530. Setter,
  531. KeyValue,
  532. DirectKeyValue, // Used for Object expressions. Always sets an own property, never calls a setter.
  533. Spread,
  534. ProtoSetter,
  535. };
  536. class PutById final : public Instruction {
  537. public:
  538. explicit PutById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
  539. : Instruction(Type::PutById, sizeof(*this))
  540. , m_base(base)
  541. , m_property(property)
  542. , m_kind(kind)
  543. {
  544. }
  545. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  546. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  547. Register base() const { return m_base; }
  548. IdentifierTableIndex property() const { return m_property; }
  549. PropertyKind kind() const { return m_kind; }
  550. private:
  551. Register m_base;
  552. IdentifierTableIndex m_property;
  553. PropertyKind m_kind;
  554. };
  555. class PutByIdWithThis final : public Instruction {
  556. public:
  557. PutByIdWithThis(Register base, Register this_value, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
  558. : Instruction(Type::PutByIdWithThis, sizeof(*this))
  559. , m_base(base)
  560. , m_this_value(this_value)
  561. , m_property(property)
  562. , m_kind(kind)
  563. {
  564. }
  565. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  566. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  567. private:
  568. Register m_base;
  569. Register m_this_value;
  570. IdentifierTableIndex m_property;
  571. PropertyKind m_kind;
  572. };
  573. class PutPrivateById final : public Instruction {
  574. public:
  575. explicit PutPrivateById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
  576. : Instruction(Type::PutPrivateById, sizeof(*this))
  577. , m_base(base)
  578. , m_property(property)
  579. , m_kind(kind)
  580. {
  581. }
  582. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  583. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  584. private:
  585. Register m_base;
  586. IdentifierTableIndex m_property;
  587. PropertyKind m_kind;
  588. };
  589. class DeleteById final : public Instruction {
  590. public:
  591. explicit DeleteById(IdentifierTableIndex property)
  592. : Instruction(Type::DeleteById, sizeof(*this))
  593. , m_property(property)
  594. {
  595. }
  596. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  597. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  598. IdentifierTableIndex property() const { return m_property; }
  599. private:
  600. IdentifierTableIndex m_property;
  601. };
  602. class DeleteByIdWithThis final : public Instruction {
  603. public:
  604. DeleteByIdWithThis(Register this_value, IdentifierTableIndex property)
  605. : Instruction(Type::DeleteByIdWithThis, sizeof(*this))
  606. , m_this_value(this_value)
  607. , m_property(property)
  608. {
  609. }
  610. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  611. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  612. private:
  613. Register m_this_value;
  614. IdentifierTableIndex m_property;
  615. };
  616. class GetByValue final : public Instruction {
  617. public:
  618. explicit GetByValue(Register base)
  619. : Instruction(Type::GetByValue, sizeof(*this))
  620. , m_base(base)
  621. {
  622. }
  623. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  624. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  625. Register base() const { return m_base; }
  626. private:
  627. Register m_base;
  628. };
  629. class GetByValueWithThis final : public Instruction {
  630. public:
  631. GetByValueWithThis(Register base, Register this_value)
  632. : Instruction(Type::GetByValueWithThis, sizeof(*this))
  633. , m_base(base)
  634. , m_this_value(this_value)
  635. {
  636. }
  637. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  638. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  639. private:
  640. Register m_base;
  641. Register m_this_value;
  642. };
  643. class PutByValue final : public Instruction {
  644. public:
  645. PutByValue(Register base, Register property, PropertyKind kind = PropertyKind::KeyValue)
  646. : Instruction(Type::PutByValue, sizeof(*this))
  647. , m_base(base)
  648. , m_property(property)
  649. , m_kind(kind)
  650. {
  651. }
  652. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  653. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  654. Register base() const { return m_base; }
  655. Register property() const { return m_property; }
  656. PropertyKind kind() const { return m_kind; }
  657. private:
  658. Register m_base;
  659. Register m_property;
  660. PropertyKind m_kind;
  661. };
  662. class PutByValueWithThis final : public Instruction {
  663. public:
  664. PutByValueWithThis(Register base, Register property, Register this_value, PropertyKind kind = PropertyKind::KeyValue)
  665. : Instruction(Type::PutByValueWithThis, sizeof(*this))
  666. , m_base(base)
  667. , m_property(property)
  668. , m_this_value(this_value)
  669. , m_kind(kind)
  670. {
  671. }
  672. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  673. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  674. private:
  675. Register m_base;
  676. Register m_property;
  677. Register m_this_value;
  678. PropertyKind m_kind;
  679. };
  680. class DeleteByValue final : public Instruction {
  681. public:
  682. DeleteByValue(Register base)
  683. : Instruction(Type::DeleteByValue, sizeof(*this))
  684. , m_base(base)
  685. {
  686. }
  687. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  688. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  689. private:
  690. Register m_base;
  691. };
  692. class DeleteByValueWithThis final : public Instruction {
  693. public:
  694. DeleteByValueWithThis(Register base, Register this_value)
  695. : Instruction(Type::DeleteByValueWithThis, sizeof(*this))
  696. , m_base(base)
  697. , m_this_value(this_value)
  698. {
  699. }
  700. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  701. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  702. private:
  703. Register m_base;
  704. Register m_this_value;
  705. };
  706. class Jump : public Instruction {
  707. public:
  708. constexpr static bool IsTerminator = true;
  709. explicit Jump(Type type, Label taken_target, Optional<Label> nontaken_target = {})
  710. : Instruction(type, sizeof(*this))
  711. , m_true_target(move(taken_target))
  712. , m_false_target(move(nontaken_target))
  713. {
  714. }
  715. explicit Jump(Label taken_target, Optional<Label> nontaken_target = {})
  716. : Instruction(Type::Jump, sizeof(*this))
  717. , m_true_target(move(taken_target))
  718. , m_false_target(move(nontaken_target))
  719. {
  720. }
  721. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  722. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  723. auto& true_target() const { return m_true_target; }
  724. auto& false_target() const { return m_false_target; }
  725. protected:
  726. Optional<Label> m_true_target;
  727. Optional<Label> m_false_target;
  728. };
  729. class JumpConditional final : public Jump {
  730. public:
  731. explicit JumpConditional(Label true_target, Label false_target)
  732. : Jump(Type::JumpConditional, move(true_target), move(false_target))
  733. {
  734. }
  735. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  736. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  737. };
  738. class JumpNullish final : public Jump {
  739. public:
  740. explicit JumpNullish(Label true_target, Label false_target)
  741. : Jump(Type::JumpNullish, move(true_target), move(false_target))
  742. {
  743. }
  744. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  745. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  746. };
  747. class JumpUndefined final : public Jump {
  748. public:
  749. explicit JumpUndefined(Label true_target, Label false_target)
  750. : Jump(Type::JumpUndefined, move(true_target), move(false_target))
  751. {
  752. }
  753. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  754. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  755. };
  756. enum class CallType {
  757. Call,
  758. Construct,
  759. DirectEval,
  760. };
  761. class Call final : public Instruction {
  762. public:
  763. Call(CallType type, Register callee, Register this_value, Register first_argument, u32 argument_count, Optional<StringTableIndex> expression_string = {})
  764. : Instruction(Type::Call, sizeof(*this))
  765. , m_callee(callee)
  766. , m_this_value(this_value)
  767. , m_first_argument(first_argument)
  768. , m_argument_count(argument_count)
  769. , m_type(type)
  770. , m_expression_string(expression_string)
  771. {
  772. }
  773. CallType call_type() const { return m_type; }
  774. Register callee() const { return m_callee; }
  775. Register this_value() const { return m_this_value; }
  776. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  777. Register first_argument() const { return m_first_argument; }
  778. u32 argument_count() const { return m_argument_count; }
  779. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  780. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  781. private:
  782. Register m_callee;
  783. Register m_this_value;
  784. Register m_first_argument;
  785. u32 m_argument_count { 0 };
  786. CallType m_type;
  787. Optional<StringTableIndex> m_expression_string;
  788. };
  789. class CallWithArgumentArray final : public Instruction {
  790. public:
  791. CallWithArgumentArray(CallType type, Register callee, Register this_value, Optional<StringTableIndex> expression_string = {})
  792. : Instruction(Type::CallWithArgumentArray, sizeof(*this))
  793. , m_callee(callee)
  794. , m_this_value(this_value)
  795. , m_type(type)
  796. , m_expression_string(expression_string)
  797. {
  798. }
  799. CallType call_type() const { return m_type; }
  800. Register callee() const { return m_callee; }
  801. Register this_value() const { return m_this_value; }
  802. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  803. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  804. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  805. private:
  806. Register m_callee;
  807. Register m_this_value;
  808. CallType m_type;
  809. Optional<StringTableIndex> m_expression_string;
  810. };
  811. class SuperCallWithArgumentArray : public Instruction {
  812. public:
  813. explicit SuperCallWithArgumentArray(bool is_synthetic)
  814. : Instruction(Type::SuperCallWithArgumentArray, sizeof(*this))
  815. , m_is_synthetic(is_synthetic)
  816. {
  817. }
  818. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  819. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  820. bool is_synthetic() const { return m_is_synthetic; }
  821. private:
  822. bool m_is_synthetic;
  823. };
  824. class NewClass final : public Instruction {
  825. public:
  826. explicit NewClass(ClassExpression const& class_expression, Optional<IdentifierTableIndex> lhs_name)
  827. : Instruction(Type::NewClass, sizeof(*this))
  828. , m_class_expression(class_expression)
  829. , m_lhs_name(lhs_name)
  830. {
  831. }
  832. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  833. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  834. ClassExpression const& class_expression() const { return m_class_expression; }
  835. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  836. private:
  837. ClassExpression const& m_class_expression;
  838. Optional<IdentifierTableIndex> m_lhs_name;
  839. };
  840. class NewFunction final : public Instruction {
  841. public:
  842. explicit NewFunction(FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Register> home_object = {})
  843. : Instruction(Type::NewFunction, sizeof(*this))
  844. , m_function_node(function_node)
  845. , m_lhs_name(lhs_name)
  846. , m_home_object(move(home_object))
  847. {
  848. }
  849. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  850. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  851. FunctionExpression const& function_node() const { return m_function_node; }
  852. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  853. Optional<Register> const& home_object() const { return m_home_object; }
  854. private:
  855. FunctionExpression const& m_function_node;
  856. Optional<IdentifierTableIndex> m_lhs_name;
  857. Optional<Register> m_home_object;
  858. };
  859. class BlockDeclarationInstantiation final : public Instruction {
  860. public:
  861. explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
  862. : Instruction(Type::BlockDeclarationInstantiation, sizeof(*this))
  863. , m_scope_node(scope_node)
  864. {
  865. }
  866. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  867. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  868. ScopeNode const& scope_node() const { return m_scope_node; }
  869. private:
  870. ScopeNode const& m_scope_node;
  871. };
  872. class Return final : public Instruction {
  873. public:
  874. constexpr static bool IsTerminator = true;
  875. Return()
  876. : Instruction(Type::Return, sizeof(*this))
  877. {
  878. }
  879. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  880. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  881. };
  882. class Increment final : public Instruction {
  883. public:
  884. Increment()
  885. : Instruction(Type::Increment, sizeof(*this))
  886. {
  887. }
  888. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  889. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  890. };
  891. class Decrement final : public Instruction {
  892. public:
  893. Decrement()
  894. : Instruction(Type::Decrement, sizeof(*this))
  895. {
  896. }
  897. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  898. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  899. };
  900. class ToNumeric final : public Instruction {
  901. public:
  902. ToNumeric()
  903. : Instruction(Type::ToNumeric, sizeof(*this))
  904. {
  905. }
  906. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  907. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  908. };
  909. class Throw final : public Instruction {
  910. public:
  911. constexpr static bool IsTerminator = true;
  912. Throw()
  913. : Instruction(Type::Throw, sizeof(*this))
  914. {
  915. }
  916. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  917. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  918. };
  919. class ThrowIfNotObject final : public Instruction {
  920. public:
  921. ThrowIfNotObject()
  922. : Instruction(Type::ThrowIfNotObject, sizeof(*this))
  923. {
  924. }
  925. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  926. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  927. };
  928. class ThrowIfNullish final : public Instruction {
  929. public:
  930. ThrowIfNullish()
  931. : Instruction(Type::ThrowIfNullish, sizeof(*this))
  932. {
  933. }
  934. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  935. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  936. };
  937. class EnterUnwindContext final : public Instruction {
  938. public:
  939. constexpr static bool IsTerminator = true;
  940. EnterUnwindContext(Label entry_point, Optional<Label> handler_target, Optional<Label> finalizer_target)
  941. : Instruction(Type::EnterUnwindContext, sizeof(*this))
  942. , m_entry_point(move(entry_point))
  943. , m_handler_target(move(handler_target))
  944. , m_finalizer_target(move(finalizer_target))
  945. {
  946. }
  947. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  948. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  949. auto& entry_point() const { return m_entry_point; }
  950. auto& handler_target() const { return m_handler_target; }
  951. auto& finalizer_target() const { return m_finalizer_target; }
  952. private:
  953. Label m_entry_point;
  954. Optional<Label> m_handler_target;
  955. Optional<Label> m_finalizer_target;
  956. };
  957. class ScheduleJump final : public Instruction {
  958. public:
  959. // Note: We use this instruction to tell the next `finally` block to
  960. // continue execution with a specific break/continue target;
  961. // FIXME: We currently don't clear the interpreter internal flag, when we change
  962. // the control-flow (`break`, `continue`) in a finally-block,
  963. // FIXME: .NET on x86_64 uses a call to the finally instead, which could make this
  964. // easier, at the cost of making control-flow changes (`break`, `continue`, `return`)
  965. // in the finally-block more difficult, but as stated above, those
  966. // aren't handled 100% correctly at the moment anyway
  967. // It might be worth investigating a similar mechanism
  968. constexpr static bool IsTerminator = true;
  969. ScheduleJump(Label target)
  970. : Instruction(Type::ScheduleJump, sizeof(*this))
  971. , m_target(target)
  972. {
  973. }
  974. Label target() const { return m_target; }
  975. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  976. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  977. private:
  978. Label m_target;
  979. };
  980. class LeaveLexicalEnvironment final : public Instruction {
  981. public:
  982. LeaveLexicalEnvironment()
  983. : Instruction(Type::LeaveLexicalEnvironment, sizeof(*this))
  984. {
  985. }
  986. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  987. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  988. };
  989. class LeaveUnwindContext final : public Instruction {
  990. public:
  991. LeaveUnwindContext()
  992. : Instruction(Type::LeaveUnwindContext, sizeof(*this))
  993. {
  994. }
  995. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  996. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  997. };
  998. class ContinuePendingUnwind final : public Instruction {
  999. public:
  1000. constexpr static bool IsTerminator = true;
  1001. explicit ContinuePendingUnwind(Label resume_target)
  1002. : Instruction(Type::ContinuePendingUnwind, sizeof(*this))
  1003. , m_resume_target(resume_target)
  1004. {
  1005. }
  1006. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1007. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1008. auto& resume_target() const { return m_resume_target; }
  1009. private:
  1010. Label m_resume_target;
  1011. };
  1012. class Yield final : public Instruction {
  1013. public:
  1014. constexpr static bool IsTerminator = true;
  1015. explicit Yield(Label continuation_label)
  1016. : Instruction(Type::Yield, sizeof(*this))
  1017. , m_continuation_label(continuation_label)
  1018. {
  1019. }
  1020. explicit Yield(nullptr_t)
  1021. : Instruction(Type::Yield, sizeof(*this))
  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. Optional<Label> m_continuation_label;
  1029. };
  1030. class Await final : public Instruction {
  1031. public:
  1032. constexpr static bool IsTerminator = true;
  1033. explicit Await(Label continuation_label)
  1034. : Instruction(Type::Await, sizeof(*this))
  1035. , m_continuation_label(continuation_label)
  1036. {
  1037. }
  1038. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1039. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1040. auto& continuation() const { return m_continuation_label; }
  1041. private:
  1042. Label m_continuation_label;
  1043. };
  1044. class PushDeclarativeEnvironment final : public Instruction {
  1045. public:
  1046. explicit PushDeclarativeEnvironment(HashMap<u32, Variable> variables)
  1047. : Instruction(Type::PushDeclarativeEnvironment, sizeof(*this))
  1048. , m_variables(move(variables))
  1049. {
  1050. }
  1051. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1052. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1053. private:
  1054. HashMap<u32, Variable> m_variables;
  1055. };
  1056. class GetIterator final : public Instruction {
  1057. public:
  1058. GetIterator(IteratorHint hint = IteratorHint::Sync)
  1059. : Instruction(Type::GetIterator, sizeof(*this))
  1060. , m_hint(hint)
  1061. {
  1062. }
  1063. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1064. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1065. IteratorHint hint() const { return m_hint; }
  1066. private:
  1067. IteratorHint m_hint { IteratorHint::Sync };
  1068. };
  1069. class GetMethod final : public Instruction {
  1070. public:
  1071. GetMethod(IdentifierTableIndex property)
  1072. : Instruction(Type::GetMethod, sizeof(*this))
  1073. , m_property(property)
  1074. {
  1075. }
  1076. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1077. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1078. private:
  1079. IdentifierTableIndex m_property;
  1080. };
  1081. class GetObjectPropertyIterator final : public Instruction {
  1082. public:
  1083. GetObjectPropertyIterator()
  1084. : Instruction(Type::GetObjectPropertyIterator, sizeof(*this))
  1085. {
  1086. }
  1087. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1088. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1089. };
  1090. class IteratorClose final : public Instruction {
  1091. public:
  1092. IteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
  1093. : Instruction(Type::IteratorClose, sizeof(*this))
  1094. , m_completion_type(completion_type)
  1095. , m_completion_value(completion_value)
  1096. {
  1097. }
  1098. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1099. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1100. Completion::Type completion_type() const { return m_completion_type; }
  1101. Optional<Value> const& completion_value() const { return m_completion_value; }
  1102. private:
  1103. Completion::Type m_completion_type { Completion::Type::Normal };
  1104. Optional<Value> m_completion_value;
  1105. };
  1106. class AsyncIteratorClose final : public Instruction {
  1107. public:
  1108. AsyncIteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
  1109. : Instruction(Type::AsyncIteratorClose, sizeof(*this))
  1110. , m_completion_type(completion_type)
  1111. , m_completion_value(completion_value)
  1112. {
  1113. }
  1114. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1115. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1116. private:
  1117. Completion::Type m_completion_type { Completion::Type::Normal };
  1118. Optional<Value> m_completion_value;
  1119. };
  1120. class IteratorNext final : public Instruction {
  1121. public:
  1122. IteratorNext()
  1123. : Instruction(Type::IteratorNext, sizeof(*this))
  1124. {
  1125. }
  1126. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1127. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1128. };
  1129. class IteratorResultDone final : public Instruction {
  1130. public:
  1131. IteratorResultDone()
  1132. : Instruction(Type::IteratorResultDone, sizeof(*this))
  1133. {
  1134. }
  1135. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1136. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1137. };
  1138. class IteratorResultValue final : public Instruction {
  1139. public:
  1140. IteratorResultValue()
  1141. : Instruction(Type::IteratorResultValue, sizeof(*this))
  1142. {
  1143. }
  1144. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1145. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1146. };
  1147. class ResolveThisBinding final : public Instruction {
  1148. public:
  1149. explicit ResolveThisBinding()
  1150. : Instruction(Type::ResolveThisBinding, sizeof(*this))
  1151. {
  1152. }
  1153. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1154. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1155. };
  1156. class ResolveSuperBase final : public Instruction {
  1157. public:
  1158. explicit ResolveSuperBase()
  1159. : Instruction(Type::ResolveSuperBase, sizeof(*this))
  1160. {
  1161. }
  1162. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1163. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1164. };
  1165. class GetNewTarget final : public Instruction {
  1166. public:
  1167. explicit GetNewTarget()
  1168. : Instruction(Type::GetNewTarget, sizeof(*this))
  1169. {
  1170. }
  1171. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1172. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1173. };
  1174. class GetImportMeta final : public Instruction {
  1175. public:
  1176. explicit GetImportMeta()
  1177. : Instruction(Type::GetImportMeta, sizeof(*this))
  1178. {
  1179. }
  1180. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1181. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1182. };
  1183. class TypeofVariable final : public Instruction {
  1184. public:
  1185. explicit TypeofVariable(IdentifierTableIndex identifier)
  1186. : Instruction(Type::TypeofVariable, sizeof(*this))
  1187. , m_identifier(identifier)
  1188. {
  1189. }
  1190. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1191. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1192. IdentifierTableIndex identifier() const { return m_identifier; }
  1193. private:
  1194. IdentifierTableIndex m_identifier;
  1195. };
  1196. class TypeofLocal final : public Instruction {
  1197. public:
  1198. explicit TypeofLocal(size_t index)
  1199. : Instruction(Type::TypeofLocal, sizeof(*this))
  1200. , m_index(index)
  1201. {
  1202. }
  1203. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1204. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1205. size_t index() const { return m_index; }
  1206. private:
  1207. size_t m_index;
  1208. };
  1209. }
  1210. namespace JS::Bytecode {
  1211. ALWAYS_INLINE ThrowCompletionOr<void> Instruction::execute(Bytecode::Interpreter& interpreter) const
  1212. {
  1213. #define __BYTECODE_OP(op) \
  1214. case Instruction::Type::op: \
  1215. return static_cast<Bytecode::Op::op const&>(*this).execute_impl(interpreter);
  1216. switch (type()) {
  1217. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1218. default:
  1219. VERIFY_NOT_REACHED();
  1220. }
  1221. #undef __BYTECODE_OP
  1222. }
  1223. }