Op.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  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. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  688. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  689. auto& true_target() const { return m_true_target; }
  690. auto& false_target() const { return m_false_target; }
  691. protected:
  692. Optional<Label> m_true_target;
  693. Optional<Label> m_false_target;
  694. };
  695. class JumpConditional final : public Jump {
  696. public:
  697. explicit JumpConditional(Label true_target, Label false_target)
  698. : Jump(Type::JumpConditional, move(true_target), move(false_target))
  699. {
  700. }
  701. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  702. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  703. };
  704. class JumpNullish final : public Jump {
  705. public:
  706. explicit JumpNullish(Label true_target, Label false_target)
  707. : Jump(Type::JumpNullish, move(true_target), move(false_target))
  708. {
  709. }
  710. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  711. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  712. };
  713. class JumpUndefined final : public Jump {
  714. public:
  715. explicit JumpUndefined(Label true_target, Label false_target)
  716. : Jump(Type::JumpUndefined, move(true_target), move(false_target))
  717. {
  718. }
  719. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  720. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  721. };
  722. enum class CallType {
  723. Call,
  724. Construct,
  725. DirectEval,
  726. };
  727. class Call final : public Instruction {
  728. public:
  729. Call(CallType type, Register callee, Register this_value, Register first_argument, u32 argument_count, Optional<StringTableIndex> expression_string = {})
  730. : Instruction(Type::Call, sizeof(*this))
  731. , m_callee(callee)
  732. , m_this_value(this_value)
  733. , m_first_argument(first_argument)
  734. , m_argument_count(argument_count)
  735. , m_type(type)
  736. , m_expression_string(expression_string)
  737. {
  738. }
  739. CallType call_type() const { return m_type; }
  740. Register callee() const { return m_callee; }
  741. Register this_value() const { return m_this_value; }
  742. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  743. Register first_argument() const { return m_first_argument; }
  744. u32 argument_count() const { return m_argument_count; }
  745. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  746. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  747. private:
  748. Register m_callee;
  749. Register m_this_value;
  750. Register m_first_argument;
  751. u32 m_argument_count { 0 };
  752. CallType m_type;
  753. Optional<StringTableIndex> m_expression_string;
  754. };
  755. class CallWithArgumentArray final : public Instruction {
  756. public:
  757. CallWithArgumentArray(CallType type, Register callee, Register this_value, Optional<StringTableIndex> expression_string = {})
  758. : Instruction(Type::CallWithArgumentArray, sizeof(*this))
  759. , m_callee(callee)
  760. , m_this_value(this_value)
  761. , m_type(type)
  762. , m_expression_string(expression_string)
  763. {
  764. }
  765. CallType call_type() const { return m_type; }
  766. Register callee() const { return m_callee; }
  767. Register this_value() const { return m_this_value; }
  768. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  769. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  770. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  771. private:
  772. Register m_callee;
  773. Register m_this_value;
  774. CallType m_type;
  775. Optional<StringTableIndex> m_expression_string;
  776. };
  777. class SuperCallWithArgumentArray : public Instruction {
  778. public:
  779. explicit SuperCallWithArgumentArray(bool is_synthetic)
  780. : Instruction(Type::SuperCallWithArgumentArray, sizeof(*this))
  781. , m_is_synthetic(is_synthetic)
  782. {
  783. }
  784. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  785. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  786. private:
  787. bool m_is_synthetic;
  788. };
  789. class NewClass final : public Instruction {
  790. public:
  791. explicit NewClass(ClassExpression const& class_expression, Optional<IdentifierTableIndex> lhs_name)
  792. : Instruction(Type::NewClass, sizeof(*this))
  793. , m_class_expression(class_expression)
  794. , m_lhs_name(lhs_name)
  795. {
  796. }
  797. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  798. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  799. private:
  800. ClassExpression const& m_class_expression;
  801. Optional<IdentifierTableIndex> m_lhs_name;
  802. };
  803. class NewFunction final : public Instruction {
  804. public:
  805. explicit NewFunction(FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Register> home_object = {})
  806. : Instruction(Type::NewFunction, sizeof(*this))
  807. , m_function_node(function_node)
  808. , m_lhs_name(lhs_name)
  809. , m_home_object(move(home_object))
  810. {
  811. }
  812. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  813. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  814. private:
  815. FunctionExpression const& m_function_node;
  816. Optional<IdentifierTableIndex> m_lhs_name;
  817. Optional<Register> m_home_object;
  818. };
  819. class BlockDeclarationInstantiation final : public Instruction {
  820. public:
  821. explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
  822. : Instruction(Type::BlockDeclarationInstantiation, sizeof(*this))
  823. , m_scope_node(scope_node)
  824. {
  825. }
  826. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  827. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  828. private:
  829. ScopeNode const& m_scope_node;
  830. };
  831. class Return final : public Instruction {
  832. public:
  833. constexpr static bool IsTerminator = true;
  834. Return()
  835. : Instruction(Type::Return, sizeof(*this))
  836. {
  837. }
  838. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  839. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  840. };
  841. class Increment final : public Instruction {
  842. public:
  843. Increment()
  844. : Instruction(Type::Increment, sizeof(*this))
  845. {
  846. }
  847. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  848. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  849. };
  850. class Decrement final : public Instruction {
  851. public:
  852. Decrement()
  853. : Instruction(Type::Decrement, sizeof(*this))
  854. {
  855. }
  856. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  857. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  858. };
  859. class ToNumeric final : public Instruction {
  860. public:
  861. ToNumeric()
  862. : Instruction(Type::ToNumeric, sizeof(*this))
  863. {
  864. }
  865. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  866. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  867. };
  868. class Throw final : public Instruction {
  869. public:
  870. constexpr static bool IsTerminator = true;
  871. Throw()
  872. : Instruction(Type::Throw, sizeof(*this))
  873. {
  874. }
  875. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  876. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  877. };
  878. class ThrowIfNotObject final : public Instruction {
  879. public:
  880. ThrowIfNotObject()
  881. : Instruction(Type::ThrowIfNotObject, sizeof(*this))
  882. {
  883. }
  884. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  885. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  886. };
  887. class ThrowIfNullish final : public Instruction {
  888. public:
  889. ThrowIfNullish()
  890. : Instruction(Type::ThrowIfNullish, sizeof(*this))
  891. {
  892. }
  893. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  894. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  895. };
  896. class EnterUnwindContext final : public Instruction {
  897. public:
  898. constexpr static bool IsTerminator = true;
  899. EnterUnwindContext(Label entry_point, Optional<Label> handler_target, Optional<Label> finalizer_target)
  900. : Instruction(Type::EnterUnwindContext, sizeof(*this))
  901. , m_entry_point(move(entry_point))
  902. , m_handler_target(move(handler_target))
  903. , m_finalizer_target(move(finalizer_target))
  904. {
  905. }
  906. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  907. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  908. auto& entry_point() const { return m_entry_point; }
  909. auto& handler_target() const { return m_handler_target; }
  910. auto& finalizer_target() const { return m_finalizer_target; }
  911. private:
  912. Label m_entry_point;
  913. Optional<Label> m_handler_target;
  914. Optional<Label> m_finalizer_target;
  915. };
  916. class ScheduleJump final : public Instruction {
  917. public:
  918. // Note: We use this instruction to tell the next `finally` block to
  919. // continue execution with a specific break/continue target;
  920. // FIXME: We currently don't clear the interpreter internal flag, when we change
  921. // the control-flow (`break`, `continue`) in a finally-block,
  922. // FIXME: .NET on x86_64 uses a call to the finally instead, which could make this
  923. // easier, at the cost of making control-flow changes (`break`, `continue`, `return`)
  924. // in the finally-block more difficult, but as stated above, those
  925. // aren't handled 100% correctly at the moment anyway
  926. // It might be worth investigating a similar mechanism
  927. constexpr static bool IsTerminator = true;
  928. ScheduleJump(Label target)
  929. : Instruction(Type::ScheduleJump, sizeof(*this))
  930. , m_target(target)
  931. {
  932. }
  933. Label target() const { return m_target; }
  934. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  935. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  936. private:
  937. Label m_target;
  938. };
  939. class LeaveLexicalEnvironment final : public Instruction {
  940. public:
  941. LeaveLexicalEnvironment()
  942. : Instruction(Type::LeaveLexicalEnvironment, sizeof(*this))
  943. {
  944. }
  945. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  946. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  947. };
  948. class LeaveUnwindContext final : public Instruction {
  949. public:
  950. LeaveUnwindContext()
  951. : Instruction(Type::LeaveUnwindContext, sizeof(*this))
  952. {
  953. }
  954. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  955. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  956. };
  957. class ContinuePendingUnwind final : public Instruction {
  958. public:
  959. constexpr static bool IsTerminator = true;
  960. explicit ContinuePendingUnwind(Label resume_target)
  961. : Instruction(Type::ContinuePendingUnwind, sizeof(*this))
  962. , m_resume_target(resume_target)
  963. {
  964. }
  965. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  966. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  967. auto& resume_target() const { return m_resume_target; }
  968. private:
  969. Label m_resume_target;
  970. };
  971. class Yield final : public Instruction {
  972. public:
  973. constexpr static bool IsTerminator = true;
  974. explicit Yield(Label continuation_label)
  975. : Instruction(Type::Yield, sizeof(*this))
  976. , m_continuation_label(continuation_label)
  977. {
  978. }
  979. explicit Yield(nullptr_t)
  980. : Instruction(Type::Yield, sizeof(*this))
  981. {
  982. }
  983. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  984. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  985. auto& continuation() const { return m_continuation_label; }
  986. private:
  987. Optional<Label> m_continuation_label;
  988. };
  989. class Await final : public Instruction {
  990. public:
  991. constexpr static bool IsTerminator = true;
  992. explicit Await(Label continuation_label)
  993. : Instruction(Type::Await, sizeof(*this))
  994. , m_continuation_label(continuation_label)
  995. {
  996. }
  997. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  998. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  999. auto& continuation() const { return m_continuation_label; }
  1000. private:
  1001. Label m_continuation_label;
  1002. };
  1003. class PushDeclarativeEnvironment final : public Instruction {
  1004. public:
  1005. explicit PushDeclarativeEnvironment(HashMap<u32, Variable> variables)
  1006. : Instruction(Type::PushDeclarativeEnvironment, sizeof(*this))
  1007. , m_variables(move(variables))
  1008. {
  1009. }
  1010. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1011. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1012. private:
  1013. HashMap<u32, Variable> m_variables;
  1014. };
  1015. class GetIterator final : public Instruction {
  1016. public:
  1017. GetIterator(IteratorHint hint = IteratorHint::Sync)
  1018. : Instruction(Type::GetIterator, sizeof(*this))
  1019. , m_hint(hint)
  1020. {
  1021. }
  1022. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1023. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1024. private:
  1025. IteratorHint m_hint { IteratorHint::Sync };
  1026. };
  1027. class GetMethod final : public Instruction {
  1028. public:
  1029. GetMethod(IdentifierTableIndex property)
  1030. : Instruction(Type::GetMethod, sizeof(*this))
  1031. , m_property(property)
  1032. {
  1033. }
  1034. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1035. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1036. private:
  1037. IdentifierTableIndex m_property;
  1038. };
  1039. class GetObjectPropertyIterator final : public Instruction {
  1040. public:
  1041. GetObjectPropertyIterator()
  1042. : Instruction(Type::GetObjectPropertyIterator, sizeof(*this))
  1043. {
  1044. }
  1045. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1046. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1047. };
  1048. class IteratorClose final : public Instruction {
  1049. public:
  1050. IteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
  1051. : Instruction(Type::IteratorClose, sizeof(*this))
  1052. , m_completion_type(completion_type)
  1053. , m_completion_value(completion_value)
  1054. {
  1055. }
  1056. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1057. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1058. private:
  1059. Completion::Type m_completion_type { Completion::Type::Normal };
  1060. Optional<Value> m_completion_value;
  1061. };
  1062. class AsyncIteratorClose final : public Instruction {
  1063. public:
  1064. AsyncIteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
  1065. : Instruction(Type::AsyncIteratorClose, sizeof(*this))
  1066. , m_completion_type(completion_type)
  1067. , m_completion_value(completion_value)
  1068. {
  1069. }
  1070. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1071. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1072. private:
  1073. Completion::Type m_completion_type { Completion::Type::Normal };
  1074. Optional<Value> m_completion_value;
  1075. };
  1076. class IteratorNext final : public Instruction {
  1077. public:
  1078. IteratorNext()
  1079. : Instruction(Type::IteratorNext, sizeof(*this))
  1080. {
  1081. }
  1082. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1083. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1084. };
  1085. class IteratorResultDone final : public Instruction {
  1086. public:
  1087. IteratorResultDone()
  1088. : Instruction(Type::IteratorResultDone, sizeof(*this))
  1089. {
  1090. }
  1091. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1092. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1093. };
  1094. class IteratorResultValue final : public Instruction {
  1095. public:
  1096. IteratorResultValue()
  1097. : Instruction(Type::IteratorResultValue, sizeof(*this))
  1098. {
  1099. }
  1100. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1101. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1102. };
  1103. class ResolveThisBinding final : public Instruction {
  1104. public:
  1105. explicit ResolveThisBinding()
  1106. : Instruction(Type::ResolveThisBinding, sizeof(*this))
  1107. {
  1108. }
  1109. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1110. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1111. };
  1112. class ResolveSuperBase final : public Instruction {
  1113. public:
  1114. explicit ResolveSuperBase()
  1115. : Instruction(Type::ResolveSuperBase, sizeof(*this))
  1116. {
  1117. }
  1118. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1119. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1120. };
  1121. class GetNewTarget final : public Instruction {
  1122. public:
  1123. explicit GetNewTarget()
  1124. : Instruction(Type::GetNewTarget, sizeof(*this))
  1125. {
  1126. }
  1127. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1128. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1129. };
  1130. class GetImportMeta final : public Instruction {
  1131. public:
  1132. explicit GetImportMeta()
  1133. : Instruction(Type::GetImportMeta, sizeof(*this))
  1134. {
  1135. }
  1136. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1137. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1138. };
  1139. class TypeofVariable final : public Instruction {
  1140. public:
  1141. explicit TypeofVariable(IdentifierTableIndex identifier)
  1142. : Instruction(Type::TypeofVariable, sizeof(*this))
  1143. , m_identifier(identifier)
  1144. {
  1145. }
  1146. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1147. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1148. private:
  1149. IdentifierTableIndex m_identifier;
  1150. };
  1151. class TypeofLocal final : public Instruction {
  1152. public:
  1153. explicit TypeofLocal(size_t index)
  1154. : Instruction(Type::TypeofLocal, sizeof(*this))
  1155. , m_index(index)
  1156. {
  1157. }
  1158. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1159. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1160. private:
  1161. size_t m_index;
  1162. };
  1163. }
  1164. namespace JS::Bytecode {
  1165. ALWAYS_INLINE ThrowCompletionOr<void> Instruction::execute(Bytecode::Interpreter& interpreter) const
  1166. {
  1167. #define __BYTECODE_OP(op) \
  1168. case Instruction::Type::op: \
  1169. return static_cast<Bytecode::Op::op const&>(*this).execute_impl(interpreter);
  1170. switch (type()) {
  1171. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1172. default:
  1173. VERIFY_NOT_REACHED();
  1174. }
  1175. #undef __BYTECODE_OP
  1176. }
  1177. }