Op.h 46 KB

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