Op.h 45 KB

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