Op.h 44 KB

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