Op.h 46 KB

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