AST.h 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2021, David Tuin <davidot@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/FlyString.h>
  10. #include <AK/HashMap.h>
  11. #include <AK/NonnullRefPtrVector.h>
  12. #include <AK/OwnPtr.h>
  13. #include <AK/RefPtr.h>
  14. #include <AK/String.h>
  15. #include <AK/Variant.h>
  16. #include <AK/Vector.h>
  17. #include <LibJS/Forward.h>
  18. #include <LibJS/Runtime/EnvironmentCoordinate.h>
  19. #include <LibJS/Runtime/FunctionKind.h>
  20. #include <LibJS/Runtime/PropertyKey.h>
  21. #include <LibJS/Runtime/Reference.h>
  22. #include <LibJS/Runtime/Value.h>
  23. #include <LibJS/SourceRange.h>
  24. #include <LibRegex/Regex.h>
  25. namespace JS {
  26. class Declaration;
  27. class ClassDeclaration;
  28. class FunctionDeclaration;
  29. class Identifier;
  30. class MemberExpression;
  31. class VariableDeclaration;
  32. template<class T, class... Args>
  33. static inline NonnullRefPtr<T>
  34. create_ast_node(SourceRange range, Args&&... args)
  35. {
  36. return adopt_ref(*new T(range, forward<Args>(args)...));
  37. }
  38. class ASTNode : public RefCounted<ASTNode> {
  39. public:
  40. virtual ~ASTNode() { }
  41. virtual Value execute(Interpreter&, GlobalObject&) const = 0;
  42. virtual void generate_bytecode(Bytecode::Generator&) const;
  43. virtual void dump(int indent) const;
  44. SourceRange const& source_range() const { return m_source_range; }
  45. SourceRange& source_range() { return m_source_range; }
  46. String class_name() const;
  47. template<typename T>
  48. bool fast_is() const = delete;
  49. virtual bool is_new_expression() const { return false; }
  50. virtual bool is_member_expression() const { return false; }
  51. virtual bool is_super_expression() const { return false; }
  52. virtual bool is_function_expression() const { return false; }
  53. virtual bool is_class_expression() const { return false; }
  54. virtual bool is_expression_statement() const { return false; }
  55. virtual bool is_identifier() const { return false; }
  56. virtual bool is_scope_node() const { return false; }
  57. virtual bool is_program() const { return false; }
  58. virtual bool is_function_declaration() const { return false; }
  59. protected:
  60. explicit ASTNode(SourceRange source_range)
  61. : m_source_range(source_range)
  62. {
  63. }
  64. private:
  65. SourceRange m_source_range;
  66. };
  67. class Statement : public ASTNode {
  68. public:
  69. explicit Statement(SourceRange source_range)
  70. : ASTNode(source_range)
  71. {
  72. }
  73. };
  74. class LabelableStatement : public Statement {
  75. public:
  76. using Statement::Statement;
  77. Vector<FlyString> const& labels() const { return m_labels; }
  78. virtual void add_label(FlyString string) { m_labels.append(move(string)); }
  79. protected:
  80. Vector<FlyString> m_labels;
  81. };
  82. class IterationStatement : public LabelableStatement {
  83. public:
  84. using LabelableStatement::LabelableStatement;
  85. };
  86. class EmptyStatement final : public Statement {
  87. public:
  88. explicit EmptyStatement(SourceRange source_range)
  89. : Statement(source_range)
  90. {
  91. }
  92. Value execute(Interpreter&, GlobalObject&) const override { return {}; }
  93. virtual void generate_bytecode(Bytecode::Generator&) const override;
  94. };
  95. class ErrorStatement final : public Statement {
  96. public:
  97. explicit ErrorStatement(SourceRange source_range)
  98. : Statement(source_range)
  99. {
  100. }
  101. Value execute(Interpreter&, GlobalObject&) const override { return {}; }
  102. };
  103. class ExpressionStatement final : public Statement {
  104. public:
  105. ExpressionStatement(SourceRange source_range, NonnullRefPtr<Expression> expression)
  106. : Statement(source_range)
  107. , m_expression(move(expression))
  108. {
  109. }
  110. virtual Value execute(Interpreter&, GlobalObject&) const override;
  111. virtual void dump(int indent) const override;
  112. virtual void generate_bytecode(Bytecode::Generator&) const override;
  113. Expression const& expression() const { return m_expression; };
  114. private:
  115. virtual bool is_expression_statement() const override { return true; }
  116. NonnullRefPtr<Expression> m_expression;
  117. };
  118. template<typename... Args>
  119. class IteratorOrVoidFunction : public Function<IterationDecision(Args...)> {
  120. public:
  121. template<typename CallableType>
  122. IteratorOrVoidFunction(CallableType&& callable) requires(VoidFunction<CallableType, Args...>)
  123. : Function<IterationDecision(Args...)>([callable = forward<CallableType>(callable)](Args... args) {
  124. callable(args...);
  125. return IterationDecision::Continue;
  126. })
  127. {
  128. }
  129. template<typename CallableType>
  130. IteratorOrVoidFunction(CallableType&& callable) requires(IteratorFunction<CallableType, Args...>)
  131. : Function<IterationDecision(Args...)>(forward<CallableType>(callable))
  132. {
  133. }
  134. };
  135. class ScopeNode : public LabelableStatement {
  136. public:
  137. template<typename T, typename... Args>
  138. T& append(SourceRange range, Args&&... args)
  139. {
  140. auto child = create_ast_node<T>(range, forward<Args>(args)...);
  141. m_children.append(move(child));
  142. return static_cast<T&>(m_children.last());
  143. }
  144. void append(NonnullRefPtr<Statement> child)
  145. {
  146. m_children.append(move(child));
  147. }
  148. NonnullRefPtrVector<Statement> const& children() const { return m_children; }
  149. virtual void dump(int indent) const override;
  150. virtual void generate_bytecode(Bytecode::Generator&) const override;
  151. Value evaluate_statements(Interpreter& interpreter, GlobalObject& global_object) const;
  152. void add_var_scoped_declaration(NonnullRefPtr<Declaration> variables);
  153. void add_lexical_declaration(NonnullRefPtr<Declaration> variables);
  154. void add_hoisted_function(NonnullRefPtr<FunctionDeclaration> declaration);
  155. [[nodiscard]] bool has_lexical_declarations() const { return !m_lexical_declarations.is_empty(); }
  156. [[nodiscard]] bool has_var_declarations() const { return !m_var_declarations.is_empty(); }
  157. [[nodiscard]] size_t var_declaration_count() const { return m_var_declarations.size(); }
  158. [[nodiscard]] size_t lexical_declaration_count() const { return m_lexical_declarations.size(); }
  159. void for_each_lexically_scoped_declaration(IteratorOrVoidFunction<Declaration const&>&& callback) const;
  160. void for_each_lexically_declared_name(IteratorOrVoidFunction<FlyString const&>&& callback) const;
  161. void for_each_var_declared_name(IteratorOrVoidFunction<FlyString const&>&& callback) const;
  162. void for_each_var_function_declaration_in_reverse_order(IteratorOrVoidFunction<FunctionDeclaration const&>&& callback) const;
  163. void for_each_var_scoped_variable_declaration(IteratorOrVoidFunction<VariableDeclaration const&>&& callback) const;
  164. void block_declaration_instantiation(GlobalObject& global_object, Environment* environment) const;
  165. void for_each_function_hoistable_with_annexB_extension(IteratorOrVoidFunction<FunctionDeclaration&>&& callback) const;
  166. protected:
  167. explicit ScopeNode(SourceRange source_range)
  168. : LabelableStatement(source_range)
  169. {
  170. }
  171. private:
  172. virtual bool is_scope_node() const final { return true; }
  173. NonnullRefPtrVector<Statement> m_children;
  174. NonnullRefPtrVector<Declaration> m_lexical_declarations;
  175. NonnullRefPtrVector<Declaration> m_var_declarations;
  176. NonnullRefPtrVector<FunctionDeclaration> m_functions_hoistable_with_annexB_extension;
  177. };
  178. class ImportStatement final : public Statement {
  179. public:
  180. struct ImportEntry {
  181. String import_name;
  182. String local_name;
  183. };
  184. explicit ImportStatement(SourceRange source_range, StringView from_module, Vector<ImportEntry> entries = {})
  185. : Statement(source_range)
  186. , m_module_request(from_module)
  187. , m_entries(move(entries))
  188. {
  189. }
  190. virtual Value execute(Interpreter&, GlobalObject&) const override;
  191. virtual void dump(int indent) const override;
  192. bool has_bound_name(StringView name) const;
  193. private:
  194. String m_module_request;
  195. Vector<ImportEntry> m_entries;
  196. };
  197. class ExportStatement final : public Statement {
  198. public:
  199. struct ExportEntry {
  200. enum Kind {
  201. ModuleRequest,
  202. LocalExport
  203. } kind;
  204. // Can always have
  205. String export_name;
  206. // Only if module request
  207. String module_request;
  208. // Has just one of ones below
  209. String local_or_import_name;
  210. ExportEntry(String export_name, String local_name)
  211. : kind(LocalExport)
  212. , export_name(move(export_name))
  213. , local_or_import_name(move(local_name))
  214. {
  215. }
  216. };
  217. explicit ExportStatement(SourceRange source_range, RefPtr<ASTNode> statement, Vector<ExportEntry> entries)
  218. : Statement(source_range)
  219. , m_statement(move(statement))
  220. , m_entries(move(entries))
  221. {
  222. }
  223. virtual Value execute(Interpreter&, GlobalObject&) const override;
  224. virtual void dump(int indent) const override;
  225. bool has_export(StringView export_name) const;
  226. bool has_statement() const { return m_statement; }
  227. Vector<ExportEntry> const& entries() const { return m_entries; }
  228. private:
  229. RefPtr<ASTNode> m_statement;
  230. Vector<ExportEntry> m_entries;
  231. };
  232. class Program final : public ScopeNode {
  233. public:
  234. enum class Type {
  235. Script,
  236. Module
  237. };
  238. explicit Program(SourceRange source_range, Type program_type)
  239. : ScopeNode(source_range)
  240. , m_type(program_type)
  241. {
  242. }
  243. virtual Value execute(Interpreter&, GlobalObject&) const override;
  244. bool is_strict_mode() const { return m_is_strict_mode; }
  245. void set_strict_mode() { m_is_strict_mode = true; }
  246. Type type() const { return m_type; }
  247. void append_import(NonnullRefPtr<ImportStatement> import_statement)
  248. {
  249. m_imports.append(import_statement);
  250. append(import_statement);
  251. }
  252. void append_export(NonnullRefPtr<ExportStatement> export_statement)
  253. {
  254. m_exports.append(export_statement);
  255. append(export_statement);
  256. }
  257. NonnullRefPtrVector<ImportStatement> const& imports() const { return m_imports; }
  258. NonnullRefPtrVector<ExportStatement> const& exports() const { return m_exports; }
  259. ThrowCompletionOr<void> global_declaration_instantiation(Interpreter& interpreter, GlobalObject& global_object, GlobalEnvironment& global_environment) const;
  260. private:
  261. virtual bool is_program() const override { return true; }
  262. bool m_is_strict_mode { false };
  263. Type m_type { Type::Script };
  264. NonnullRefPtrVector<ImportStatement> m_imports;
  265. NonnullRefPtrVector<ExportStatement> m_exports;
  266. };
  267. class BlockStatement final : public ScopeNode {
  268. public:
  269. explicit BlockStatement(SourceRange source_range)
  270. : ScopeNode(source_range)
  271. {
  272. }
  273. Value execute(Interpreter& interpreter, GlobalObject& object) const override;
  274. };
  275. class FunctionBody final : public ScopeNode {
  276. public:
  277. explicit FunctionBody(SourceRange source_range)
  278. : ScopeNode(source_range)
  279. {
  280. }
  281. void set_strict_mode() { m_in_strict_mode = true; }
  282. bool in_strict_mode() const { return m_in_strict_mode; }
  283. virtual Value execute(Interpreter&, GlobalObject&) const override;
  284. private:
  285. bool m_in_strict_mode { false };
  286. };
  287. class Expression : public ASTNode {
  288. public:
  289. explicit Expression(SourceRange source_range)
  290. : ASTNode(source_range)
  291. {
  292. }
  293. virtual Reference to_reference(Interpreter&, GlobalObject&) const;
  294. };
  295. class Declaration : public Statement {
  296. public:
  297. explicit Declaration(SourceRange source_range)
  298. : Statement(source_range)
  299. {
  300. }
  301. virtual void for_each_bound_name(IteratorOrVoidFunction<FlyString const&> callback) const = 0;
  302. // 8.1.3 Static Semantics: IsConstantDeclaration, https://tc39.es/ecma262/#sec-static-semantics-isconstantdeclaration
  303. virtual bool is_constant_declaration() const { return false; }
  304. virtual bool is_lexical_declaration() const { return false; }
  305. };
  306. class ErrorDeclaration final : public Declaration {
  307. public:
  308. explicit ErrorDeclaration(SourceRange source_range)
  309. : Declaration(source_range)
  310. {
  311. }
  312. Value execute(Interpreter&, GlobalObject&) const override { return {}; }
  313. void for_each_bound_name(IteratorOrVoidFunction<FlyString const&>) const override
  314. {
  315. VERIFY_NOT_REACHED();
  316. }
  317. };
  318. struct BindingPattern : RefCounted<BindingPattern> {
  319. // This covers both BindingProperty and BindingElement, hence the more generic name
  320. struct BindingEntry {
  321. // If this entry represents a BindingElement, then name will be Empty
  322. Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<Expression>, Empty> name {};
  323. Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>, NonnullRefPtr<MemberExpression>, Empty> alias {};
  324. RefPtr<Expression> initializer {};
  325. bool is_rest { false };
  326. bool is_elision() const { return name.has<Empty>() && alias.has<Empty>(); }
  327. };
  328. enum class Kind {
  329. Array,
  330. Object,
  331. };
  332. void dump(int indent) const;
  333. template<typename C>
  334. void for_each_bound_name(C&& callback) const;
  335. bool contains_expression() const;
  336. Vector<BindingEntry> entries;
  337. Kind kind { Kind::Object };
  338. };
  339. class FunctionNode {
  340. public:
  341. struct Parameter {
  342. Variant<FlyString, NonnullRefPtr<BindingPattern>> binding;
  343. RefPtr<Expression> default_value;
  344. bool is_rest { false };
  345. };
  346. FlyString const& name() const { return m_name; }
  347. Statement const& body() const { return *m_body; }
  348. Vector<Parameter> const& parameters() const { return m_parameters; };
  349. i32 function_length() const { return m_function_length; }
  350. bool is_strict_mode() const { return m_is_strict_mode; }
  351. bool might_need_arguments_object() const { return m_might_need_arguments_object; }
  352. bool contains_direct_call_to_eval() const { return m_contains_direct_call_to_eval; }
  353. bool is_arrow_function() const { return m_is_arrow_function; }
  354. FunctionKind kind() const { return m_kind; }
  355. protected:
  356. FunctionNode(FlyString name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function)
  357. : m_name(move(name))
  358. , m_body(move(body))
  359. , m_parameters(move(parameters))
  360. , m_function_length(function_length)
  361. , m_kind(kind)
  362. , m_is_strict_mode(is_strict_mode)
  363. , m_might_need_arguments_object(might_need_arguments_object)
  364. , m_contains_direct_call_to_eval(contains_direct_call_to_eval)
  365. , m_is_arrow_function(is_arrow_function)
  366. {
  367. if (m_is_arrow_function)
  368. VERIFY(!m_might_need_arguments_object);
  369. }
  370. void dump(int indent, String const& class_name) const;
  371. protected:
  372. void set_name(FlyString name)
  373. {
  374. VERIFY(m_name.is_empty());
  375. m_name = move(name);
  376. }
  377. private:
  378. FlyString m_name;
  379. NonnullRefPtr<Statement> m_body;
  380. Vector<Parameter> const m_parameters;
  381. const i32 m_function_length;
  382. FunctionKind m_kind;
  383. bool m_is_strict_mode { false };
  384. bool m_might_need_arguments_object { false };
  385. bool m_contains_direct_call_to_eval { false };
  386. bool m_is_arrow_function { false };
  387. };
  388. class FunctionDeclaration final
  389. : public Declaration
  390. , public FunctionNode {
  391. public:
  392. static bool must_have_name() { return true; }
  393. FunctionDeclaration(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, bool might_need_arguments_object, bool contains_direct_call_to_eval)
  394. : Declaration(source_range)
  395. , FunctionNode(name, move(body), move(parameters), function_length, kind, is_strict_mode, might_need_arguments_object, contains_direct_call_to_eval, false)
  396. {
  397. }
  398. virtual Value execute(Interpreter&, GlobalObject&) const override;
  399. virtual void dump(int indent) const override;
  400. virtual void generate_bytecode(Bytecode::Generator&) const override;
  401. void for_each_bound_name(IteratorOrVoidFunction<FlyString const&> callback) const override;
  402. virtual bool is_function_declaration() const override { return true; }
  403. void set_should_do_additional_annexB_steps() { m_is_hoisted = true; }
  404. private:
  405. bool m_is_hoisted { false };
  406. };
  407. class FunctionExpression final
  408. : public Expression
  409. , public FunctionNode {
  410. public:
  411. static bool must_have_name() { return false; }
  412. FunctionExpression(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function = false)
  413. : Expression(source_range)
  414. , FunctionNode(name, move(body), move(parameters), function_length, kind, is_strict_mode, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function)
  415. {
  416. }
  417. virtual Value execute(Interpreter&, GlobalObject&) const override;
  418. virtual void dump(int indent) const override;
  419. virtual void generate_bytecode(Bytecode::Generator&) const override;
  420. bool has_name() const { return !name().is_empty(); }
  421. Value instantiate_ordinary_function_expression(Interpreter& interpreter, GlobalObject& global_object, FlyString given_name) const;
  422. private:
  423. virtual bool is_function_expression() const override { return true; }
  424. };
  425. class ErrorExpression final : public Expression {
  426. public:
  427. explicit ErrorExpression(SourceRange source_range)
  428. : Expression(source_range)
  429. {
  430. }
  431. Value execute(Interpreter&, GlobalObject&) const override { return {}; }
  432. };
  433. class YieldExpression final : public Expression {
  434. public:
  435. explicit YieldExpression(SourceRange source_range, RefPtr<Expression> argument, bool is_yield_from)
  436. : Expression(source_range)
  437. , m_argument(move(argument))
  438. , m_is_yield_from(is_yield_from)
  439. {
  440. }
  441. Expression const* argument() const { return m_argument; }
  442. bool is_yield_from() const { return m_is_yield_from; }
  443. virtual Value execute(Interpreter&, GlobalObject&) const override;
  444. virtual void dump(int indent) const override;
  445. virtual void generate_bytecode(Bytecode::Generator&) const override;
  446. private:
  447. RefPtr<Expression> m_argument;
  448. bool m_is_yield_from { false };
  449. };
  450. class AwaitExpression final : public Expression {
  451. public:
  452. explicit AwaitExpression(SourceRange source_range, NonnullRefPtr<Expression> argument)
  453. : Expression(source_range)
  454. , m_argument(move(argument))
  455. {
  456. }
  457. virtual Value execute(Interpreter&, GlobalObject&) const override;
  458. virtual void dump(int indent) const override;
  459. virtual void generate_bytecode(Bytecode::Generator&) const override;
  460. private:
  461. NonnullRefPtr<Expression> m_argument;
  462. };
  463. class ReturnStatement final : public Statement {
  464. public:
  465. explicit ReturnStatement(SourceRange source_range, RefPtr<Expression> argument)
  466. : Statement(source_range)
  467. , m_argument(move(argument))
  468. {
  469. }
  470. Expression const* argument() const { return m_argument; }
  471. virtual Value execute(Interpreter&, GlobalObject&) const override;
  472. virtual void dump(int indent) const override;
  473. virtual void generate_bytecode(Bytecode::Generator&) const override;
  474. private:
  475. RefPtr<Expression> m_argument;
  476. };
  477. class IfStatement final : public Statement {
  478. public:
  479. IfStatement(SourceRange source_range, NonnullRefPtr<Expression> predicate, NonnullRefPtr<Statement> consequent, RefPtr<Statement> alternate)
  480. : Statement(source_range)
  481. , m_predicate(move(predicate))
  482. , m_consequent(move(consequent))
  483. , m_alternate(move(alternate))
  484. {
  485. }
  486. Expression const& predicate() const { return *m_predicate; }
  487. Statement const& consequent() const { return *m_consequent; }
  488. Statement const* alternate() const { return m_alternate; }
  489. virtual Value execute(Interpreter&, GlobalObject&) const override;
  490. virtual void dump(int indent) const override;
  491. virtual void generate_bytecode(Bytecode::Generator&) const override;
  492. private:
  493. NonnullRefPtr<Expression> m_predicate;
  494. NonnullRefPtr<Statement> m_consequent;
  495. RefPtr<Statement> m_alternate;
  496. };
  497. class WhileStatement final : public IterationStatement {
  498. public:
  499. WhileStatement(SourceRange source_range, NonnullRefPtr<Expression> test, NonnullRefPtr<Statement> body)
  500. : IterationStatement(source_range)
  501. , m_test(move(test))
  502. , m_body(move(body))
  503. {
  504. }
  505. Expression const& test() const { return *m_test; }
  506. Statement const& body() const { return *m_body; }
  507. virtual Value execute(Interpreter&, GlobalObject&) const override;
  508. virtual void dump(int indent) const override;
  509. virtual void generate_bytecode(Bytecode::Generator&) const override;
  510. private:
  511. NonnullRefPtr<Expression> m_test;
  512. NonnullRefPtr<Statement> m_body;
  513. };
  514. class DoWhileStatement final : public IterationStatement {
  515. public:
  516. DoWhileStatement(SourceRange source_range, NonnullRefPtr<Expression> test, NonnullRefPtr<Statement> body)
  517. : IterationStatement(source_range)
  518. , m_test(move(test))
  519. , m_body(move(body))
  520. {
  521. }
  522. Expression const& test() const { return *m_test; }
  523. Statement const& body() const { return *m_body; }
  524. virtual Value execute(Interpreter&, GlobalObject&) const override;
  525. virtual void dump(int indent) const override;
  526. virtual void generate_bytecode(Bytecode::Generator&) const override;
  527. private:
  528. NonnullRefPtr<Expression> m_test;
  529. NonnullRefPtr<Statement> m_body;
  530. };
  531. class WithStatement final : public Statement {
  532. public:
  533. WithStatement(SourceRange source_range, NonnullRefPtr<Expression> object, NonnullRefPtr<Statement> body)
  534. : Statement(source_range)
  535. , m_object(move(object))
  536. , m_body(move(body))
  537. {
  538. }
  539. Expression const& object() const { return *m_object; }
  540. Statement const& body() const { return *m_body; }
  541. virtual Value execute(Interpreter&, GlobalObject&) const override;
  542. virtual void dump(int indent) const override;
  543. private:
  544. NonnullRefPtr<Expression> m_object;
  545. NonnullRefPtr<Statement> m_body;
  546. };
  547. class ForStatement final : public IterationStatement {
  548. public:
  549. ForStatement(SourceRange source_range, RefPtr<ASTNode> init, RefPtr<Expression> test, RefPtr<Expression> update, NonnullRefPtr<Statement> body)
  550. : IterationStatement(source_range)
  551. , m_init(move(init))
  552. , m_test(move(test))
  553. , m_update(move(update))
  554. , m_body(move(body))
  555. {
  556. }
  557. ASTNode const* init() const { return m_init; }
  558. Expression const* test() const { return m_test; }
  559. Expression const* update() const { return m_update; }
  560. Statement const& body() const { return *m_body; }
  561. virtual Value execute(Interpreter&, GlobalObject&) const override;
  562. virtual void dump(int indent) const override;
  563. virtual void generate_bytecode(Bytecode::Generator&) const override;
  564. private:
  565. RefPtr<ASTNode> m_init;
  566. RefPtr<Expression> m_test;
  567. RefPtr<Expression> m_update;
  568. NonnullRefPtr<Statement> m_body;
  569. };
  570. class ForInStatement final : public IterationStatement {
  571. public:
  572. ForInStatement(SourceRange source_range, Variant<NonnullRefPtr<ASTNode>, NonnullRefPtr<BindingPattern>> lhs, NonnullRefPtr<Expression> rhs, NonnullRefPtr<Statement> body)
  573. : IterationStatement(source_range)
  574. , m_lhs(move(lhs))
  575. , m_rhs(move(rhs))
  576. , m_body(move(body))
  577. {
  578. }
  579. auto const& lhs() const { return m_lhs; }
  580. Expression const& rhs() const { return *m_rhs; }
  581. Statement const& body() const { return *m_body; }
  582. virtual Value execute(Interpreter&, GlobalObject&) const override;
  583. virtual void dump(int indent) const override;
  584. private:
  585. Variant<NonnullRefPtr<ASTNode>, NonnullRefPtr<BindingPattern>> m_lhs;
  586. NonnullRefPtr<Expression> m_rhs;
  587. NonnullRefPtr<Statement> m_body;
  588. };
  589. class ForOfStatement final : public IterationStatement {
  590. public:
  591. ForOfStatement(SourceRange source_range, Variant<NonnullRefPtr<ASTNode>, NonnullRefPtr<BindingPattern>> lhs, NonnullRefPtr<Expression> rhs, NonnullRefPtr<Statement> body)
  592. : IterationStatement(source_range)
  593. , m_lhs(move(lhs))
  594. , m_rhs(move(rhs))
  595. , m_body(move(body))
  596. {
  597. }
  598. auto const& lhs() const { return m_lhs; }
  599. Expression const& rhs() const { return *m_rhs; }
  600. Statement const& body() const { return *m_body; }
  601. virtual Value execute(Interpreter&, GlobalObject&) const override;
  602. virtual void dump(int indent) const override;
  603. private:
  604. Variant<NonnullRefPtr<ASTNode>, NonnullRefPtr<BindingPattern>> m_lhs;
  605. NonnullRefPtr<Expression> m_rhs;
  606. NonnullRefPtr<Statement> m_body;
  607. };
  608. class ForAwaitOfStatement final : public IterationStatement {
  609. public:
  610. ForAwaitOfStatement(SourceRange source_range, Variant<NonnullRefPtr<ASTNode>, NonnullRefPtr<BindingPattern>> lhs, NonnullRefPtr<Expression> rhs, NonnullRefPtr<Statement> body)
  611. : IterationStatement(source_range)
  612. , m_lhs(move(lhs))
  613. , m_rhs(move(rhs))
  614. , m_body(move(body))
  615. {
  616. }
  617. virtual Value execute(Interpreter&, GlobalObject&) const override;
  618. virtual void dump(int indent) const override;
  619. private:
  620. Variant<NonnullRefPtr<ASTNode>, NonnullRefPtr<BindingPattern>> m_lhs;
  621. NonnullRefPtr<Expression> m_rhs;
  622. NonnullRefPtr<Statement> m_body;
  623. };
  624. enum class BinaryOp {
  625. Addition,
  626. Subtraction,
  627. Multiplication,
  628. Division,
  629. Modulo,
  630. Exponentiation,
  631. StrictlyEquals,
  632. StrictlyInequals,
  633. LooselyEquals,
  634. LooselyInequals,
  635. GreaterThan,
  636. GreaterThanEquals,
  637. LessThan,
  638. LessThanEquals,
  639. BitwiseAnd,
  640. BitwiseOr,
  641. BitwiseXor,
  642. LeftShift,
  643. RightShift,
  644. UnsignedRightShift,
  645. In,
  646. InstanceOf,
  647. };
  648. class BinaryExpression final : public Expression {
  649. public:
  650. BinaryExpression(SourceRange source_range, BinaryOp op, NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs)
  651. : Expression(source_range)
  652. , m_op(op)
  653. , m_lhs(move(lhs))
  654. , m_rhs(move(rhs))
  655. {
  656. }
  657. virtual Value execute(Interpreter&, GlobalObject&) const override;
  658. virtual void dump(int indent) const override;
  659. virtual void generate_bytecode(Bytecode::Generator&) const override;
  660. private:
  661. BinaryOp m_op;
  662. NonnullRefPtr<Expression> m_lhs;
  663. NonnullRefPtr<Expression> m_rhs;
  664. };
  665. enum class LogicalOp {
  666. And,
  667. Or,
  668. NullishCoalescing,
  669. };
  670. class LogicalExpression final : public Expression {
  671. public:
  672. LogicalExpression(SourceRange source_range, LogicalOp op, NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs)
  673. : Expression(source_range)
  674. , m_op(op)
  675. , m_lhs(move(lhs))
  676. , m_rhs(move(rhs))
  677. {
  678. }
  679. virtual Value execute(Interpreter&, GlobalObject&) const override;
  680. virtual void dump(int indent) const override;
  681. virtual void generate_bytecode(Bytecode::Generator&) const override;
  682. private:
  683. LogicalOp m_op;
  684. NonnullRefPtr<Expression> m_lhs;
  685. NonnullRefPtr<Expression> m_rhs;
  686. };
  687. enum class UnaryOp {
  688. BitwiseNot,
  689. Not,
  690. Plus,
  691. Minus,
  692. Typeof,
  693. Void,
  694. Delete,
  695. };
  696. class UnaryExpression final : public Expression {
  697. public:
  698. UnaryExpression(SourceRange source_range, UnaryOp op, NonnullRefPtr<Expression> lhs)
  699. : Expression(source_range)
  700. , m_op(op)
  701. , m_lhs(move(lhs))
  702. {
  703. }
  704. virtual Value execute(Interpreter&, GlobalObject&) const override;
  705. virtual void dump(int indent) const override;
  706. virtual void generate_bytecode(Bytecode::Generator&) const override;
  707. private:
  708. UnaryOp m_op;
  709. NonnullRefPtr<Expression> m_lhs;
  710. };
  711. class SequenceExpression final : public Expression {
  712. public:
  713. SequenceExpression(SourceRange source_range, NonnullRefPtrVector<Expression> expressions)
  714. : Expression(source_range)
  715. , m_expressions(move(expressions))
  716. {
  717. VERIFY(m_expressions.size() >= 2);
  718. }
  719. virtual void dump(int indent) const override;
  720. virtual Value execute(Interpreter&, GlobalObject&) const override;
  721. virtual void generate_bytecode(Bytecode::Generator&) const override;
  722. private:
  723. NonnullRefPtrVector<Expression> m_expressions;
  724. };
  725. class Literal : public Expression {
  726. protected:
  727. explicit Literal(SourceRange source_range)
  728. : Expression(source_range)
  729. {
  730. }
  731. };
  732. class BooleanLiteral final : public Literal {
  733. public:
  734. explicit BooleanLiteral(SourceRange source_range, bool value)
  735. : Literal(source_range)
  736. , m_value(value)
  737. {
  738. }
  739. virtual Value execute(Interpreter&, GlobalObject&) const override;
  740. virtual void dump(int indent) const override;
  741. virtual void generate_bytecode(Bytecode::Generator&) const override;
  742. private:
  743. bool m_value { false };
  744. };
  745. class NumericLiteral final : public Literal {
  746. public:
  747. explicit NumericLiteral(SourceRange source_range, double value)
  748. : Literal(source_range)
  749. , m_value(value)
  750. {
  751. }
  752. virtual Value execute(Interpreter&, GlobalObject&) const override;
  753. virtual void dump(int indent) const override;
  754. virtual void generate_bytecode(Bytecode::Generator&) const override;
  755. private:
  756. Value m_value;
  757. };
  758. class BigIntLiteral final : public Literal {
  759. public:
  760. explicit BigIntLiteral(SourceRange source_range, String value)
  761. : Literal(source_range)
  762. , m_value(move(value))
  763. {
  764. }
  765. virtual Value execute(Interpreter&, GlobalObject&) const override;
  766. virtual void dump(int indent) const override;
  767. virtual void generate_bytecode(Bytecode::Generator&) const override;
  768. private:
  769. String m_value;
  770. };
  771. class StringLiteral final : public Literal {
  772. public:
  773. explicit StringLiteral(SourceRange source_range, String value, bool is_use_strict_directive = false)
  774. : Literal(source_range)
  775. , m_value(move(value))
  776. , m_is_use_strict_directive(is_use_strict_directive)
  777. {
  778. }
  779. virtual Value execute(Interpreter&, GlobalObject&) const override;
  780. virtual void dump(int indent) const override;
  781. virtual void generate_bytecode(Bytecode::Generator&) const override;
  782. StringView value() const { return m_value; }
  783. bool is_use_strict_directive() const { return m_is_use_strict_directive; };
  784. private:
  785. String m_value;
  786. bool m_is_use_strict_directive;
  787. };
  788. class NullLiteral final : public Literal {
  789. public:
  790. explicit NullLiteral(SourceRange source_range)
  791. : Literal(source_range)
  792. {
  793. }
  794. virtual Value execute(Interpreter&, GlobalObject&) const override;
  795. virtual void dump(int indent) const override;
  796. virtual void generate_bytecode(Bytecode::Generator&) const override;
  797. };
  798. class RegExpLiteral final : public Literal {
  799. public:
  800. RegExpLiteral(SourceRange source_range, regex::Parser::Result parsed_regex, String parsed_pattern, regex::RegexOptions<ECMAScriptFlags> parsed_flags, String pattern, String flags)
  801. : Literal(source_range)
  802. , m_parsed_regex(move(parsed_regex))
  803. , m_parsed_pattern(move(parsed_pattern))
  804. , m_parsed_flags(move(parsed_flags))
  805. , m_pattern(move(pattern))
  806. , m_flags(move(flags))
  807. {
  808. }
  809. virtual Value execute(Interpreter&, GlobalObject&) const override;
  810. virtual void dump(int indent) const override;
  811. virtual void generate_bytecode(Bytecode::Generator&) const override;
  812. regex::Parser::Result const& parsed_regex() const { return m_parsed_regex; }
  813. String const& parsed_pattern() const { return m_parsed_pattern; }
  814. regex::RegexOptions<ECMAScriptFlags> const& parsed_flags() const { return m_parsed_flags; }
  815. String const& pattern() const { return m_pattern; }
  816. String const& flags() const { return m_flags; }
  817. private:
  818. regex::Parser::Result m_parsed_regex;
  819. String m_parsed_pattern;
  820. regex::RegexOptions<ECMAScriptFlags> m_parsed_flags;
  821. String m_pattern;
  822. String m_flags;
  823. };
  824. class Identifier final : public Expression {
  825. public:
  826. explicit Identifier(SourceRange source_range, FlyString string)
  827. : Expression(source_range)
  828. , m_string(move(string))
  829. {
  830. }
  831. FlyString const& string() const { return m_string; }
  832. void set_lexically_bound_function_argument_index(size_t index) { m_lexically_bound_function_argument = index; }
  833. virtual Value execute(Interpreter&, GlobalObject&) const override;
  834. virtual void dump(int indent) const override;
  835. virtual Reference to_reference(Interpreter&, GlobalObject&) const override;
  836. virtual void generate_bytecode(Bytecode::Generator&) const override;
  837. private:
  838. virtual bool is_identifier() const override { return true; }
  839. FlyString m_string;
  840. Optional<size_t> m_lexically_bound_function_argument;
  841. mutable Optional<EnvironmentCoordinate> m_cached_environment_coordinate;
  842. };
  843. class PrivateIdentifier final : public Expression {
  844. public:
  845. explicit PrivateIdentifier(SourceRange source_range, FlyString string)
  846. : Expression(source_range)
  847. , m_string(move(string))
  848. {
  849. }
  850. FlyString const& string() const { return m_string; }
  851. virtual Value execute(Interpreter&, GlobalObject&) const override;
  852. virtual void dump(int indent) const override;
  853. private:
  854. FlyString m_string;
  855. };
  856. class ClassElement : public ASTNode {
  857. public:
  858. ClassElement(SourceRange source_range, bool is_static)
  859. : ASTNode(source_range)
  860. , m_is_static(is_static)
  861. {
  862. }
  863. virtual Value execute(Interpreter&, GlobalObject&) const override;
  864. enum class ElementKind {
  865. Method,
  866. Field,
  867. StaticInitializer,
  868. };
  869. virtual ElementKind class_element_kind() const = 0;
  870. bool is_static() const { return m_is_static; }
  871. using ClassElementName = Variant<PropertyKey, PrivateName>;
  872. struct ClassFieldDefinition {
  873. ClassElementName name;
  874. ECMAScriptFunctionObject* initializer { nullptr };
  875. };
  876. // We use the Completion also as a ClassStaticBlockDefinition Record.
  877. using ClassValue = Variant<ClassFieldDefinition, Completion, PrivateElement>;
  878. virtual ThrowCompletionOr<ClassValue> class_element_evaluation(Interpreter&, GlobalObject&, Object& home_object) const = 0;
  879. virtual Optional<FlyString> private_bound_identifier() const { return {}; };
  880. private:
  881. bool m_is_static { false };
  882. };
  883. class ClassMethod final : public ClassElement {
  884. public:
  885. enum class Kind {
  886. Method,
  887. Getter,
  888. Setter,
  889. };
  890. ClassMethod(SourceRange source_range, NonnullRefPtr<Expression> key, NonnullRefPtr<FunctionExpression> function, Kind kind, bool is_static)
  891. : ClassElement(source_range, is_static)
  892. , m_key(move(key))
  893. , m_function(move(function))
  894. , m_kind(kind)
  895. {
  896. }
  897. Expression const& key() const { return *m_key; }
  898. Kind kind() const { return m_kind; }
  899. virtual ElementKind class_element_kind() const override { return ElementKind::Method; }
  900. virtual void dump(int indent) const override;
  901. virtual ThrowCompletionOr<ClassValue> class_element_evaluation(Interpreter&, GlobalObject&, Object& home_object) const override;
  902. virtual Optional<FlyString> private_bound_identifier() const override;
  903. private:
  904. NonnullRefPtr<Expression> m_key;
  905. NonnullRefPtr<FunctionExpression> m_function;
  906. Kind m_kind;
  907. };
  908. class ClassField final : public ClassElement {
  909. public:
  910. ClassField(SourceRange source_range, NonnullRefPtr<Expression> key, RefPtr<Expression> init, bool contains_direct_call_to_eval, bool is_static)
  911. : ClassElement(source_range, is_static)
  912. , m_key(move(key))
  913. , m_initializer(move(init))
  914. , m_contains_direct_call_to_eval(contains_direct_call_to_eval)
  915. {
  916. }
  917. Expression const& key() const { return *m_key; }
  918. RefPtr<Expression> const& initializer() const { return m_initializer; }
  919. RefPtr<Expression>& initializer() { return m_initializer; }
  920. virtual ElementKind class_element_kind() const override { return ElementKind::Field; }
  921. virtual void dump(int indent) const override;
  922. virtual ThrowCompletionOr<ClassValue> class_element_evaluation(Interpreter& interpreter, GlobalObject& object, Object& home_object) const override;
  923. virtual Optional<FlyString> private_bound_identifier() const override;
  924. private:
  925. NonnullRefPtr<Expression> m_key;
  926. RefPtr<Expression> m_initializer;
  927. bool m_contains_direct_call_to_eval { false };
  928. };
  929. class StaticInitializer final : public ClassElement {
  930. public:
  931. StaticInitializer(SourceRange source_range, NonnullRefPtr<FunctionBody> function_body, bool contains_direct_call_to_eval)
  932. : ClassElement(source_range, true)
  933. , m_function_body(move(function_body))
  934. , m_contains_direct_call_to_eval(contains_direct_call_to_eval)
  935. {
  936. }
  937. virtual ElementKind class_element_kind() const override { return ElementKind::StaticInitializer; }
  938. virtual ThrowCompletionOr<ClassValue> class_element_evaluation(Interpreter&, GlobalObject&, Object& home_object) const override;
  939. virtual void dump(int indent) const override;
  940. private:
  941. NonnullRefPtr<FunctionBody> m_function_body;
  942. bool m_contains_direct_call_to_eval { false };
  943. };
  944. class SuperExpression final : public Expression {
  945. public:
  946. explicit SuperExpression(SourceRange source_range)
  947. : Expression(source_range)
  948. {
  949. }
  950. virtual Value execute(Interpreter&, GlobalObject&) const override;
  951. virtual void dump(int indent) const override;
  952. virtual bool is_super_expression() const override { return true; }
  953. };
  954. class ClassExpression final : public Expression {
  955. public:
  956. ClassExpression(SourceRange source_range, String name, RefPtr<FunctionExpression> constructor, RefPtr<Expression> super_class, NonnullRefPtrVector<ClassElement> elements)
  957. : Expression(source_range)
  958. , m_name(move(name))
  959. , m_constructor(move(constructor))
  960. , m_super_class(move(super_class))
  961. , m_elements(move(elements))
  962. {
  963. }
  964. StringView name() const { return m_name; }
  965. RefPtr<FunctionExpression> constructor() const { return m_constructor; }
  966. virtual Value execute(Interpreter&, GlobalObject&) const override;
  967. virtual void dump(int indent) const override;
  968. bool has_name() const { return !m_name.is_empty(); }
  969. ThrowCompletionOr<Value> class_definition_evaluation(Interpreter& interpreter, GlobalObject& global_object, FlyString const& binding_name = {}, FlyString const& class_name = {}) const;
  970. private:
  971. virtual bool is_class_expression() const override { return true; }
  972. String m_name;
  973. RefPtr<FunctionExpression> m_constructor;
  974. RefPtr<Expression> m_super_class;
  975. NonnullRefPtrVector<ClassElement> m_elements;
  976. };
  977. class ClassDeclaration final : public Declaration {
  978. public:
  979. ClassDeclaration(SourceRange source_range, NonnullRefPtr<ClassExpression> class_expression)
  980. : Declaration(source_range)
  981. , m_class_expression(move(class_expression))
  982. {
  983. }
  984. virtual Value execute(Interpreter&, GlobalObject&) const override;
  985. virtual void dump(int indent) const override;
  986. virtual void generate_bytecode(Bytecode::Generator&) const override;
  987. void for_each_bound_name(IteratorOrVoidFunction<FlyString const&> callback) const override;
  988. virtual bool is_lexical_declaration() const override { return true; }
  989. StringView name() const { return m_class_expression->name(); }
  990. private:
  991. NonnullRefPtr<ClassExpression> m_class_expression;
  992. };
  993. class SpreadExpression final : public Expression {
  994. public:
  995. explicit SpreadExpression(SourceRange source_range, NonnullRefPtr<Expression> target)
  996. : Expression(source_range)
  997. , m_target(move(target))
  998. {
  999. }
  1000. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1001. virtual void dump(int indent) const override;
  1002. private:
  1003. NonnullRefPtr<Expression> m_target;
  1004. };
  1005. class ThisExpression final : public Expression {
  1006. public:
  1007. explicit ThisExpression(SourceRange source_range)
  1008. : Expression(source_range)
  1009. {
  1010. }
  1011. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1012. virtual void dump(int indent) const override;
  1013. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1014. };
  1015. class CallExpression : public Expression {
  1016. public:
  1017. struct Argument {
  1018. NonnullRefPtr<Expression> value;
  1019. bool is_spread;
  1020. };
  1021. CallExpression(SourceRange source_range, NonnullRefPtr<Expression> callee, Vector<Argument> arguments = {})
  1022. : Expression(source_range)
  1023. , m_callee(move(callee))
  1024. , m_arguments(move(arguments))
  1025. {
  1026. }
  1027. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1028. virtual void dump(int indent) const override;
  1029. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1030. Expression const& callee() const { return m_callee; }
  1031. protected:
  1032. void throw_type_error_for_callee(Interpreter&, GlobalObject&, Value callee_value, StringView call_type) const;
  1033. NonnullRefPtr<Expression> m_callee;
  1034. Vector<Argument> const m_arguments;
  1035. private:
  1036. struct ThisAndCallee {
  1037. Value this_value;
  1038. Value callee;
  1039. };
  1040. ThisAndCallee compute_this_and_callee(Interpreter&, GlobalObject&, Reference const&) const;
  1041. };
  1042. class NewExpression final : public CallExpression {
  1043. public:
  1044. NewExpression(SourceRange source_range, NonnullRefPtr<Expression> callee, Vector<Argument> arguments = {})
  1045. : CallExpression(source_range, move(callee), move(arguments))
  1046. {
  1047. }
  1048. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1049. virtual bool is_new_expression() const override { return true; }
  1050. };
  1051. class SuperCall final : public Expression {
  1052. public:
  1053. SuperCall(SourceRange source_range, Vector<CallExpression::Argument> arguments)
  1054. : Expression(source_range)
  1055. , m_arguments(move(arguments))
  1056. {
  1057. }
  1058. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1059. virtual void dump(int indent) const override;
  1060. private:
  1061. Vector<CallExpression::Argument> const m_arguments;
  1062. };
  1063. enum class AssignmentOp {
  1064. Assignment,
  1065. AdditionAssignment,
  1066. SubtractionAssignment,
  1067. MultiplicationAssignment,
  1068. DivisionAssignment,
  1069. ModuloAssignment,
  1070. ExponentiationAssignment,
  1071. BitwiseAndAssignment,
  1072. BitwiseOrAssignment,
  1073. BitwiseXorAssignment,
  1074. LeftShiftAssignment,
  1075. RightShiftAssignment,
  1076. UnsignedRightShiftAssignment,
  1077. AndAssignment,
  1078. OrAssignment,
  1079. NullishAssignment,
  1080. };
  1081. class AssignmentExpression final : public Expression {
  1082. public:
  1083. AssignmentExpression(SourceRange source_range, AssignmentOp op, NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs)
  1084. : Expression(source_range)
  1085. , m_op(op)
  1086. , m_lhs(move(lhs))
  1087. , m_rhs(move(rhs))
  1088. {
  1089. }
  1090. AssignmentExpression(SourceRange source_range, AssignmentOp op, NonnullRefPtr<BindingPattern> lhs, NonnullRefPtr<Expression> rhs)
  1091. : Expression(source_range)
  1092. , m_op(op)
  1093. , m_lhs(move(lhs))
  1094. , m_rhs(move(rhs))
  1095. {
  1096. }
  1097. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1098. virtual void dump(int indent) const override;
  1099. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1100. private:
  1101. AssignmentOp m_op;
  1102. Variant<NonnullRefPtr<Expression>, NonnullRefPtr<BindingPattern>> m_lhs;
  1103. NonnullRefPtr<Expression> m_rhs;
  1104. };
  1105. enum class UpdateOp {
  1106. Increment,
  1107. Decrement,
  1108. };
  1109. class UpdateExpression final : public Expression {
  1110. public:
  1111. UpdateExpression(SourceRange source_range, UpdateOp op, NonnullRefPtr<Expression> argument, bool prefixed = false)
  1112. : Expression(source_range)
  1113. , m_op(op)
  1114. , m_argument(move(argument))
  1115. , m_prefixed(prefixed)
  1116. {
  1117. }
  1118. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1119. virtual void dump(int indent) const override;
  1120. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1121. private:
  1122. UpdateOp m_op;
  1123. NonnullRefPtr<Expression> m_argument;
  1124. bool m_prefixed;
  1125. };
  1126. enum class DeclarationKind {
  1127. Var,
  1128. Let,
  1129. Const,
  1130. };
  1131. class VariableDeclarator final : public ASTNode {
  1132. public:
  1133. VariableDeclarator(SourceRange source_range, NonnullRefPtr<Identifier> id)
  1134. : ASTNode(source_range)
  1135. , m_target(move(id))
  1136. {
  1137. }
  1138. VariableDeclarator(SourceRange source_range, NonnullRefPtr<Identifier> target, RefPtr<Expression> init)
  1139. : ASTNode(source_range)
  1140. , m_target(move(target))
  1141. , m_init(move(init))
  1142. {
  1143. }
  1144. VariableDeclarator(SourceRange source_range, Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>> target, RefPtr<Expression> init)
  1145. : ASTNode(source_range)
  1146. , m_target(move(target))
  1147. , m_init(move(init))
  1148. {
  1149. }
  1150. auto& target() const { return m_target; }
  1151. Expression const* init() const { return m_init; }
  1152. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1153. virtual void dump(int indent) const override;
  1154. private:
  1155. Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>> m_target;
  1156. RefPtr<Expression> m_init;
  1157. };
  1158. class VariableDeclaration final : public Declaration {
  1159. public:
  1160. VariableDeclaration(SourceRange source_range, DeclarationKind declaration_kind, NonnullRefPtrVector<VariableDeclarator> declarations)
  1161. : Declaration(source_range)
  1162. , m_declaration_kind(declaration_kind)
  1163. , m_declarations(move(declarations))
  1164. {
  1165. }
  1166. DeclarationKind declaration_kind() const { return m_declaration_kind; }
  1167. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1168. virtual void dump(int indent) const override;
  1169. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1170. NonnullRefPtrVector<VariableDeclarator> const& declarations() const { return m_declarations; }
  1171. virtual void for_each_bound_name(IteratorOrVoidFunction<FlyString const&> callback) const override;
  1172. virtual bool is_constant_declaration() const override { return m_declaration_kind == DeclarationKind::Const; };
  1173. virtual bool is_lexical_declaration() const override { return m_declaration_kind != DeclarationKind::Var; }
  1174. private:
  1175. DeclarationKind m_declaration_kind;
  1176. NonnullRefPtrVector<VariableDeclarator> m_declarations;
  1177. };
  1178. class ObjectProperty final : public ASTNode {
  1179. public:
  1180. enum class Type {
  1181. KeyValue,
  1182. Getter,
  1183. Setter,
  1184. Spread,
  1185. };
  1186. ObjectProperty(SourceRange source_range, NonnullRefPtr<Expression> key, RefPtr<Expression> value, Type property_type, bool is_method)
  1187. : ASTNode(source_range)
  1188. , m_key(move(key))
  1189. , m_value(move(value))
  1190. , m_property_type(property_type)
  1191. , m_is_method(is_method)
  1192. {
  1193. }
  1194. Expression const& key() const { return m_key; }
  1195. Expression const& value() const
  1196. {
  1197. VERIFY(m_value);
  1198. return *m_value;
  1199. }
  1200. Type type() const { return m_property_type; }
  1201. bool is_method() const { return m_is_method; }
  1202. virtual void dump(int indent) const override;
  1203. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1204. private:
  1205. NonnullRefPtr<Expression> m_key;
  1206. RefPtr<Expression> m_value;
  1207. Type m_property_type;
  1208. bool m_is_method { false };
  1209. };
  1210. class ObjectExpression final : public Expression {
  1211. public:
  1212. explicit ObjectExpression(SourceRange source_range, NonnullRefPtrVector<ObjectProperty> properties = {}, Optional<SourceRange> first_invalid_property_range = {})
  1213. : Expression(source_range)
  1214. , m_properties(move(properties))
  1215. , m_first_invalid_property_range(move(first_invalid_property_range))
  1216. {
  1217. }
  1218. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1219. virtual void dump(int indent) const override;
  1220. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1221. Optional<SourceRange> const& invalid_property_range() const { return m_first_invalid_property_range; }
  1222. private:
  1223. NonnullRefPtrVector<ObjectProperty> m_properties;
  1224. Optional<SourceRange> m_first_invalid_property_range;
  1225. };
  1226. class ArrayExpression final : public Expression {
  1227. public:
  1228. ArrayExpression(SourceRange source_range, Vector<RefPtr<Expression>> elements)
  1229. : Expression(source_range)
  1230. , m_elements(move(elements))
  1231. {
  1232. }
  1233. Vector<RefPtr<Expression>> const& elements() const { return m_elements; }
  1234. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1235. virtual void dump(int indent) const override;
  1236. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1237. private:
  1238. Vector<RefPtr<Expression>> m_elements;
  1239. };
  1240. class TemplateLiteral final : public Expression {
  1241. public:
  1242. TemplateLiteral(SourceRange source_range, NonnullRefPtrVector<Expression> expressions)
  1243. : Expression(source_range)
  1244. , m_expressions(move(expressions))
  1245. {
  1246. }
  1247. TemplateLiteral(SourceRange source_range, NonnullRefPtrVector<Expression> expressions, NonnullRefPtrVector<Expression> raw_strings)
  1248. : Expression(source_range)
  1249. , m_expressions(move(expressions))
  1250. , m_raw_strings(move(raw_strings))
  1251. {
  1252. }
  1253. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1254. virtual void dump(int indent) const override;
  1255. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1256. NonnullRefPtrVector<Expression> const& expressions() const { return m_expressions; }
  1257. NonnullRefPtrVector<Expression> const& raw_strings() const { return m_raw_strings; }
  1258. private:
  1259. NonnullRefPtrVector<Expression> const m_expressions;
  1260. NonnullRefPtrVector<Expression> const m_raw_strings;
  1261. };
  1262. class TaggedTemplateLiteral final : public Expression {
  1263. public:
  1264. TaggedTemplateLiteral(SourceRange source_range, NonnullRefPtr<Expression> tag, NonnullRefPtr<TemplateLiteral> template_literal)
  1265. : Expression(source_range)
  1266. , m_tag(move(tag))
  1267. , m_template_literal(move(template_literal))
  1268. {
  1269. }
  1270. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1271. virtual void dump(int indent) const override;
  1272. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1273. private:
  1274. NonnullRefPtr<Expression> const m_tag;
  1275. NonnullRefPtr<TemplateLiteral> const m_template_literal;
  1276. };
  1277. class MemberExpression final : public Expression {
  1278. public:
  1279. MemberExpression(SourceRange source_range, NonnullRefPtr<Expression> object, NonnullRefPtr<Expression> property, bool computed = false)
  1280. : Expression(source_range)
  1281. , m_object(move(object))
  1282. , m_property(move(property))
  1283. , m_computed(computed)
  1284. {
  1285. }
  1286. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1287. virtual void dump(int indent) const override;
  1288. virtual Reference to_reference(Interpreter&, GlobalObject&) const override;
  1289. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1290. bool is_computed() const { return m_computed; }
  1291. Expression const& object() const { return *m_object; }
  1292. Expression const& property() const { return *m_property; }
  1293. PropertyKey computed_property_name(Interpreter&, GlobalObject&) const;
  1294. String to_string_approximation() const;
  1295. bool ends_in_private_name() const;
  1296. private:
  1297. virtual bool is_member_expression() const override { return true; }
  1298. NonnullRefPtr<Expression> m_object;
  1299. NonnullRefPtr<Expression> m_property;
  1300. bool m_computed { false };
  1301. };
  1302. class OptionalChain final : public Expression {
  1303. public:
  1304. enum class Mode {
  1305. Optional,
  1306. NotOptional,
  1307. };
  1308. struct Call {
  1309. Vector<CallExpression::Argument> arguments;
  1310. Mode mode;
  1311. };
  1312. struct ComputedReference {
  1313. NonnullRefPtr<Expression> expression;
  1314. Mode mode;
  1315. };
  1316. struct MemberReference {
  1317. NonnullRefPtr<Identifier> identifier;
  1318. Mode mode;
  1319. };
  1320. struct PrivateMemberReference {
  1321. NonnullRefPtr<PrivateIdentifier> private_identifier;
  1322. Mode mode;
  1323. };
  1324. using Reference = Variant<Call, ComputedReference, MemberReference, PrivateMemberReference>;
  1325. OptionalChain(SourceRange source_range, NonnullRefPtr<Expression> base, Vector<Reference> references)
  1326. : Expression(source_range)
  1327. , m_base(move(base))
  1328. , m_references(move(references))
  1329. {
  1330. }
  1331. virtual Value execute(Interpreter& interpreter, GlobalObject& global_object) const override;
  1332. virtual JS::Reference to_reference(Interpreter& interpreter, GlobalObject& global_object) const override;
  1333. virtual void dump(int indent) const override;
  1334. private:
  1335. struct ReferenceAndValue {
  1336. JS::Reference reference;
  1337. Value value;
  1338. };
  1339. Optional<ReferenceAndValue> to_reference_and_value(Interpreter&, GlobalObject&) const;
  1340. NonnullRefPtr<Expression> m_base;
  1341. Vector<Reference> m_references;
  1342. };
  1343. class MetaProperty final : public Expression {
  1344. public:
  1345. enum class Type {
  1346. NewTarget,
  1347. ImportMeta,
  1348. };
  1349. MetaProperty(SourceRange source_range, Type type)
  1350. : Expression(source_range)
  1351. , m_type(type)
  1352. {
  1353. }
  1354. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1355. virtual void dump(int indent) const override;
  1356. private:
  1357. Type m_type;
  1358. };
  1359. class ImportCall final : public Expression {
  1360. public:
  1361. ImportCall(SourceRange source_range, NonnullRefPtr<Expression> specifier, RefPtr<Expression> options)
  1362. : Expression(source_range)
  1363. , m_specifier(move(specifier))
  1364. , m_options(move(options))
  1365. {
  1366. }
  1367. virtual void dump(int indent) const override;
  1368. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1369. private:
  1370. NonnullRefPtr<Expression> m_specifier;
  1371. RefPtr<Expression> m_options;
  1372. };
  1373. class ConditionalExpression final : public Expression {
  1374. public:
  1375. ConditionalExpression(SourceRange source_range, NonnullRefPtr<Expression> test, NonnullRefPtr<Expression> consequent, NonnullRefPtr<Expression> alternate)
  1376. : Expression(source_range)
  1377. , m_test(move(test))
  1378. , m_consequent(move(consequent))
  1379. , m_alternate(move(alternate))
  1380. {
  1381. }
  1382. virtual void dump(int indent) const override;
  1383. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1384. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1385. private:
  1386. NonnullRefPtr<Expression> m_test;
  1387. NonnullRefPtr<Expression> m_consequent;
  1388. NonnullRefPtr<Expression> m_alternate;
  1389. };
  1390. class CatchClause final : public ASTNode {
  1391. public:
  1392. CatchClause(SourceRange source_range, FlyString parameter, NonnullRefPtr<BlockStatement> body)
  1393. : ASTNode(source_range)
  1394. , m_parameter(move(parameter))
  1395. , m_body(move(body))
  1396. {
  1397. }
  1398. CatchClause(SourceRange source_range, NonnullRefPtr<BindingPattern> parameter, NonnullRefPtr<BlockStatement> body)
  1399. : ASTNode(source_range)
  1400. , m_parameter(move(parameter))
  1401. , m_body(move(body))
  1402. {
  1403. }
  1404. auto& parameter() const { return m_parameter; }
  1405. BlockStatement const& body() const { return m_body; }
  1406. virtual void dump(int indent) const override;
  1407. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1408. private:
  1409. Variant<FlyString, NonnullRefPtr<BindingPattern>> m_parameter;
  1410. NonnullRefPtr<BlockStatement> m_body;
  1411. };
  1412. class TryStatement final : public LabelableStatement {
  1413. public:
  1414. TryStatement(SourceRange source_range, NonnullRefPtr<BlockStatement> block, RefPtr<CatchClause> handler, RefPtr<BlockStatement> finalizer)
  1415. : LabelableStatement(source_range)
  1416. , m_block(move(block))
  1417. , m_handler(move(handler))
  1418. , m_finalizer(move(finalizer))
  1419. {
  1420. }
  1421. BlockStatement const& block() const { return m_block; }
  1422. CatchClause const* handler() const { return m_handler; }
  1423. BlockStatement const* finalizer() const { return m_finalizer; }
  1424. virtual void dump(int indent) const override;
  1425. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1426. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1427. void add_label(FlyString string) override;
  1428. private:
  1429. NonnullRefPtr<BlockStatement> m_block;
  1430. RefPtr<CatchClause> m_handler;
  1431. RefPtr<BlockStatement> m_finalizer;
  1432. };
  1433. class ThrowStatement final : public Statement {
  1434. public:
  1435. explicit ThrowStatement(SourceRange source_range, NonnullRefPtr<Expression> argument)
  1436. : Statement(source_range)
  1437. , m_argument(move(argument))
  1438. {
  1439. }
  1440. Expression const& argument() const { return m_argument; }
  1441. virtual void dump(int indent) const override;
  1442. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1443. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1444. private:
  1445. NonnullRefPtr<Expression> m_argument;
  1446. };
  1447. class SwitchCase final : public ScopeNode {
  1448. public:
  1449. SwitchCase(SourceRange source_range, RefPtr<Expression> test)
  1450. : ScopeNode(source_range)
  1451. , m_test(move(test))
  1452. {
  1453. }
  1454. Expression const* test() const { return m_test; }
  1455. virtual void dump(int indent) const override;
  1456. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1457. private:
  1458. RefPtr<Expression> m_test;
  1459. };
  1460. class SwitchStatement final : public ScopeNode {
  1461. public:
  1462. SwitchStatement(SourceRange source_range, NonnullRefPtr<Expression> discriminant)
  1463. : ScopeNode(source_range)
  1464. , m_discriminant(move(discriminant))
  1465. {
  1466. }
  1467. virtual void dump(int indent) const override;
  1468. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1469. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1470. void add_case(NonnullRefPtr<SwitchCase> switch_case) { m_cases.append(move(switch_case)); }
  1471. private:
  1472. NonnullRefPtr<Expression> m_discriminant;
  1473. NonnullRefPtrVector<SwitchCase> m_cases;
  1474. };
  1475. class BreakStatement final : public Statement {
  1476. public:
  1477. BreakStatement(SourceRange source_range, FlyString target_label)
  1478. : Statement(source_range)
  1479. , m_target_label(move(target_label))
  1480. {
  1481. }
  1482. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1483. FlyString const& target_label() const { return m_target_label; }
  1484. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1485. private:
  1486. FlyString m_target_label;
  1487. };
  1488. class ContinueStatement final : public Statement {
  1489. public:
  1490. ContinueStatement(SourceRange source_range, FlyString target_label)
  1491. : Statement(source_range)
  1492. , m_target_label(move(target_label))
  1493. {
  1494. }
  1495. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1496. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1497. FlyString const& target_label() const { return m_target_label; }
  1498. private:
  1499. FlyString m_target_label;
  1500. };
  1501. class DebuggerStatement final : public Statement {
  1502. public:
  1503. explicit DebuggerStatement(SourceRange source_range)
  1504. : Statement(source_range)
  1505. {
  1506. }
  1507. virtual Value execute(Interpreter&, GlobalObject&) const override;
  1508. virtual void generate_bytecode(Bytecode::Generator&) const override;
  1509. };
  1510. class SyntheticReferenceExpression final : public Expression {
  1511. public:
  1512. explicit SyntheticReferenceExpression(SourceRange source_range, Reference reference, Value value)
  1513. : Expression(source_range)
  1514. , m_reference(move(reference))
  1515. , m_value(value)
  1516. {
  1517. }
  1518. virtual Value execute(Interpreter&, GlobalObject&) const override { return m_value; }
  1519. virtual Reference to_reference(Interpreter&, GlobalObject&) const override { return m_reference; }
  1520. private:
  1521. Reference m_reference;
  1522. Value m_value;
  1523. };
  1524. template<typename C>
  1525. void BindingPattern::for_each_bound_name(C&& callback) const
  1526. {
  1527. for (auto& entry : entries) {
  1528. auto& alias = entry.alias;
  1529. if (alias.has<NonnullRefPtr<Identifier>>()) {
  1530. callback(alias.get<NonnullRefPtr<Identifier>>()->string());
  1531. } else if (alias.has<NonnullRefPtr<BindingPattern>>()) {
  1532. alias.get<NonnullRefPtr<BindingPattern>>()->for_each_bound_name(forward<C>(callback));
  1533. } else {
  1534. auto& name = entry.name;
  1535. if (name.has<NonnullRefPtr<Identifier>>())
  1536. callback(name.get<NonnullRefPtr<Identifier>>()->string());
  1537. }
  1538. }
  1539. }
  1540. template<>
  1541. inline bool ASTNode::fast_is<NewExpression>() const { return is_new_expression(); }
  1542. template<>
  1543. inline bool ASTNode::fast_is<MemberExpression>() const { return is_member_expression(); }
  1544. template<>
  1545. inline bool ASTNode::fast_is<SuperExpression>() const { return is_super_expression(); }
  1546. template<>
  1547. inline bool ASTNode::fast_is<FunctionExpression>() const { return is_function_expression(); }
  1548. template<>
  1549. inline bool ASTNode::fast_is<ClassExpression>() const { return is_class_expression(); }
  1550. template<>
  1551. inline bool ASTNode::fast_is<Identifier>() const { return is_identifier(); }
  1552. template<>
  1553. inline bool ASTNode::fast_is<ExpressionStatement>() const { return is_expression_statement(); }
  1554. template<>
  1555. inline bool ASTNode::fast_is<ScopeNode>() const { return is_scope_node(); }
  1556. template<>
  1557. inline bool ASTNode::fast_is<Program>() const { return is_program(); }
  1558. template<>
  1559. inline bool ASTNode::fast_is<FunctionDeclaration>() const { return is_function_declaration(); }
  1560. }