Op.h 45 KB

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