Op.h 48 KB

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