Op.h 45 KB

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