Op.h 45 KB

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