Op.h 46 KB

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