Op.h 47 KB

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