Op.h 45 KB

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