11cb0ef41Sopenharmony_ci// Copyright 2012 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_PARSING_PARSER_H_ 61cb0ef41Sopenharmony_ci#define V8_PARSING_PARSER_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include <cstddef> 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "src/ast/ast-source-ranges.h" 111cb0ef41Sopenharmony_ci#include "src/ast/ast-value-factory.h" 121cb0ef41Sopenharmony_ci#include "src/ast/ast.h" 131cb0ef41Sopenharmony_ci#include "src/ast/scopes.h" 141cb0ef41Sopenharmony_ci#include "src/base/compiler-specific.h" 151cb0ef41Sopenharmony_ci#include "src/base/pointer-with-payload.h" 161cb0ef41Sopenharmony_ci#include "src/base/small-vector.h" 171cb0ef41Sopenharmony_ci#include "src/base/threaded-list.h" 181cb0ef41Sopenharmony_ci#include "src/common/globals.h" 191cb0ef41Sopenharmony_ci#include "src/parsing/import-assertions.h" 201cb0ef41Sopenharmony_ci#include "src/parsing/parse-info.h" 211cb0ef41Sopenharmony_ci#include "src/parsing/parser-base.h" 221cb0ef41Sopenharmony_ci#include "src/parsing/parsing.h" 231cb0ef41Sopenharmony_ci#include "src/parsing/preparser.h" 241cb0ef41Sopenharmony_ci#include "src/zone/zone-chunk-list.h" 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cinamespace v8 { 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciclass ScriptCompiler; 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cinamespace internal { 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciclass ConsumedPreparseData; 331cb0ef41Sopenharmony_ciclass ParseInfo; 341cb0ef41Sopenharmony_ciclass ParserTarget; 351cb0ef41Sopenharmony_ciclass ParserTargetScope; 361cb0ef41Sopenharmony_ciclass PendingCompilationErrorHandler; 371cb0ef41Sopenharmony_ciclass PreparseData; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci// ---------------------------------------------------------------------------- 401cb0ef41Sopenharmony_ci// JAVASCRIPT PARSING 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ciclass Parser; 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_cistruct ParserFormalParameters : FormalParametersBase { 461cb0ef41Sopenharmony_ci struct Parameter : public ZoneObject { 471cb0ef41Sopenharmony_ci Parameter(Expression* pattern, Expression* initializer, int position, 481cb0ef41Sopenharmony_ci int initializer_end_position, bool is_rest) 491cb0ef41Sopenharmony_ci : initializer_and_is_rest(initializer, is_rest), 501cb0ef41Sopenharmony_ci pattern(pattern), 511cb0ef41Sopenharmony_ci position(position), 521cb0ef41Sopenharmony_ci initializer_end_position(initializer_end_position) {} 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci base::PointerWithPayload<Expression, bool, 1> initializer_and_is_rest; 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci Expression* pattern; 571cb0ef41Sopenharmony_ci Expression* initializer() const { 581cb0ef41Sopenharmony_ci return initializer_and_is_rest.GetPointer(); 591cb0ef41Sopenharmony_ci } 601cb0ef41Sopenharmony_ci int position; 611cb0ef41Sopenharmony_ci int initializer_end_position; 621cb0ef41Sopenharmony_ci inline bool is_rest() const { return initializer_and_is_rest.GetPayload(); } 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci Parameter* next_parameter = nullptr; 651cb0ef41Sopenharmony_ci bool is_simple() const { 661cb0ef41Sopenharmony_ci return pattern->IsVariableProxy() && initializer() == nullptr && 671cb0ef41Sopenharmony_ci !is_rest(); 681cb0ef41Sopenharmony_ci } 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci const AstRawString* name() const { 711cb0ef41Sopenharmony_ci DCHECK(is_simple()); 721cb0ef41Sopenharmony_ci return pattern->AsVariableProxy()->raw_name(); 731cb0ef41Sopenharmony_ci } 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci Parameter** next() { return &next_parameter; } 761cb0ef41Sopenharmony_ci Parameter* const* next() const { return &next_parameter; } 771cb0ef41Sopenharmony_ci }; 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci void set_strict_parameter_error(const Scanner::Location& loc, 801cb0ef41Sopenharmony_ci MessageTemplate message) { 811cb0ef41Sopenharmony_ci strict_error_loc = loc; 821cb0ef41Sopenharmony_ci strict_error_message = message; 831cb0ef41Sopenharmony_ci } 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci bool has_duplicate() const { return duplicate_loc.IsValid(); } 861cb0ef41Sopenharmony_ci void ValidateDuplicate(Parser* parser) const; 871cb0ef41Sopenharmony_ci void ValidateStrictMode(Parser* parser) const; 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci explicit ParserFormalParameters(DeclarationScope* scope) 901cb0ef41Sopenharmony_ci : FormalParametersBase(scope) {} 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci base::ThreadedList<Parameter> params; 931cb0ef41Sopenharmony_ci Scanner::Location duplicate_loc = Scanner::Location::invalid(); 941cb0ef41Sopenharmony_ci Scanner::Location strict_error_loc = Scanner::Location::invalid(); 951cb0ef41Sopenharmony_ci MessageTemplate strict_error_message = MessageTemplate::kNone; 961cb0ef41Sopenharmony_ci}; 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_citemplate <> 991cb0ef41Sopenharmony_cistruct ParserTypes<Parser> { 1001cb0ef41Sopenharmony_ci using Base = ParserBase<Parser>; 1011cb0ef41Sopenharmony_ci using Impl = Parser; 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci // Return types for traversing functions. 1041cb0ef41Sopenharmony_ci using Block = v8::internal::Block*; 1051cb0ef41Sopenharmony_ci using BreakableStatement = v8::internal::BreakableStatement*; 1061cb0ef41Sopenharmony_ci using ClassLiteralProperty = ClassLiteral::Property*; 1071cb0ef41Sopenharmony_ci using ClassLiteralStaticElement = ClassLiteral::StaticElement*; 1081cb0ef41Sopenharmony_ci using ClassPropertyList = ZonePtrList<ClassLiteral::Property>*; 1091cb0ef41Sopenharmony_ci using ClassStaticElementList = ZonePtrList<ClassLiteral::StaticElement>*; 1101cb0ef41Sopenharmony_ci using Expression = v8::internal::Expression*; 1111cb0ef41Sopenharmony_ci using ExpressionList = ScopedPtrList<v8::internal::Expression>; 1121cb0ef41Sopenharmony_ci using FormalParameters = ParserFormalParameters; 1131cb0ef41Sopenharmony_ci using ForStatement = v8::internal::ForStatement*; 1141cb0ef41Sopenharmony_ci using FunctionLiteral = v8::internal::FunctionLiteral*; 1151cb0ef41Sopenharmony_ci using Identifier = const AstRawString*; 1161cb0ef41Sopenharmony_ci using IterationStatement = v8::internal::IterationStatement*; 1171cb0ef41Sopenharmony_ci using ObjectLiteralProperty = ObjectLiteral::Property*; 1181cb0ef41Sopenharmony_ci using ObjectPropertyList = ScopedPtrList<v8::internal::ObjectLiteralProperty>; 1191cb0ef41Sopenharmony_ci using Statement = v8::internal::Statement*; 1201cb0ef41Sopenharmony_ci using StatementList = ScopedPtrList<v8::internal::Statement>; 1211cb0ef41Sopenharmony_ci using Suspend = v8::internal::Suspend*; 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci // For constructing objects returned by the traversing functions. 1241cb0ef41Sopenharmony_ci using Factory = AstNodeFactory; 1251cb0ef41Sopenharmony_ci 1261cb0ef41Sopenharmony_ci // Other implementation-specific functions. 1271cb0ef41Sopenharmony_ci using FuncNameInferrer = v8::internal::FuncNameInferrer; 1281cb0ef41Sopenharmony_ci using SourceRange = v8::internal::SourceRange; 1291cb0ef41Sopenharmony_ci using SourceRangeScope = v8::internal::SourceRangeScope; 1301cb0ef41Sopenharmony_ci}; 1311cb0ef41Sopenharmony_ci 1321cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { 1331cb0ef41Sopenharmony_ci public: 1341cb0ef41Sopenharmony_ci Parser(LocalIsolate* local_isolate, ParseInfo* info, Handle<Script> script); 1351cb0ef41Sopenharmony_ci ~Parser() { 1361cb0ef41Sopenharmony_ci delete reusable_preparser_; 1371cb0ef41Sopenharmony_ci reusable_preparser_ = nullptr; 1381cb0ef41Sopenharmony_ci } 1391cb0ef41Sopenharmony_ci 1401cb0ef41Sopenharmony_ci static bool IsPreParser() { return false; } 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci // Sets the literal on |info| if parsing succeeded. 1431cb0ef41Sopenharmony_ci void ParseOnBackground(LocalIsolate* isolate, ParseInfo* info, 1441cb0ef41Sopenharmony_ci int start_position, int end_position, 1451cb0ef41Sopenharmony_ci int function_literal_id); 1461cb0ef41Sopenharmony_ci 1471cb0ef41Sopenharmony_ci // Initializes an empty scope chain for top-level scripts, or scopes which 1481cb0ef41Sopenharmony_ci // consist of only the native context. 1491cb0ef41Sopenharmony_ci void InitializeEmptyScopeChain(ParseInfo* info); 1501cb0ef41Sopenharmony_ci 1511cb0ef41Sopenharmony_ci // Deserialize the scope chain prior to parsing in which the script is going 1521cb0ef41Sopenharmony_ci // to be executed. If the script is a top-level script, or the scope chain 1531cb0ef41Sopenharmony_ci // consists of only a native context, maybe_outer_scope_info should be an 1541cb0ef41Sopenharmony_ci // empty handle. 1551cb0ef41Sopenharmony_ci // 1561cb0ef41Sopenharmony_ci // This only deserializes the scope chain, but doesn't connect the scopes to 1571cb0ef41Sopenharmony_ci // their corresponding scope infos. Therefore, looking up variables in the 1581cb0ef41Sopenharmony_ci // deserialized scopes is not possible. 1591cb0ef41Sopenharmony_ci template <typename IsolateT> 1601cb0ef41Sopenharmony_ci void DeserializeScopeChain(IsolateT* isolate, ParseInfo* info, 1611cb0ef41Sopenharmony_ci MaybeHandle<ScopeInfo> maybe_outer_scope_info, 1621cb0ef41Sopenharmony_ci Scope::DeserializationMode mode = 1631cb0ef41Sopenharmony_ci Scope::DeserializationMode::kScopesOnly); 1641cb0ef41Sopenharmony_ci 1651cb0ef41Sopenharmony_ci // Move statistics to Isolate 1661cb0ef41Sopenharmony_ci void UpdateStatistics(Isolate* isolate, Handle<Script> script); 1671cb0ef41Sopenharmony_ci void UpdateStatistics( 1681cb0ef41Sopenharmony_ci Handle<Script> script, 1691cb0ef41Sopenharmony_ci base::SmallVector<v8::Isolate::UseCounterFeature, 8>* use_counters, 1701cb0ef41Sopenharmony_ci int* preparse_skipped); 1711cb0ef41Sopenharmony_ci template <typename IsolateT> 1721cb0ef41Sopenharmony_ci void HandleSourceURLComments(IsolateT* isolate, Handle<Script> script); 1731cb0ef41Sopenharmony_ci 1741cb0ef41Sopenharmony_ci private: 1751cb0ef41Sopenharmony_ci friend class ParserBase<Parser>; 1761cb0ef41Sopenharmony_ci friend struct ParserFormalParameters; 1771cb0ef41Sopenharmony_ci friend class i::ExpressionScope<ParserTypes<Parser>>; 1781cb0ef41Sopenharmony_ci friend class i::VariableDeclarationParsingScope<ParserTypes<Parser>>; 1791cb0ef41Sopenharmony_ci friend class i::ParameterDeclarationParsingScope<ParserTypes<Parser>>; 1801cb0ef41Sopenharmony_ci friend class i::ArrowHeadParsingScope<ParserTypes<Parser>>; 1811cb0ef41Sopenharmony_ci friend bool v8::internal::parsing::ParseProgram( 1821cb0ef41Sopenharmony_ci ParseInfo*, Handle<Script>, MaybeHandle<ScopeInfo> maybe_outer_scope_info, 1831cb0ef41Sopenharmony_ci Isolate*, parsing::ReportStatisticsMode stats_mode); 1841cb0ef41Sopenharmony_ci friend bool v8::internal::parsing::ParseFunction( 1851cb0ef41Sopenharmony_ci ParseInfo*, Handle<SharedFunctionInfo> shared_info, Isolate*, 1861cb0ef41Sopenharmony_ci parsing::ReportStatisticsMode stats_mode); 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci bool AllowsLazyParsingWithoutUnresolvedVariables() const { 1891cb0ef41Sopenharmony_ci return !MaybeParsingArrowhead() && 1901cb0ef41Sopenharmony_ci scope()->AllowsLazyParsingWithoutUnresolvedVariables( 1911cb0ef41Sopenharmony_ci original_scope_); 1921cb0ef41Sopenharmony_ci } 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci bool parse_lazily() const { return mode_ == PARSE_LAZILY; } 1951cb0ef41Sopenharmony_ci enum Mode { PARSE_LAZILY, PARSE_EAGERLY }; 1961cb0ef41Sopenharmony_ci 1971cb0ef41Sopenharmony_ci class V8_NODISCARD ParsingModeScope { 1981cb0ef41Sopenharmony_ci public: 1991cb0ef41Sopenharmony_ci ParsingModeScope(Parser* parser, Mode mode) 2001cb0ef41Sopenharmony_ci : parser_(parser), old_mode_(parser->mode_) { 2011cb0ef41Sopenharmony_ci parser_->mode_ = mode; 2021cb0ef41Sopenharmony_ci } 2031cb0ef41Sopenharmony_ci ~ParsingModeScope() { parser_->mode_ = old_mode_; } 2041cb0ef41Sopenharmony_ci 2051cb0ef41Sopenharmony_ci private: 2061cb0ef41Sopenharmony_ci Parser* parser_; 2071cb0ef41Sopenharmony_ci Mode old_mode_; 2081cb0ef41Sopenharmony_ci }; 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ci // Runtime encoding of different completion modes. 2111cb0ef41Sopenharmony_ci enum CompletionKind { 2121cb0ef41Sopenharmony_ci kNormalCompletion, 2131cb0ef41Sopenharmony_ci kThrowCompletion, 2141cb0ef41Sopenharmony_ci kAbruptCompletion 2151cb0ef41Sopenharmony_ci }; 2161cb0ef41Sopenharmony_ci 2171cb0ef41Sopenharmony_ci Variable* NewTemporary(const AstRawString* name) { 2181cb0ef41Sopenharmony_ci return scope()->NewTemporary(name); 2191cb0ef41Sopenharmony_ci } 2201cb0ef41Sopenharmony_ci 2211cb0ef41Sopenharmony_ci void PrepareGeneratorVariables(); 2221cb0ef41Sopenharmony_ci 2231cb0ef41Sopenharmony_ci // Sets the literal on |info| if parsing succeeded. 2241cb0ef41Sopenharmony_ci void ParseProgram(Isolate* isolate, Handle<Script> script, ParseInfo* info, 2251cb0ef41Sopenharmony_ci MaybeHandle<ScopeInfo> maybe_outer_scope_info); 2261cb0ef41Sopenharmony_ci 2271cb0ef41Sopenharmony_ci // Sets the literal on |info| if parsing succeeded. 2281cb0ef41Sopenharmony_ci void ParseFunction(Isolate* isolate, ParseInfo* info, 2291cb0ef41Sopenharmony_ci Handle<SharedFunctionInfo> shared_info); 2301cb0ef41Sopenharmony_ci 2311cb0ef41Sopenharmony_ci template <typename IsolateT> 2321cb0ef41Sopenharmony_ci void PostProcessParseResult(IsolateT* isolate, ParseInfo* info, 2331cb0ef41Sopenharmony_ci FunctionLiteral* literal); 2341cb0ef41Sopenharmony_ci 2351cb0ef41Sopenharmony_ci FunctionLiteral* DoParseFunction(Isolate* isolate, ParseInfo* info, 2361cb0ef41Sopenharmony_ci int start_position, int end_position, 2371cb0ef41Sopenharmony_ci int function_literal_id, 2381cb0ef41Sopenharmony_ci const AstRawString* raw_name); 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ci FunctionLiteral* DoParseDeserializedFunction( 2411cb0ef41Sopenharmony_ci Isolate* isolate, MaybeHandle<ScopeInfo> maybe_outer_scope_info, 2421cb0ef41Sopenharmony_ci ParseInfo* info, int start_position, int end_position, 2431cb0ef41Sopenharmony_ci int function_literal_id, const AstRawString* raw_name); 2441cb0ef41Sopenharmony_ci 2451cb0ef41Sopenharmony_ci FunctionLiteral* ParseClassForInstanceMemberInitialization( 2461cb0ef41Sopenharmony_ci Isolate* isolate, MaybeHandle<ScopeInfo> maybe_class_scope_info, 2471cb0ef41Sopenharmony_ci int initializer_pos, int initializer_id, int initializer_end_pos); 2481cb0ef41Sopenharmony_ci 2491cb0ef41Sopenharmony_ci // Called by ParseProgram after setting up the scanner. 2501cb0ef41Sopenharmony_ci FunctionLiteral* DoParseProgram(Isolate* isolate, ParseInfo* info); 2511cb0ef41Sopenharmony_ci 2521cb0ef41Sopenharmony_ci // Parse with the script as if the source is implicitly wrapped in a function. 2531cb0ef41Sopenharmony_ci // We manually construct the AST and scopes for a top-level function and the 2541cb0ef41Sopenharmony_ci // function wrapper. 2551cb0ef41Sopenharmony_ci void ParseWrapped(Isolate* isolate, ParseInfo* info, 2561cb0ef41Sopenharmony_ci ScopedPtrList<Statement>* body, DeclarationScope* scope, 2571cb0ef41Sopenharmony_ci Zone* zone); 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ci void ParseREPLProgram(ParseInfo* info, ScopedPtrList<Statement>* body, 2601cb0ef41Sopenharmony_ci DeclarationScope* scope); 2611cb0ef41Sopenharmony_ci Expression* WrapREPLResult(Expression* value); 2621cb0ef41Sopenharmony_ci 2631cb0ef41Sopenharmony_ci ZonePtrList<const AstRawString>* PrepareWrappedArguments(Isolate* isolate, 2641cb0ef41Sopenharmony_ci ParseInfo* info, 2651cb0ef41Sopenharmony_ci Zone* zone); 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ci PreParser* reusable_preparser() { 2681cb0ef41Sopenharmony_ci if (reusable_preparser_ == nullptr) { 2691cb0ef41Sopenharmony_ci reusable_preparser_ = new PreParser( 2701cb0ef41Sopenharmony_ci &preparser_zone_, &scanner_, stack_limit_, ast_value_factory(), 2711cb0ef41Sopenharmony_ci pending_error_handler(), runtime_call_stats_, logger_, flags(), 2721cb0ef41Sopenharmony_ci parsing_on_main_thread_); 2731cb0ef41Sopenharmony_ci reusable_preparser_->set_allow_eval_cache(allow_eval_cache()); 2741cb0ef41Sopenharmony_ci preparse_data_buffer_.reserve(128); 2751cb0ef41Sopenharmony_ci } 2761cb0ef41Sopenharmony_ci return reusable_preparser_; 2771cb0ef41Sopenharmony_ci } 2781cb0ef41Sopenharmony_ci 2791cb0ef41Sopenharmony_ci void ParseModuleItemList(ScopedPtrList<Statement>* body); 2801cb0ef41Sopenharmony_ci Statement* ParseModuleItem(); 2811cb0ef41Sopenharmony_ci const AstRawString* ParseModuleSpecifier(); 2821cb0ef41Sopenharmony_ci void ParseImportDeclaration(); 2831cb0ef41Sopenharmony_ci Statement* ParseExportDeclaration(); 2841cb0ef41Sopenharmony_ci Statement* ParseExportDefault(); 2851cb0ef41Sopenharmony_ci void ParseExportStar(); 2861cb0ef41Sopenharmony_ci struct ExportClauseData { 2871cb0ef41Sopenharmony_ci const AstRawString* export_name; 2881cb0ef41Sopenharmony_ci const AstRawString* local_name; 2891cb0ef41Sopenharmony_ci Scanner::Location location; 2901cb0ef41Sopenharmony_ci }; 2911cb0ef41Sopenharmony_ci ZoneChunkList<ExportClauseData>* ParseExportClause( 2921cb0ef41Sopenharmony_ci Scanner::Location* reserved_loc, 2931cb0ef41Sopenharmony_ci Scanner::Location* string_literal_local_name_loc); 2941cb0ef41Sopenharmony_ci struct NamedImport : public ZoneObject { 2951cb0ef41Sopenharmony_ci const AstRawString* import_name; 2961cb0ef41Sopenharmony_ci const AstRawString* local_name; 2971cb0ef41Sopenharmony_ci const Scanner::Location location; 2981cb0ef41Sopenharmony_ci NamedImport(const AstRawString* import_name, const AstRawString* local_name, 2991cb0ef41Sopenharmony_ci Scanner::Location location) 3001cb0ef41Sopenharmony_ci : import_name(import_name), 3011cb0ef41Sopenharmony_ci local_name(local_name), 3021cb0ef41Sopenharmony_ci location(location) {} 3031cb0ef41Sopenharmony_ci }; 3041cb0ef41Sopenharmony_ci const AstRawString* ParseExportSpecifierName(); 3051cb0ef41Sopenharmony_ci ZonePtrList<const NamedImport>* ParseNamedImports(int pos); 3061cb0ef41Sopenharmony_ci 3071cb0ef41Sopenharmony_ci ImportAssertions* ParseImportAssertClause(); 3081cb0ef41Sopenharmony_ci Statement* BuildInitializationBlock(DeclarationParsingResult* parsing_result); 3091cb0ef41Sopenharmony_ci Expression* RewriteReturn(Expression* return_value, int pos); 3101cb0ef41Sopenharmony_ci Statement* RewriteSwitchStatement(SwitchStatement* switch_statement, 3111cb0ef41Sopenharmony_ci Scope* scope); 3121cb0ef41Sopenharmony_ci Block* RewriteCatchPattern(CatchInfo* catch_info); 3131cb0ef41Sopenharmony_ci void ReportVarRedeclarationIn(const AstRawString* name, Scope* scope); 3141cb0ef41Sopenharmony_ci Statement* RewriteTryStatement(Block* try_block, Block* catch_block, 3151cb0ef41Sopenharmony_ci const SourceRange& catch_range, 3161cb0ef41Sopenharmony_ci Block* finally_block, 3171cb0ef41Sopenharmony_ci const SourceRange& finally_range, 3181cb0ef41Sopenharmony_ci const CatchInfo& catch_info, int pos); 3191cb0ef41Sopenharmony_ci void ParseAndRewriteGeneratorFunctionBody(int pos, FunctionKind kind, 3201cb0ef41Sopenharmony_ci ScopedPtrList<Statement>* body); 3211cb0ef41Sopenharmony_ci void ParseAndRewriteAsyncGeneratorFunctionBody( 3221cb0ef41Sopenharmony_ci int pos, FunctionKind kind, ScopedPtrList<Statement>* body); 3231cb0ef41Sopenharmony_ci void DeclareFunctionNameVar(const AstRawString* function_name, 3241cb0ef41Sopenharmony_ci FunctionSyntaxKind function_syntax_kind, 3251cb0ef41Sopenharmony_ci DeclarationScope* function_scope); 3261cb0ef41Sopenharmony_ci 3271cb0ef41Sopenharmony_ci Statement* DeclareFunction(const AstRawString* variable_name, 3281cb0ef41Sopenharmony_ci FunctionLiteral* function, VariableMode mode, 3291cb0ef41Sopenharmony_ci VariableKind kind, int beg_pos, int end_pos, 3301cb0ef41Sopenharmony_ci ZonePtrList<const AstRawString>* names); 3311cb0ef41Sopenharmony_ci Variable* CreateSyntheticContextVariable(const AstRawString* synthetic_name); 3321cb0ef41Sopenharmony_ci Variable* CreatePrivateNameVariable(ClassScope* scope, VariableMode mode, 3331cb0ef41Sopenharmony_ci IsStaticFlag is_static_flag, 3341cb0ef41Sopenharmony_ci const AstRawString* name); 3351cb0ef41Sopenharmony_ci FunctionLiteral* CreateInitializerFunction(const char* name, 3361cb0ef41Sopenharmony_ci DeclarationScope* scope, 3371cb0ef41Sopenharmony_ci Statement* initializer_stmt); 3381cb0ef41Sopenharmony_ci 3391cb0ef41Sopenharmony_ci bool IdentifierEquals(const AstRawString* identifier, 3401cb0ef41Sopenharmony_ci const AstRawString* other) { 3411cb0ef41Sopenharmony_ci return identifier == other; 3421cb0ef41Sopenharmony_ci } 3431cb0ef41Sopenharmony_ci 3441cb0ef41Sopenharmony_ci Statement* DeclareClass(const AstRawString* variable_name, Expression* value, 3451cb0ef41Sopenharmony_ci ZonePtrList<const AstRawString>* names, 3461cb0ef41Sopenharmony_ci int class_token_pos, int end_pos); 3471cb0ef41Sopenharmony_ci void DeclareClassVariable(ClassScope* scope, const AstRawString* name, 3481cb0ef41Sopenharmony_ci ClassInfo* class_info, int class_token_pos); 3491cb0ef41Sopenharmony_ci void DeclareClassBrandVariable(ClassScope* scope, ClassInfo* class_info, 3501cb0ef41Sopenharmony_ci int class_token_pos); 3511cb0ef41Sopenharmony_ci void DeclarePrivateClassMember(ClassScope* scope, 3521cb0ef41Sopenharmony_ci const AstRawString* property_name, 3531cb0ef41Sopenharmony_ci ClassLiteralProperty* property, 3541cb0ef41Sopenharmony_ci ClassLiteralProperty::Kind kind, 3551cb0ef41Sopenharmony_ci bool is_static, ClassInfo* class_info); 3561cb0ef41Sopenharmony_ci void DeclarePublicClassMethod(const AstRawString* class_name, 3571cb0ef41Sopenharmony_ci ClassLiteralProperty* property, 3581cb0ef41Sopenharmony_ci bool is_constructor, ClassInfo* class_info); 3591cb0ef41Sopenharmony_ci void DeclarePublicClassField(ClassScope* scope, 3601cb0ef41Sopenharmony_ci ClassLiteralProperty* property, bool is_static, 3611cb0ef41Sopenharmony_ci bool is_computed_name, ClassInfo* class_info); 3621cb0ef41Sopenharmony_ci void DeclareClassProperty(ClassScope* scope, const AstRawString* class_name, 3631cb0ef41Sopenharmony_ci ClassLiteralProperty* property, bool is_constructor, 3641cb0ef41Sopenharmony_ci ClassInfo* class_info); 3651cb0ef41Sopenharmony_ci void DeclareClassField(ClassScope* scope, ClassLiteralProperty* property, 3661cb0ef41Sopenharmony_ci const AstRawString* property_name, bool is_static, 3671cb0ef41Sopenharmony_ci bool is_computed_name, bool is_private, 3681cb0ef41Sopenharmony_ci ClassInfo* class_info); 3691cb0ef41Sopenharmony_ci void AddClassStaticBlock(Block* block, ClassInfo* class_info); 3701cb0ef41Sopenharmony_ci Expression* RewriteClassLiteral(ClassScope* block_scope, 3711cb0ef41Sopenharmony_ci const AstRawString* name, 3721cb0ef41Sopenharmony_ci ClassInfo* class_info, int pos, int end_pos); 3731cb0ef41Sopenharmony_ci Statement* DeclareNative(const AstRawString* name, int pos); 3741cb0ef41Sopenharmony_ci 3751cb0ef41Sopenharmony_ci Block* IgnoreCompletion(Statement* statement); 3761cb0ef41Sopenharmony_ci 3771cb0ef41Sopenharmony_ci Scope* NewHiddenCatchScope(); 3781cb0ef41Sopenharmony_ci 3791cb0ef41Sopenharmony_ci bool HasCheckedSyntax() { 3801cb0ef41Sopenharmony_ci return scope()->GetDeclarationScope()->has_checked_syntax(); 3811cb0ef41Sopenharmony_ci } 3821cb0ef41Sopenharmony_ci 3831cb0ef41Sopenharmony_ci void InitializeVariables( 3841cb0ef41Sopenharmony_ci ScopedPtrList<Statement>* statements, VariableKind kind, 3851cb0ef41Sopenharmony_ci const DeclarationParsingResult::Declaration* declaration); 3861cb0ef41Sopenharmony_ci 3871cb0ef41Sopenharmony_ci Block* RewriteForVarInLegacy(const ForInfo& for_info); 3881cb0ef41Sopenharmony_ci void DesugarBindingInForEachStatement(ForInfo* for_info, Block** body_block, 3891cb0ef41Sopenharmony_ci Expression** each_variable); 3901cb0ef41Sopenharmony_ci Block* CreateForEachStatementTDZ(Block* init_block, const ForInfo& for_info); 3911cb0ef41Sopenharmony_ci 3921cb0ef41Sopenharmony_ci Statement* DesugarLexicalBindingsInForStatement( 3931cb0ef41Sopenharmony_ci ForStatement* loop, Statement* init, Expression* cond, Statement* next, 3941cb0ef41Sopenharmony_ci Statement* body, Scope* inner_scope, const ForInfo& for_info); 3951cb0ef41Sopenharmony_ci 3961cb0ef41Sopenharmony_ci FunctionLiteral* ParseFunctionLiteral( 3971cb0ef41Sopenharmony_ci const AstRawString* name, Scanner::Location function_name_location, 3981cb0ef41Sopenharmony_ci FunctionNameValidity function_name_validity, FunctionKind kind, 3991cb0ef41Sopenharmony_ci int function_token_position, FunctionSyntaxKind type, 4001cb0ef41Sopenharmony_ci LanguageMode language_mode, 4011cb0ef41Sopenharmony_ci ZonePtrList<const AstRawString>* arguments_for_wrapped_function); 4021cb0ef41Sopenharmony_ci 4031cb0ef41Sopenharmony_ci ObjectLiteral* InitializeObjectLiteral(ObjectLiteral* object_literal) { 4041cb0ef41Sopenharmony_ci object_literal->CalculateEmitStore(main_zone()); 4051cb0ef41Sopenharmony_ci return object_literal; 4061cb0ef41Sopenharmony_ci } 4071cb0ef41Sopenharmony_ci 4081cb0ef41Sopenharmony_ci // Insert initializer statements for var-bindings shadowing parameter bindings 4091cb0ef41Sopenharmony_ci // from a non-simple parameter list. 4101cb0ef41Sopenharmony_ci void InsertShadowingVarBindingInitializers(Block* block); 4111cb0ef41Sopenharmony_ci 4121cb0ef41Sopenharmony_ci // Implement sloppy block-scoped functions, ES2015 Annex B 3.3 4131cb0ef41Sopenharmony_ci void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope); 4141cb0ef41Sopenharmony_ci 4151cb0ef41Sopenharmony_ci void DeclareUnboundVariable(const AstRawString* name, VariableMode mode, 4161cb0ef41Sopenharmony_ci InitializationFlag init, int pos); 4171cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT 4181cb0ef41Sopenharmony_ci VariableProxy* DeclareBoundVariable(const AstRawString* name, 4191cb0ef41Sopenharmony_ci VariableMode mode, int pos); 4201cb0ef41Sopenharmony_ci void DeclareAndBindVariable(VariableProxy* proxy, VariableKind kind, 4211cb0ef41Sopenharmony_ci VariableMode mode, Scope* declaration_scope, 4221cb0ef41Sopenharmony_ci bool* was_added, int initializer_position); 4231cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT 4241cb0ef41Sopenharmony_ci Variable* DeclareVariable(const AstRawString* name, VariableKind kind, 4251cb0ef41Sopenharmony_ci VariableMode mode, InitializationFlag init, 4261cb0ef41Sopenharmony_ci Scope* declaration_scope, bool* was_added, 4271cb0ef41Sopenharmony_ci int begin, int end = kNoSourcePosition); 4281cb0ef41Sopenharmony_ci void Declare(Declaration* declaration, const AstRawString* name, 4291cb0ef41Sopenharmony_ci VariableKind kind, VariableMode mode, InitializationFlag init, 4301cb0ef41Sopenharmony_ci Scope* declaration_scope, bool* was_added, int var_begin_pos, 4311cb0ef41Sopenharmony_ci int var_end_pos = kNoSourcePosition); 4321cb0ef41Sopenharmony_ci 4331cb0ef41Sopenharmony_ci // Factory methods. 4341cb0ef41Sopenharmony_ci FunctionLiteral* DefaultConstructor(const AstRawString* name, bool call_super, 4351cb0ef41Sopenharmony_ci int pos, int end_pos); 4361cb0ef41Sopenharmony_ci 4371cb0ef41Sopenharmony_ci // Skip over a lazy function, either using cached data if we have it, or 4381cb0ef41Sopenharmony_ci // by parsing the function with PreParser. Consumes the ending }. 4391cb0ef41Sopenharmony_ci // In case the preparser detects an error it cannot identify, it resets the 4401cb0ef41Sopenharmony_ci // scanner- and preparser state to the initial one, before PreParsing the 4411cb0ef41Sopenharmony_ci // function. 4421cb0ef41Sopenharmony_ci // SkipFunction returns true if it correctly parsed the function, including 4431cb0ef41Sopenharmony_ci // cases where we detect an error. It returns false, if we needed to stop 4441cb0ef41Sopenharmony_ci // parsing or could not identify an error correctly, meaning the caller needs 4451cb0ef41Sopenharmony_ci // to fully reparse. In this case it resets the scanner and preparser state. 4461cb0ef41Sopenharmony_ci bool SkipFunction(const AstRawString* function_name, FunctionKind kind, 4471cb0ef41Sopenharmony_ci FunctionSyntaxKind function_syntax_kind, 4481cb0ef41Sopenharmony_ci DeclarationScope* function_scope, int* num_parameters, 4491cb0ef41Sopenharmony_ci int* function_length, 4501cb0ef41Sopenharmony_ci ProducedPreparseData** produced_preparsed_scope_data); 4511cb0ef41Sopenharmony_ci 4521cb0ef41Sopenharmony_ci Block* BuildParameterInitializationBlock( 4531cb0ef41Sopenharmony_ci const ParserFormalParameters& parameters); 4541cb0ef41Sopenharmony_ci Block* BuildRejectPromiseOnException(Block* block, 4551cb0ef41Sopenharmony_ci REPLMode repl_mode = REPLMode::kNo); 4561cb0ef41Sopenharmony_ci 4571cb0ef41Sopenharmony_ci void ParseFunction( 4581cb0ef41Sopenharmony_ci ScopedPtrList<Statement>* body, const AstRawString* function_name, 4591cb0ef41Sopenharmony_ci int pos, FunctionKind kind, FunctionSyntaxKind function_syntax_kind, 4601cb0ef41Sopenharmony_ci DeclarationScope* function_scope, int* num_parameters, 4611cb0ef41Sopenharmony_ci int* function_length, bool* has_duplicate_parameters, 4621cb0ef41Sopenharmony_ci int* expected_property_count, int* suspend_count, 4631cb0ef41Sopenharmony_ci ZonePtrList<const AstRawString>* arguments_for_wrapped_function); 4641cb0ef41Sopenharmony_ci 4651cb0ef41Sopenharmony_ci void ThrowPendingError(Isolate* isolate, Handle<Script> script); 4661cb0ef41Sopenharmony_ci 4671cb0ef41Sopenharmony_ci class TemplateLiteral : public ZoneObject { 4681cb0ef41Sopenharmony_ci public: 4691cb0ef41Sopenharmony_ci TemplateLiteral(Zone* zone, int pos) 4701cb0ef41Sopenharmony_ci : cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {} 4711cb0ef41Sopenharmony_ci 4721cb0ef41Sopenharmony_ci const ZonePtrList<const AstRawString>* cooked() const { return &cooked_; } 4731cb0ef41Sopenharmony_ci const ZonePtrList<const AstRawString>* raw() const { return &raw_; } 4741cb0ef41Sopenharmony_ci const ZonePtrList<Expression>* expressions() const { return &expressions_; } 4751cb0ef41Sopenharmony_ci int position() const { return pos_; } 4761cb0ef41Sopenharmony_ci 4771cb0ef41Sopenharmony_ci void AddTemplateSpan(const AstRawString* cooked, const AstRawString* raw, 4781cb0ef41Sopenharmony_ci int end, Zone* zone) { 4791cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(raw); 4801cb0ef41Sopenharmony_ci cooked_.Add(cooked, zone); 4811cb0ef41Sopenharmony_ci raw_.Add(raw, zone); 4821cb0ef41Sopenharmony_ci } 4831cb0ef41Sopenharmony_ci 4841cb0ef41Sopenharmony_ci void AddExpression(Expression* expression, Zone* zone) { 4851cb0ef41Sopenharmony_ci expressions_.Add(expression, zone); 4861cb0ef41Sopenharmony_ci } 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_ci private: 4891cb0ef41Sopenharmony_ci ZonePtrList<const AstRawString> cooked_; 4901cb0ef41Sopenharmony_ci ZonePtrList<const AstRawString> raw_; 4911cb0ef41Sopenharmony_ci ZonePtrList<Expression> expressions_; 4921cb0ef41Sopenharmony_ci int pos_; 4931cb0ef41Sopenharmony_ci }; 4941cb0ef41Sopenharmony_ci 4951cb0ef41Sopenharmony_ci using TemplateLiteralState = TemplateLiteral*; 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ci TemplateLiteralState OpenTemplateLiteral(int pos); 4981cb0ef41Sopenharmony_ci // "should_cook" means that the span can be "cooked": in tagged template 4991cb0ef41Sopenharmony_ci // literals, both the raw and "cooked" representations are available to user 5001cb0ef41Sopenharmony_ci // code ("cooked" meaning that escape sequences are converted to their 5011cb0ef41Sopenharmony_ci // interpreted values). Invalid escape sequences cause the cooked span 5021cb0ef41Sopenharmony_ci // to be represented by undefined, instead of being a syntax error. 5031cb0ef41Sopenharmony_ci // "tail" indicates that this span is the last in the literal. 5041cb0ef41Sopenharmony_ci void AddTemplateSpan(TemplateLiteralState* state, bool should_cook, 5051cb0ef41Sopenharmony_ci bool tail); 5061cb0ef41Sopenharmony_ci void AddTemplateExpression(TemplateLiteralState* state, 5071cb0ef41Sopenharmony_ci Expression* expression); 5081cb0ef41Sopenharmony_ci Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, 5091cb0ef41Sopenharmony_ci Expression* tag); 5101cb0ef41Sopenharmony_ci 5111cb0ef41Sopenharmony_ci ArrayLiteral* ArrayLiteralFromListWithSpread( 5121cb0ef41Sopenharmony_ci const ScopedPtrList<Expression>& list); 5131cb0ef41Sopenharmony_ci Expression* RewriteSuperCall(Expression* call_expression); 5141cb0ef41Sopenharmony_ci 5151cb0ef41Sopenharmony_ci void SetLanguageMode(Scope* scope, LanguageMode mode); 5161cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY 5171cb0ef41Sopenharmony_ci void SetAsmModule(); 5181cb0ef41Sopenharmony_ci#endif // V8_ENABLE_WEBASSEMBLY 5191cb0ef41Sopenharmony_ci 5201cb0ef41Sopenharmony_ci Expression* RewriteSpreads(ArrayLiteral* lit); 5211cb0ef41Sopenharmony_ci 5221cb0ef41Sopenharmony_ci Expression* BuildInitialYield(int pos, FunctionKind kind); 5231cb0ef41Sopenharmony_ci Assignment* BuildCreateJSGeneratorObject(int pos, FunctionKind kind); 5241cb0ef41Sopenharmony_ci 5251cb0ef41Sopenharmony_ci // Generic AST generator for throwing errors from compiled code. 5261cb0ef41Sopenharmony_ci Expression* NewThrowError(Runtime::FunctionId function_id, 5271cb0ef41Sopenharmony_ci MessageTemplate message, const AstRawString* arg, 5281cb0ef41Sopenharmony_ci int pos); 5291cb0ef41Sopenharmony_ci 5301cb0ef41Sopenharmony_ci Statement* CheckCallable(Variable* var, Expression* error, int pos); 5311cb0ef41Sopenharmony_ci 5321cb0ef41Sopenharmony_ci void RewriteAsyncFunctionBody(ScopedPtrList<Statement>* body, Block* block, 5331cb0ef41Sopenharmony_ci Expression* return_value, 5341cb0ef41Sopenharmony_ci REPLMode repl_mode = REPLMode::kNo); 5351cb0ef41Sopenharmony_ci 5361cb0ef41Sopenharmony_ci void AddArrowFunctionFormalParameters(ParserFormalParameters* parameters, 5371cb0ef41Sopenharmony_ci Expression* params, int end_pos); 5381cb0ef41Sopenharmony_ci void SetFunctionName(Expression* value, const AstRawString* name, 5391cb0ef41Sopenharmony_ci const AstRawString* prefix = nullptr); 5401cb0ef41Sopenharmony_ci 5411cb0ef41Sopenharmony_ci // Helper functions for recursive descent. 5421cb0ef41Sopenharmony_ci V8_INLINE bool IsEval(const AstRawString* identifier) const { 5431cb0ef41Sopenharmony_ci return identifier == ast_value_factory()->eval_string(); 5441cb0ef41Sopenharmony_ci } 5451cb0ef41Sopenharmony_ci 5461cb0ef41Sopenharmony_ci V8_INLINE bool IsAsync(const AstRawString* identifier) const { 5471cb0ef41Sopenharmony_ci return identifier == ast_value_factory()->async_string(); 5481cb0ef41Sopenharmony_ci } 5491cb0ef41Sopenharmony_ci 5501cb0ef41Sopenharmony_ci V8_INLINE bool IsArguments(const AstRawString* identifier) const { 5511cb0ef41Sopenharmony_ci return identifier == ast_value_factory()->arguments_string(); 5521cb0ef41Sopenharmony_ci } 5531cb0ef41Sopenharmony_ci 5541cb0ef41Sopenharmony_ci V8_INLINE bool IsEvalOrArguments(const AstRawString* identifier) const { 5551cb0ef41Sopenharmony_ci return IsEval(identifier) || IsArguments(identifier); 5561cb0ef41Sopenharmony_ci } 5571cb0ef41Sopenharmony_ci 5581cb0ef41Sopenharmony_ci // Returns true if the expression is of type "this.foo". 5591cb0ef41Sopenharmony_ci V8_INLINE static bool IsThisProperty(Expression* expression) { 5601cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(expression); 5611cb0ef41Sopenharmony_ci Property* property = expression->AsProperty(); 5621cb0ef41Sopenharmony_ci return property != nullptr && property->obj()->IsThisExpression(); 5631cb0ef41Sopenharmony_ci } 5641cb0ef41Sopenharmony_ci 5651cb0ef41Sopenharmony_ci // Returns true if the expression is of type "obj.#foo" or "obj?.#foo". 5661cb0ef41Sopenharmony_ci V8_INLINE static bool IsPrivateReference(Expression* expression) { 5671cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(expression); 5681cb0ef41Sopenharmony_ci Property* property = expression->AsProperty(); 5691cb0ef41Sopenharmony_ci if (expression->IsOptionalChain()) { 5701cb0ef41Sopenharmony_ci Expression* expr_inner = expression->AsOptionalChain()->expression(); 5711cb0ef41Sopenharmony_ci property = expr_inner->AsProperty(); 5721cb0ef41Sopenharmony_ci } 5731cb0ef41Sopenharmony_ci return property != nullptr && property->IsPrivateReference(); 5741cb0ef41Sopenharmony_ci } 5751cb0ef41Sopenharmony_ci 5761cb0ef41Sopenharmony_ci // This returns true if the expression is an identifier (wrapped 5771cb0ef41Sopenharmony_ci // inside a variable proxy). We exclude the case of 'this', which 5781cb0ef41Sopenharmony_ci // has been converted to a variable proxy. 5791cb0ef41Sopenharmony_ci V8_INLINE static bool IsIdentifier(Expression* expression) { 5801cb0ef41Sopenharmony_ci VariableProxy* operand = expression->AsVariableProxy(); 5811cb0ef41Sopenharmony_ci return operand != nullptr && !operand->is_new_target(); 5821cb0ef41Sopenharmony_ci } 5831cb0ef41Sopenharmony_ci 5841cb0ef41Sopenharmony_ci V8_INLINE static const AstRawString* AsIdentifier(Expression* expression) { 5851cb0ef41Sopenharmony_ci DCHECK(IsIdentifier(expression)); 5861cb0ef41Sopenharmony_ci return expression->AsVariableProxy()->raw_name(); 5871cb0ef41Sopenharmony_ci } 5881cb0ef41Sopenharmony_ci 5891cb0ef41Sopenharmony_ci V8_INLINE VariableProxy* AsIdentifierExpression(Expression* expression) { 5901cb0ef41Sopenharmony_ci return expression->AsVariableProxy(); 5911cb0ef41Sopenharmony_ci } 5921cb0ef41Sopenharmony_ci 5931cb0ef41Sopenharmony_ci V8_INLINE bool IsConstructor(const AstRawString* identifier) const { 5941cb0ef41Sopenharmony_ci return identifier == ast_value_factory()->constructor_string(); 5951cb0ef41Sopenharmony_ci } 5961cb0ef41Sopenharmony_ci 5971cb0ef41Sopenharmony_ci V8_INLINE bool IsName(const AstRawString* identifier) const { 5981cb0ef41Sopenharmony_ci return identifier == ast_value_factory()->name_string(); 5991cb0ef41Sopenharmony_ci } 6001cb0ef41Sopenharmony_ci 6011cb0ef41Sopenharmony_ci V8_INLINE static bool IsBoilerplateProperty( 6021cb0ef41Sopenharmony_ci ObjectLiteral::Property* property) { 6031cb0ef41Sopenharmony_ci return !property->IsPrototype(); 6041cb0ef41Sopenharmony_ci } 6051cb0ef41Sopenharmony_ci 6061cb0ef41Sopenharmony_ci V8_INLINE v8::Extension* extension() const { return info_->extension(); } 6071cb0ef41Sopenharmony_ci 6081cb0ef41Sopenharmony_ci V8_INLINE bool ParsingExtension() const { return extension() != nullptr; } 6091cb0ef41Sopenharmony_ci 6101cb0ef41Sopenharmony_ci V8_INLINE bool IsNative(Expression* expr) const { 6111cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(expr); 6121cb0ef41Sopenharmony_ci return expr->IsVariableProxy() && 6131cb0ef41Sopenharmony_ci expr->AsVariableProxy()->raw_name() == 6141cb0ef41Sopenharmony_ci ast_value_factory()->native_string(); 6151cb0ef41Sopenharmony_ci } 6161cb0ef41Sopenharmony_ci 6171cb0ef41Sopenharmony_ci V8_INLINE static bool IsArrayIndex(const AstRawString* string, 6181cb0ef41Sopenharmony_ci uint32_t* index) { 6191cb0ef41Sopenharmony_ci return string->AsArrayIndex(index); 6201cb0ef41Sopenharmony_ci } 6211cb0ef41Sopenharmony_ci 6221cb0ef41Sopenharmony_ci // Returns true if the statement is an expression statement containing 6231cb0ef41Sopenharmony_ci // a single string literal. If a second argument is given, the literal 6241cb0ef41Sopenharmony_ci // is also compared with it and the result is true only if they are equal. 6251cb0ef41Sopenharmony_ci V8_INLINE bool IsStringLiteral(Statement* statement, 6261cb0ef41Sopenharmony_ci const AstRawString* arg = nullptr) const { 6271cb0ef41Sopenharmony_ci ExpressionStatement* e_stat = statement->AsExpressionStatement(); 6281cb0ef41Sopenharmony_ci if (e_stat == nullptr) return false; 6291cb0ef41Sopenharmony_ci Literal* literal = e_stat->expression()->AsLiteral(); 6301cb0ef41Sopenharmony_ci if (literal == nullptr || !literal->IsString()) return false; 6311cb0ef41Sopenharmony_ci return arg == nullptr || literal->AsRawString() == arg; 6321cb0ef41Sopenharmony_ci } 6331cb0ef41Sopenharmony_ci 6341cb0ef41Sopenharmony_ci V8_INLINE void GetDefaultStrings(const AstRawString** default_string, 6351cb0ef41Sopenharmony_ci const AstRawString** dot_default_string) { 6361cb0ef41Sopenharmony_ci *default_string = ast_value_factory()->default_string(); 6371cb0ef41Sopenharmony_ci *dot_default_string = ast_value_factory()->dot_default_string(); 6381cb0ef41Sopenharmony_ci } 6391cb0ef41Sopenharmony_ci 6401cb0ef41Sopenharmony_ci // Functions for encapsulating the differences between parsing and preparsing; 6411cb0ef41Sopenharmony_ci // operations interleaved with the recursive descent. 6421cb0ef41Sopenharmony_ci V8_INLINE void PushLiteralName(const AstRawString* id) { 6431cb0ef41Sopenharmony_ci fni_.PushLiteralName(id); 6441cb0ef41Sopenharmony_ci } 6451cb0ef41Sopenharmony_ci 6461cb0ef41Sopenharmony_ci V8_INLINE void PushVariableName(const AstRawString* id) { 6471cb0ef41Sopenharmony_ci fni_.PushVariableName(id); 6481cb0ef41Sopenharmony_ci } 6491cb0ef41Sopenharmony_ci 6501cb0ef41Sopenharmony_ci V8_INLINE void PushPropertyName(Expression* expression) { 6511cb0ef41Sopenharmony_ci if (expression->IsPropertyName()) { 6521cb0ef41Sopenharmony_ci fni_.PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); 6531cb0ef41Sopenharmony_ci } else { 6541cb0ef41Sopenharmony_ci fni_.PushLiteralName(ast_value_factory()->computed_string()); 6551cb0ef41Sopenharmony_ci } 6561cb0ef41Sopenharmony_ci } 6571cb0ef41Sopenharmony_ci 6581cb0ef41Sopenharmony_ci V8_INLINE void PushEnclosingName(const AstRawString* name) { 6591cb0ef41Sopenharmony_ci fni_.PushEnclosingName(name); 6601cb0ef41Sopenharmony_ci } 6611cb0ef41Sopenharmony_ci 6621cb0ef41Sopenharmony_ci V8_INLINE void AddFunctionForNameInference(FunctionLiteral* func_to_infer) { 6631cb0ef41Sopenharmony_ci fni_.AddFunction(func_to_infer); 6641cb0ef41Sopenharmony_ci } 6651cb0ef41Sopenharmony_ci 6661cb0ef41Sopenharmony_ci V8_INLINE void InferFunctionName() { fni_.Infer(); } 6671cb0ef41Sopenharmony_ci 6681cb0ef41Sopenharmony_ci // If we assign a function literal to a property we pretenure the 6691cb0ef41Sopenharmony_ci // literal so it can be added as a constant function property. 6701cb0ef41Sopenharmony_ci V8_INLINE static void CheckAssigningFunctionLiteralToProperty( 6711cb0ef41Sopenharmony_ci Expression* left, Expression* right) { 6721cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(left); 6731cb0ef41Sopenharmony_ci if (left->IsProperty() && right->IsFunctionLiteral()) { 6741cb0ef41Sopenharmony_ci right->AsFunctionLiteral()->set_pretenure(); 6751cb0ef41Sopenharmony_ci } 6761cb0ef41Sopenharmony_ci } 6771cb0ef41Sopenharmony_ci 6781cb0ef41Sopenharmony_ci // Returns true if we have a binary expression between two numeric 6791cb0ef41Sopenharmony_ci // literals. In that case, *x will be changed to an expression which is the 6801cb0ef41Sopenharmony_ci // computed value. 6811cb0ef41Sopenharmony_ci bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y, 6821cb0ef41Sopenharmony_ci Token::Value op, int pos); 6831cb0ef41Sopenharmony_ci 6841cb0ef41Sopenharmony_ci // Returns true if we have a binary operation between a binary/n-ary 6851cb0ef41Sopenharmony_ci // expression (with the same operation) and a value, which can be collapsed 6861cb0ef41Sopenharmony_ci // into a single n-ary expression. In that case, *x will be changed to an 6871cb0ef41Sopenharmony_ci // n-ary expression. 6881cb0ef41Sopenharmony_ci bool CollapseNaryExpression(Expression** x, Expression* y, Token::Value op, 6891cb0ef41Sopenharmony_ci int pos, const SourceRange& range); 6901cb0ef41Sopenharmony_ci 6911cb0ef41Sopenharmony_ci // Returns a UnaryExpression or, in one of the following cases, a Literal. 6921cb0ef41Sopenharmony_ci // ! <literal> -> true / false 6931cb0ef41Sopenharmony_ci // + <Number literal> -> <Number literal> 6941cb0ef41Sopenharmony_ci // - <Number literal> -> <Number literal with value negated> 6951cb0ef41Sopenharmony_ci // ~ <literal> -> true / false 6961cb0ef41Sopenharmony_ci Expression* BuildUnaryExpression(Expression* expression, Token::Value op, 6971cb0ef41Sopenharmony_ci int pos); 6981cb0ef41Sopenharmony_ci 6991cb0ef41Sopenharmony_ci // Generate AST node that throws a ReferenceError with the given type. 7001cb0ef41Sopenharmony_ci V8_INLINE Expression* NewThrowReferenceError(MessageTemplate message, 7011cb0ef41Sopenharmony_ci int pos) { 7021cb0ef41Sopenharmony_ci return NewThrowError(Runtime::kNewReferenceError, message, 7031cb0ef41Sopenharmony_ci ast_value_factory()->empty_string(), pos); 7041cb0ef41Sopenharmony_ci } 7051cb0ef41Sopenharmony_ci 7061cb0ef41Sopenharmony_ci // Generate AST node that throws a SyntaxError with the given 7071cb0ef41Sopenharmony_ci // type. The first argument may be null (in the handle sense) in 7081cb0ef41Sopenharmony_ci // which case no arguments are passed to the constructor. 7091cb0ef41Sopenharmony_ci V8_INLINE Expression* NewThrowSyntaxError(MessageTemplate message, 7101cb0ef41Sopenharmony_ci const AstRawString* arg, int pos) { 7111cb0ef41Sopenharmony_ci return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos); 7121cb0ef41Sopenharmony_ci } 7131cb0ef41Sopenharmony_ci 7141cb0ef41Sopenharmony_ci // Generate AST node that throws a TypeError with the given 7151cb0ef41Sopenharmony_ci // type. Both arguments must be non-null (in the handle sense). 7161cb0ef41Sopenharmony_ci V8_INLINE Expression* NewThrowTypeError(MessageTemplate message, 7171cb0ef41Sopenharmony_ci const AstRawString* arg, int pos) { 7181cb0ef41Sopenharmony_ci return NewThrowError(Runtime::kNewTypeError, message, arg, pos); 7191cb0ef41Sopenharmony_ci } 7201cb0ef41Sopenharmony_ci 7211cb0ef41Sopenharmony_ci // Dummy implementation. The parser should never have a unidentifiable 7221cb0ef41Sopenharmony_ci // error. 7231cb0ef41Sopenharmony_ci V8_INLINE void ReportUnidentifiableError() { UNREACHABLE(); } 7241cb0ef41Sopenharmony_ci 7251cb0ef41Sopenharmony_ci const AstRawString* GetRawNameFromIdentifier(const AstRawString* arg) { 7261cb0ef41Sopenharmony_ci return arg; 7271cb0ef41Sopenharmony_ci } 7281cb0ef41Sopenharmony_ci 7291cb0ef41Sopenharmony_ci const AstRawString* PreParserIdentifierToAstRawString( 7301cb0ef41Sopenharmony_ci const PreParserIdentifier& arg) { 7311cb0ef41Sopenharmony_ci // This method definition is only needed due to an MSVC oddity that 7321cb0ef41Sopenharmony_ci // instantiates the method despite it being unused. See crbug.com/v8/12266 . 7331cb0ef41Sopenharmony_ci UNREACHABLE(); 7341cb0ef41Sopenharmony_ci } 7351cb0ef41Sopenharmony_ci 7361cb0ef41Sopenharmony_ci IterationStatement* AsIterationStatement(BreakableStatement* s) { 7371cb0ef41Sopenharmony_ci return s->AsIterationStatement(); 7381cb0ef41Sopenharmony_ci } 7391cb0ef41Sopenharmony_ci 7401cb0ef41Sopenharmony_ci void ReportUnexpectedTokenAt( 7411cb0ef41Sopenharmony_ci Scanner::Location location, Token::Value token, 7421cb0ef41Sopenharmony_ci MessageTemplate message = MessageTemplate::kUnexpectedToken); 7431cb0ef41Sopenharmony_ci 7441cb0ef41Sopenharmony_ci // "null" return type creators. 7451cb0ef41Sopenharmony_ci V8_INLINE static std::nullptr_t NullIdentifier() { return nullptr; } 7461cb0ef41Sopenharmony_ci V8_INLINE static std::nullptr_t NullExpression() { return nullptr; } 7471cb0ef41Sopenharmony_ci V8_INLINE static std::nullptr_t NullLiteralProperty() { return nullptr; } 7481cb0ef41Sopenharmony_ci V8_INLINE static ZonePtrList<Expression>* NullExpressionList() { 7491cb0ef41Sopenharmony_ci return nullptr; 7501cb0ef41Sopenharmony_ci } 7511cb0ef41Sopenharmony_ci V8_INLINE static ZonePtrList<Statement>* NullStatementList() { 7521cb0ef41Sopenharmony_ci return nullptr; 7531cb0ef41Sopenharmony_ci } 7541cb0ef41Sopenharmony_ci V8_INLINE static std::nullptr_t NullStatement() { return nullptr; } 7551cb0ef41Sopenharmony_ci V8_INLINE static std::nullptr_t NullBlock() { return nullptr; } 7561cb0ef41Sopenharmony_ci Expression* FailureExpression() { return factory()->FailureExpression(); } 7571cb0ef41Sopenharmony_ci 7581cb0ef41Sopenharmony_ci template <typename T> 7591cb0ef41Sopenharmony_ci V8_INLINE static bool IsNull(T subject) { 7601cb0ef41Sopenharmony_ci return subject == nullptr; 7611cb0ef41Sopenharmony_ci } 7621cb0ef41Sopenharmony_ci 7631cb0ef41Sopenharmony_ci V8_INLINE static bool IsIterationStatement(Statement* subject) { 7641cb0ef41Sopenharmony_ci return subject->AsIterationStatement() != nullptr; 7651cb0ef41Sopenharmony_ci } 7661cb0ef41Sopenharmony_ci 7671cb0ef41Sopenharmony_ci // Non-null empty string. 7681cb0ef41Sopenharmony_ci V8_INLINE const AstRawString* EmptyIdentifierString() const { 7691cb0ef41Sopenharmony_ci return ast_value_factory()->empty_string(); 7701cb0ef41Sopenharmony_ci } 7711cb0ef41Sopenharmony_ci 7721cb0ef41Sopenharmony_ci // Producing data during the recursive descent. 7731cb0ef41Sopenharmony_ci V8_INLINE const AstRawString* GetSymbol() const { 7741cb0ef41Sopenharmony_ci const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory()); 7751cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(result); 7761cb0ef41Sopenharmony_ci return result; 7771cb0ef41Sopenharmony_ci } 7781cb0ef41Sopenharmony_ci 7791cb0ef41Sopenharmony_ci V8_INLINE const AstRawString* GetIdentifier() const { return GetSymbol(); } 7801cb0ef41Sopenharmony_ci 7811cb0ef41Sopenharmony_ci V8_INLINE const AstRawString* GetNextSymbol() const { 7821cb0ef41Sopenharmony_ci return scanner()->NextSymbol(ast_value_factory()); 7831cb0ef41Sopenharmony_ci } 7841cb0ef41Sopenharmony_ci 7851cb0ef41Sopenharmony_ci V8_INLINE const AstRawString* GetNumberAsSymbol() const { 7861cb0ef41Sopenharmony_ci double double_value = scanner()->DoubleValue(); 7871cb0ef41Sopenharmony_ci char array[100]; 7881cb0ef41Sopenharmony_ci const char* string = 7891cb0ef41Sopenharmony_ci DoubleToCString(double_value, base::ArrayVector(array)); 7901cb0ef41Sopenharmony_ci return ast_value_factory()->GetOneByteString(string); 7911cb0ef41Sopenharmony_ci } 7921cb0ef41Sopenharmony_ci 7931cb0ef41Sopenharmony_ci const AstRawString* GetBigIntAsSymbol(); 7941cb0ef41Sopenharmony_ci 7951cb0ef41Sopenharmony_ci class ThisExpression* ThisExpression() { 7961cb0ef41Sopenharmony_ci UseThis(); 7971cb0ef41Sopenharmony_ci return factory()->ThisExpression(); 7981cb0ef41Sopenharmony_ci } 7991cb0ef41Sopenharmony_ci 8001cb0ef41Sopenharmony_ci class ThisExpression* NewThisExpression(int pos) { 8011cb0ef41Sopenharmony_ci UseThis(); 8021cb0ef41Sopenharmony_ci return factory()->NewThisExpression(pos); 8031cb0ef41Sopenharmony_ci } 8041cb0ef41Sopenharmony_ci 8051cb0ef41Sopenharmony_ci Expression* NewSuperPropertyReference(Scope* home_object_scope, int pos); 8061cb0ef41Sopenharmony_ci Expression* NewSuperCallReference(int pos); 8071cb0ef41Sopenharmony_ci Expression* NewTargetExpression(int pos); 8081cb0ef41Sopenharmony_ci Expression* ImportMetaExpression(int pos); 8091cb0ef41Sopenharmony_ci 8101cb0ef41Sopenharmony_ci Expression* ExpressionFromLiteral(Token::Value token, int pos); 8111cb0ef41Sopenharmony_ci 8121cb0ef41Sopenharmony_ci V8_INLINE VariableProxy* ExpressionFromPrivateName( 8131cb0ef41Sopenharmony_ci PrivateNameScopeIterator* private_name_scope, const AstRawString* name, 8141cb0ef41Sopenharmony_ci int start_position) { 8151cb0ef41Sopenharmony_ci VariableProxy* proxy = factory()->ast_node_factory()->NewVariableProxy( 8161cb0ef41Sopenharmony_ci name, NORMAL_VARIABLE, start_position); 8171cb0ef41Sopenharmony_ci private_name_scope->AddUnresolvedPrivateName(proxy); 8181cb0ef41Sopenharmony_ci return proxy; 8191cb0ef41Sopenharmony_ci } 8201cb0ef41Sopenharmony_ci 8211cb0ef41Sopenharmony_ci V8_INLINE VariableProxy* ExpressionFromIdentifier( 8221cb0ef41Sopenharmony_ci const AstRawString* name, int start_position, 8231cb0ef41Sopenharmony_ci InferName infer = InferName::kYes) { 8241cb0ef41Sopenharmony_ci if (infer == InferName::kYes) { 8251cb0ef41Sopenharmony_ci fni_.PushVariableName(name); 8261cb0ef41Sopenharmony_ci } 8271cb0ef41Sopenharmony_ci return expression_scope()->NewVariable(name, start_position); 8281cb0ef41Sopenharmony_ci } 8291cb0ef41Sopenharmony_ci 8301cb0ef41Sopenharmony_ci V8_INLINE void DeclareIdentifier(const AstRawString* name, 8311cb0ef41Sopenharmony_ci int start_position) { 8321cb0ef41Sopenharmony_ci expression_scope()->Declare(name, start_position); 8331cb0ef41Sopenharmony_ci } 8341cb0ef41Sopenharmony_ci 8351cb0ef41Sopenharmony_ci V8_INLINE Variable* DeclareCatchVariableName(Scope* scope, 8361cb0ef41Sopenharmony_ci const AstRawString* name) { 8371cb0ef41Sopenharmony_ci return scope->DeclareCatchVariableName(name); 8381cb0ef41Sopenharmony_ci } 8391cb0ef41Sopenharmony_ci 8401cb0ef41Sopenharmony_ci V8_INLINE ZonePtrList<Expression>* NewExpressionList(int size) const { 8411cb0ef41Sopenharmony_ci return zone()->New<ZonePtrList<Expression>>(size, zone()); 8421cb0ef41Sopenharmony_ci } 8431cb0ef41Sopenharmony_ci V8_INLINE ZonePtrList<ObjectLiteral::Property>* NewObjectPropertyList( 8441cb0ef41Sopenharmony_ci int size) const { 8451cb0ef41Sopenharmony_ci return zone()->New<ZonePtrList<ObjectLiteral::Property>>(size, zone()); 8461cb0ef41Sopenharmony_ci } 8471cb0ef41Sopenharmony_ci V8_INLINE ZonePtrList<ClassLiteral::Property>* NewClassPropertyList( 8481cb0ef41Sopenharmony_ci int size) const { 8491cb0ef41Sopenharmony_ci return zone()->New<ZonePtrList<ClassLiteral::Property>>(size, zone()); 8501cb0ef41Sopenharmony_ci } 8511cb0ef41Sopenharmony_ci V8_INLINE ZonePtrList<ClassLiteral::StaticElement>* NewClassStaticElementList( 8521cb0ef41Sopenharmony_ci int size) const { 8531cb0ef41Sopenharmony_ci return zone()->New<ZonePtrList<ClassLiteral::StaticElement>>(size, zone()); 8541cb0ef41Sopenharmony_ci } 8551cb0ef41Sopenharmony_ci V8_INLINE ZonePtrList<Statement>* NewStatementList(int size) const { 8561cb0ef41Sopenharmony_ci return zone()->New<ZonePtrList<Statement>>(size, zone()); 8571cb0ef41Sopenharmony_ci } 8581cb0ef41Sopenharmony_ci 8591cb0ef41Sopenharmony_ci Expression* NewV8Intrinsic(const AstRawString* name, 8601cb0ef41Sopenharmony_ci const ScopedPtrList<Expression>& args, int pos); 8611cb0ef41Sopenharmony_ci 8621cb0ef41Sopenharmony_ci Expression* NewV8RuntimeFunctionForFuzzing( 8631cb0ef41Sopenharmony_ci const Runtime::Function* function, const ScopedPtrList<Expression>& args, 8641cb0ef41Sopenharmony_ci int pos); 8651cb0ef41Sopenharmony_ci 8661cb0ef41Sopenharmony_ci V8_INLINE Statement* NewThrowStatement(Expression* exception, int pos) { 8671cb0ef41Sopenharmony_ci return factory()->NewExpressionStatement( 8681cb0ef41Sopenharmony_ci factory()->NewThrow(exception, pos), pos); 8691cb0ef41Sopenharmony_ci } 8701cb0ef41Sopenharmony_ci 8711cb0ef41Sopenharmony_ci V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, 8721cb0ef41Sopenharmony_ci Expression* pattern, 8731cb0ef41Sopenharmony_ci Expression* initializer, 8741cb0ef41Sopenharmony_ci int initializer_end_position, 8751cb0ef41Sopenharmony_ci bool is_rest) { 8761cb0ef41Sopenharmony_ci parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest); 8771cb0ef41Sopenharmony_ci auto parameter = 8781cb0ef41Sopenharmony_ci parameters->scope->zone()->New<ParserFormalParameters::Parameter>( 8791cb0ef41Sopenharmony_ci pattern, initializer, scanner()->location().beg_pos, 8801cb0ef41Sopenharmony_ci initializer_end_position, is_rest); 8811cb0ef41Sopenharmony_ci 8821cb0ef41Sopenharmony_ci parameters->params.Add(parameter); 8831cb0ef41Sopenharmony_ci } 8841cb0ef41Sopenharmony_ci 8851cb0ef41Sopenharmony_ci V8_INLINE void DeclareFormalParameters(ParserFormalParameters* parameters) { 8861cb0ef41Sopenharmony_ci bool is_simple = parameters->is_simple; 8871cb0ef41Sopenharmony_ci DeclarationScope* scope = parameters->scope; 8881cb0ef41Sopenharmony_ci if (!is_simple) scope->MakeParametersNonSimple(); 8891cb0ef41Sopenharmony_ci for (auto parameter : parameters->params) { 8901cb0ef41Sopenharmony_ci bool is_optional = parameter->initializer() != nullptr; 8911cb0ef41Sopenharmony_ci // If the parameter list is simple, declare the parameters normally with 8921cb0ef41Sopenharmony_ci // their names. If the parameter list is not simple, declare a temporary 8931cb0ef41Sopenharmony_ci // for each parameter - the corresponding named variable is declared by 8941cb0ef41Sopenharmony_ci // BuildParamerterInitializationBlock. 8951cb0ef41Sopenharmony_ci scope->DeclareParameter( 8961cb0ef41Sopenharmony_ci is_simple ? parameter->name() : ast_value_factory()->empty_string(), 8971cb0ef41Sopenharmony_ci is_simple ? VariableMode::kVar : VariableMode::kTemporary, 8981cb0ef41Sopenharmony_ci is_optional, parameter->is_rest(), ast_value_factory(), 8991cb0ef41Sopenharmony_ci parameter->position); 9001cb0ef41Sopenharmony_ci } 9011cb0ef41Sopenharmony_ci } 9021cb0ef41Sopenharmony_ci 9031cb0ef41Sopenharmony_ci void DeclareArrowFunctionFormalParameters( 9041cb0ef41Sopenharmony_ci ParserFormalParameters* parameters, Expression* params, 9051cb0ef41Sopenharmony_ci const Scanner::Location& params_loc); 9061cb0ef41Sopenharmony_ci 9071cb0ef41Sopenharmony_ci Expression* ExpressionListToExpression(const ScopedPtrList<Expression>& args); 9081cb0ef41Sopenharmony_ci 9091cb0ef41Sopenharmony_ci void SetFunctionNameFromPropertyName(LiteralProperty* property, 9101cb0ef41Sopenharmony_ci const AstRawString* name, 9111cb0ef41Sopenharmony_ci const AstRawString* prefix = nullptr); 9121cb0ef41Sopenharmony_ci void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, 9131cb0ef41Sopenharmony_ci const AstRawString* name, 9141cb0ef41Sopenharmony_ci const AstRawString* prefix = nullptr); 9151cb0ef41Sopenharmony_ci 9161cb0ef41Sopenharmony_ci void SetFunctionNameFromIdentifierRef(Expression* value, 9171cb0ef41Sopenharmony_ci Expression* identifier); 9181cb0ef41Sopenharmony_ci 9191cb0ef41Sopenharmony_ci V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { 9201cb0ef41Sopenharmony_ci ++use_counts_[feature]; 9211cb0ef41Sopenharmony_ci } 9221cb0ef41Sopenharmony_ci 9231cb0ef41Sopenharmony_ci // Returns true iff we're parsing the first function literal during 9241cb0ef41Sopenharmony_ci // CreateDynamicFunction(). 9251cb0ef41Sopenharmony_ci V8_INLINE bool ParsingDynamicFunctionDeclaration() const { 9261cb0ef41Sopenharmony_ci return parameters_end_pos_ != kNoSourcePosition; 9271cb0ef41Sopenharmony_ci } 9281cb0ef41Sopenharmony_ci 9291cb0ef41Sopenharmony_ci V8_INLINE void ConvertBinaryToNaryOperationSourceRange( 9301cb0ef41Sopenharmony_ci BinaryOperation* binary_op, NaryOperation* nary_op) { 9311cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 9321cb0ef41Sopenharmony_ci DCHECK_NULL(source_range_map_->Find(nary_op)); 9331cb0ef41Sopenharmony_ci 9341cb0ef41Sopenharmony_ci BinaryOperationSourceRanges* ranges = 9351cb0ef41Sopenharmony_ci static_cast<BinaryOperationSourceRanges*>( 9361cb0ef41Sopenharmony_ci source_range_map_->Find(binary_op)); 9371cb0ef41Sopenharmony_ci if (ranges == nullptr) return; 9381cb0ef41Sopenharmony_ci 9391cb0ef41Sopenharmony_ci SourceRange range = ranges->GetRange(SourceRangeKind::kRight); 9401cb0ef41Sopenharmony_ci source_range_map_->Insert( 9411cb0ef41Sopenharmony_ci nary_op, zone()->New<NaryOperationSourceRanges>(zone(), range)); 9421cb0ef41Sopenharmony_ci } 9431cb0ef41Sopenharmony_ci 9441cb0ef41Sopenharmony_ci V8_INLINE void AppendNaryOperationSourceRange(NaryOperation* node, 9451cb0ef41Sopenharmony_ci const SourceRange& range) { 9461cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 9471cb0ef41Sopenharmony_ci NaryOperationSourceRanges* ranges = 9481cb0ef41Sopenharmony_ci static_cast<NaryOperationSourceRanges*>(source_range_map_->Find(node)); 9491cb0ef41Sopenharmony_ci if (ranges == nullptr) return; 9501cb0ef41Sopenharmony_ci 9511cb0ef41Sopenharmony_ci ranges->AddRange(range); 9521cb0ef41Sopenharmony_ci DCHECK_EQ(node->subsequent_length(), ranges->RangeCount()); 9531cb0ef41Sopenharmony_ci } 9541cb0ef41Sopenharmony_ci 9551cb0ef41Sopenharmony_ci V8_INLINE void RecordBlockSourceRange(Block* node, 9561cb0ef41Sopenharmony_ci int32_t continuation_position) { 9571cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 9581cb0ef41Sopenharmony_ci source_range_map_->Insert( 9591cb0ef41Sopenharmony_ci node, zone()->New<BlockSourceRanges>(continuation_position)); 9601cb0ef41Sopenharmony_ci } 9611cb0ef41Sopenharmony_ci 9621cb0ef41Sopenharmony_ci V8_INLINE void RecordCaseClauseSourceRange(CaseClause* node, 9631cb0ef41Sopenharmony_ci const SourceRange& body_range) { 9641cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 9651cb0ef41Sopenharmony_ci source_range_map_->Insert(node, 9661cb0ef41Sopenharmony_ci zone()->New<CaseClauseSourceRanges>(body_range)); 9671cb0ef41Sopenharmony_ci } 9681cb0ef41Sopenharmony_ci 9691cb0ef41Sopenharmony_ci V8_INLINE void RecordConditionalSourceRange(Expression* node, 9701cb0ef41Sopenharmony_ci const SourceRange& then_range, 9711cb0ef41Sopenharmony_ci const SourceRange& else_range) { 9721cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 9731cb0ef41Sopenharmony_ci source_range_map_->Insert( 9741cb0ef41Sopenharmony_ci node->AsConditional(), 9751cb0ef41Sopenharmony_ci zone()->New<ConditionalSourceRanges>(then_range, else_range)); 9761cb0ef41Sopenharmony_ci } 9771cb0ef41Sopenharmony_ci 9781cb0ef41Sopenharmony_ci V8_INLINE void RecordFunctionLiteralSourceRange(FunctionLiteral* node) { 9791cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 9801cb0ef41Sopenharmony_ci source_range_map_->Insert(node, zone()->New<FunctionLiteralSourceRanges>()); 9811cb0ef41Sopenharmony_ci } 9821cb0ef41Sopenharmony_ci 9831cb0ef41Sopenharmony_ci V8_INLINE void RecordBinaryOperationSourceRange( 9841cb0ef41Sopenharmony_ci Expression* node, const SourceRange& right_range) { 9851cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 9861cb0ef41Sopenharmony_ci source_range_map_->Insert( 9871cb0ef41Sopenharmony_ci node->AsBinaryOperation(), 9881cb0ef41Sopenharmony_ci zone()->New<BinaryOperationSourceRanges>(right_range)); 9891cb0ef41Sopenharmony_ci } 9901cb0ef41Sopenharmony_ci 9911cb0ef41Sopenharmony_ci V8_INLINE void RecordJumpStatementSourceRange(Statement* node, 9921cb0ef41Sopenharmony_ci int32_t continuation_position) { 9931cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 9941cb0ef41Sopenharmony_ci source_range_map_->Insert( 9951cb0ef41Sopenharmony_ci static_cast<JumpStatement*>(node), 9961cb0ef41Sopenharmony_ci zone()->New<JumpStatementSourceRanges>(continuation_position)); 9971cb0ef41Sopenharmony_ci } 9981cb0ef41Sopenharmony_ci 9991cb0ef41Sopenharmony_ci V8_INLINE void RecordIfStatementSourceRange(Statement* node, 10001cb0ef41Sopenharmony_ci const SourceRange& then_range, 10011cb0ef41Sopenharmony_ci const SourceRange& else_range) { 10021cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 10031cb0ef41Sopenharmony_ci source_range_map_->Insert( 10041cb0ef41Sopenharmony_ci node->AsIfStatement(), 10051cb0ef41Sopenharmony_ci zone()->New<IfStatementSourceRanges>(then_range, else_range)); 10061cb0ef41Sopenharmony_ci } 10071cb0ef41Sopenharmony_ci 10081cb0ef41Sopenharmony_ci V8_INLINE void RecordIterationStatementSourceRange( 10091cb0ef41Sopenharmony_ci IterationStatement* node, const SourceRange& body_range) { 10101cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 10111cb0ef41Sopenharmony_ci source_range_map_->Insert( 10121cb0ef41Sopenharmony_ci node, zone()->New<IterationStatementSourceRanges>(body_range)); 10131cb0ef41Sopenharmony_ci } 10141cb0ef41Sopenharmony_ci 10151cb0ef41Sopenharmony_ci // Used to record source ranges of expressions associated with optional chain: 10161cb0ef41Sopenharmony_ci V8_INLINE void RecordExpressionSourceRange(Expression* node, 10171cb0ef41Sopenharmony_ci const SourceRange& right_range) { 10181cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 10191cb0ef41Sopenharmony_ci source_range_map_->Insert(node, 10201cb0ef41Sopenharmony_ci zone()->New<ExpressionSourceRanges>(right_range)); 10211cb0ef41Sopenharmony_ci } 10221cb0ef41Sopenharmony_ci 10231cb0ef41Sopenharmony_ci V8_INLINE void RecordSuspendSourceRange(Expression* node, 10241cb0ef41Sopenharmony_ci int32_t continuation_position) { 10251cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 10261cb0ef41Sopenharmony_ci source_range_map_->Insert( 10271cb0ef41Sopenharmony_ci static_cast<Suspend*>(node), 10281cb0ef41Sopenharmony_ci zone()->New<SuspendSourceRanges>(continuation_position)); 10291cb0ef41Sopenharmony_ci } 10301cb0ef41Sopenharmony_ci 10311cb0ef41Sopenharmony_ci V8_INLINE void RecordSwitchStatementSourceRange( 10321cb0ef41Sopenharmony_ci Statement* node, int32_t continuation_position) { 10331cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 10341cb0ef41Sopenharmony_ci source_range_map_->Insert( 10351cb0ef41Sopenharmony_ci node->AsSwitchStatement(), 10361cb0ef41Sopenharmony_ci zone()->New<SwitchStatementSourceRanges>(continuation_position)); 10371cb0ef41Sopenharmony_ci } 10381cb0ef41Sopenharmony_ci 10391cb0ef41Sopenharmony_ci V8_INLINE void RecordThrowSourceRange(Statement* node, 10401cb0ef41Sopenharmony_ci int32_t continuation_position) { 10411cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 10421cb0ef41Sopenharmony_ci ExpressionStatement* expr_stmt = static_cast<ExpressionStatement*>(node); 10431cb0ef41Sopenharmony_ci Throw* throw_expr = expr_stmt->expression()->AsThrow(); 10441cb0ef41Sopenharmony_ci source_range_map_->Insert( 10451cb0ef41Sopenharmony_ci throw_expr, zone()->New<ThrowSourceRanges>(continuation_position)); 10461cb0ef41Sopenharmony_ci } 10471cb0ef41Sopenharmony_ci 10481cb0ef41Sopenharmony_ci V8_INLINE void RecordTryCatchStatementSourceRange( 10491cb0ef41Sopenharmony_ci TryCatchStatement* node, const SourceRange& body_range) { 10501cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 10511cb0ef41Sopenharmony_ci source_range_map_->Insert( 10521cb0ef41Sopenharmony_ci node, zone()->New<TryCatchStatementSourceRanges>(body_range)); 10531cb0ef41Sopenharmony_ci } 10541cb0ef41Sopenharmony_ci 10551cb0ef41Sopenharmony_ci V8_INLINE void RecordTryFinallyStatementSourceRange( 10561cb0ef41Sopenharmony_ci TryFinallyStatement* node, const SourceRange& body_range) { 10571cb0ef41Sopenharmony_ci if (source_range_map_ == nullptr) return; 10581cb0ef41Sopenharmony_ci source_range_map_->Insert( 10591cb0ef41Sopenharmony_ci node, zone()->New<TryFinallyStatementSourceRanges>(body_range)); 10601cb0ef41Sopenharmony_ci } 10611cb0ef41Sopenharmony_ci 10621cb0ef41Sopenharmony_ci // Generate the next internal variable name for binding an exported namespace 10631cb0ef41Sopenharmony_ci // object (used to implement the "export * as" syntax). 10641cb0ef41Sopenharmony_ci const AstRawString* NextInternalNamespaceExportName(); 10651cb0ef41Sopenharmony_ci 10661cb0ef41Sopenharmony_ci ParseInfo* info() const { return info_; } 10671cb0ef41Sopenharmony_ci 10681cb0ef41Sopenharmony_ci std::vector<uint8_t>* preparse_data_buffer() { 10691cb0ef41Sopenharmony_ci return &preparse_data_buffer_; 10701cb0ef41Sopenharmony_ci } 10711cb0ef41Sopenharmony_ci 10721cb0ef41Sopenharmony_ci // Parser's private field members. 10731cb0ef41Sopenharmony_ci friend class PreParserZoneScope; // Uses reusable_preparser(). 10741cb0ef41Sopenharmony_ci friend class PreparseDataBuilder; // Uses preparse_data_buffer() 10751cb0ef41Sopenharmony_ci 10761cb0ef41Sopenharmony_ci LocalIsolate* local_isolate_; 10771cb0ef41Sopenharmony_ci ParseInfo* info_; 10781cb0ef41Sopenharmony_ci Handle<Script> script_; 10791cb0ef41Sopenharmony_ci Scanner scanner_; 10801cb0ef41Sopenharmony_ci Zone preparser_zone_; 10811cb0ef41Sopenharmony_ci PreParser* reusable_preparser_; 10821cb0ef41Sopenharmony_ci Mode mode_; 10831cb0ef41Sopenharmony_ci bool overall_parse_is_parked_ = false; 10841cb0ef41Sopenharmony_ci 10851cb0ef41Sopenharmony_ci MaybeHandle<FixedArray> maybe_wrapped_arguments_; 10861cb0ef41Sopenharmony_ci 10871cb0ef41Sopenharmony_ci SourceRangeMap* source_range_map_ = nullptr; 10881cb0ef41Sopenharmony_ci 10891cb0ef41Sopenharmony_ci friend class ParserTargetScope; 10901cb0ef41Sopenharmony_ci 10911cb0ef41Sopenharmony_ci ScriptCompiler::CompileOptions compile_options_; 10921cb0ef41Sopenharmony_ci 10931cb0ef41Sopenharmony_ci // For NextInternalNamespaceExportName(). 10941cb0ef41Sopenharmony_ci int number_of_named_namespace_exports_ = 0; 10951cb0ef41Sopenharmony_ci 10961cb0ef41Sopenharmony_ci // Other information which will be stored in Parser and moved to Isolate after 10971cb0ef41Sopenharmony_ci // parsing. 10981cb0ef41Sopenharmony_ci int use_counts_[v8::Isolate::kUseCounterFeatureCount]; 10991cb0ef41Sopenharmony_ci int total_preparse_skipped_; 11001cb0ef41Sopenharmony_ci bool allow_lazy_; 11011cb0ef41Sopenharmony_ci bool temp_zoned_; 11021cb0ef41Sopenharmony_ci ConsumedPreparseData* consumed_preparse_data_; 11031cb0ef41Sopenharmony_ci std::vector<uint8_t> preparse_data_buffer_; 11041cb0ef41Sopenharmony_ci 11051cb0ef41Sopenharmony_ci // If not kNoSourcePosition, indicates that the first function literal 11061cb0ef41Sopenharmony_ci // encountered is a dynamic function, see CreateDynamicFunction(). This field 11071cb0ef41Sopenharmony_ci // indicates the correct position of the ')' that closes the parameter list. 11081cb0ef41Sopenharmony_ci // After that ')' is encountered, this field is reset to kNoSourcePosition. 11091cb0ef41Sopenharmony_ci int parameters_end_pos_; 11101cb0ef41Sopenharmony_ci}; 11111cb0ef41Sopenharmony_ci 11121cb0ef41Sopenharmony_ci} // namespace internal 11131cb0ef41Sopenharmony_ci} // namespace v8 11141cb0ef41Sopenharmony_ci 11151cb0ef41Sopenharmony_ci#endif // V8_PARSING_PARSER_H_ 1116