#include "src/parsing/parser.h"
#include <algorithm>
#include <memory>
#include <optional>
#include "src/ast/ast-function-literal-id-reindexer.h"
#include "src/ast/ast-traversal-visitor.h"
#include "src/ast/ast.h"
#include "src/ast/source-range-ast-visitor.h"
#include "src/base/ieee754.h"
#include "src/base/overflowing-math.h"
#include "src/base/platform/platform.h"
#include "src/codegen/bailout-reason.h"
#include "src/common/globals.h"
#include "src/common/message-template.h"
#include "src/compiler-dispatcher/lazy-compile-dispatcher.h"
#include "src/heap/parked-scope.h"
#include "src/logging/counters.h"
#include "src/logging/log.h"
#include "src/logging/runtime-call-stats-scope.h"
#include "src/numbers/conversions-inl.h"
#include "src/objects/scope-info.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/rewriter.h"
#include "src/runtime/runtime.h"
#include "src/strings/char-predicates-inl.h"
#include "src/strings/string-stream.h"
#include "src/strings/unicode-inl.h"
#include "src/tracing/trace-event.h"
#include "src/zone/zone-list-inl.h"
namespace v8::internal {
FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
bool call_super, int pos) { … }
FunctionLiteral* Parser::MakeAutoAccessorGetter(VariableProxy* name_proxy,
const AstRawString* name,
bool is_static, int pos) { … }
FunctionLiteral* Parser::MakeAutoAccessorSetter(VariableProxy* name_proxy,
const AstRawString* name,
bool is_static, int pos) { … }
AutoAccessorInfo* Parser::NewAutoAccessorInfo(ClassScope* scope,
ClassInfo* class_info,
const AstRawString* name,
bool is_static, int pos) { … }
ClassLiteralProperty* Parser::NewClassLiteralPropertyWithAccessorInfo(
ClassScope* scope, ClassInfo* class_info, const AstRawString* name,
Expression* key, Expression* value, bool is_static, bool is_computed_name,
bool is_private, int pos) { … }
void Parser::ReportUnexpectedTokenAt(Scanner::Location location,
Token::Value token,
MessageTemplate message) { … }
bool Parser::ShortcutLiteralBinaryExpression(Expression** x, Expression* y,
Token::Value op, int pos) { … }
bool Parser::CollapseConditionalChain(Expression** x, Expression* cond,
Expression* then_expression,
Expression* else_expression, int pos,
const SourceRange& then_range) { … }
void Parser::AppendConditionalChainElse(Expression** x,
const SourceRange& else_range) { … }
bool Parser::CollapseNaryExpression(Expression** x, Expression* y,
Token::Value op, int pos,
const SourceRange& range) { … }
const AstRawString* Parser::GetBigIntAsSymbol() { … }
Expression* Parser::BuildUnaryExpression(Expression* expression,
Token::Value op, int pos) { … }
Expression* Parser::NewThrowError(Runtime::FunctionId id,
MessageTemplate message,
const AstRawString* arg, int pos) { … }
Expression* Parser::NewSuperPropertyReference(int pos) { … }
SuperCallReference* Parser::NewSuperCallReference(int pos) { … }
Expression* Parser::NewTargetExpression(int pos) { … }
Expression* Parser::ImportMetaExpression(int pos) { … }
Expression* Parser::ExpressionFromLiteral(Token::Value token, int pos) { … }
Expression* Parser::NewV8Intrinsic(const AstRawString* name,
const ScopedPtrList<Expression>& args,
int pos) { … }
Expression* Parser::NewV8RuntimeFunctionForFuzzing(
const Runtime::Function* function, const ScopedPtrList<Expression>& args,
int pos) { … }
Parser::Parser(LocalIsolate* local_isolate, ParseInfo* info)
: … { … }
void Parser::InitializeEmptyScopeChain(ParseInfo* info) { … }
template <typename IsolateT>
void Parser::DeserializeScopeChain(
IsolateT* isolate, ParseInfo* info,
MaybeHandle<ScopeInfo> maybe_outer_scope_info,
Scope::DeserializationMode mode) { … }
template void Parser::DeserializeScopeChain(
Isolate* isolate, ParseInfo* info,
MaybeHandle<ScopeInfo> maybe_outer_scope_info,
Scope::DeserializationMode mode);
template void Parser::DeserializeScopeChain(
LocalIsolate* isolate, ParseInfo* info,
MaybeHandle<ScopeInfo> maybe_outer_scope_info,
Scope::DeserializationMode mode);
namespace {
void MaybeProcessSourceRanges(ParseInfo* parse_info, Expression* root,
uintptr_t stack_limit_) { … }
}
void Parser::ParseProgram(Isolate* isolate, DirectHandle<Script> script,
ParseInfo* info,
MaybeHandle<ScopeInfo> maybe_outer_scope_info) { … }
FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) { … }
template <typename IsolateT>
void Parser::PostProcessParseResult(IsolateT* isolate, ParseInfo* info,
FunctionLiteral* literal) { … }
template void Parser::PostProcessParseResult(Isolate* isolate, ParseInfo* info,
FunctionLiteral* literal);
template void Parser::PostProcessParseResult(LocalIsolate* isolate,
ParseInfo* info,
FunctionLiteral* literal);
ZonePtrList<const AstRawString>* Parser::PrepareWrappedArguments(
Isolate* isolate, ParseInfo* info, Zone* zone) { … }
void Parser::ParseWrapped(Isolate* isolate, ParseInfo* info,
ScopedPtrList<Statement>* body,
DeclarationScope* outer_scope, Zone* zone) { … }
void Parser::ParseREPLProgram(ParseInfo* info, ScopedPtrList<Statement>* body,
DeclarationScope* scope) { … }
Expression* Parser::WrapREPLResult(Expression* value) { … }
void Parser::ParseFunction(Isolate* isolate, ParseInfo* info,
DirectHandle<SharedFunctionInfo> shared_info) { … }
FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
int start_position, int end_position,
int function_literal_id,
const AstRawString* raw_name) { … }
FunctionLiteral* Parser::ParseClassForMemberInitialization(
FunctionKind initalizer_kind, int initializer_pos, int initializer_id,
int initializer_end_pos, const AstRawString* class_name) { … }
Statement* Parser::ParseModuleItem() { … }
void Parser::ParseModuleItemList(ScopedPtrList<Statement>* body) { … }
const AstRawString* Parser::ParseModuleSpecifier() { … }
ZoneChunkList<Parser::ExportClauseData>* Parser::ParseExportClause(
Scanner::Location* reserved_loc,
Scanner::Location* string_literal_local_name_loc) { … }
const AstRawString* Parser::ParseExportSpecifierName() { … }
ZonePtrList<const Parser::NamedImport>* Parser::ParseNamedImports(int pos) { … }
ImportAttributes* Parser::ParseImportWithOrAssertClause() { … }
void Parser::ParseImportDeclaration() { … }
Statement* Parser::ParseExportDefault() { … }
const AstRawString* Parser::NextInternalNamespaceExportName() { … }
void Parser::ParseExportStar() { … }
Statement* Parser::ParseExportDeclaration() { … }
void Parser::DeclareUnboundVariable(const AstRawString* name, VariableMode mode,
InitializationFlag init, int pos) { … }
VariableProxy* Parser::DeclareBoundVariable(const AstRawString* name,
VariableMode mode, int pos) { … }
void Parser::DeclareAndBindVariable(VariableProxy* proxy, VariableKind kind,
VariableMode mode, Scope* scope,
bool* was_added, int initializer_position) { … }
Variable* Parser::DeclareVariable(const AstRawString* name, VariableKind kind,
VariableMode mode, InitializationFlag init,
Scope* scope, bool* was_added, int begin,
int end) { … }
void Parser::Declare(Declaration* declaration, const AstRawString* name,
VariableKind variable_kind, VariableMode mode,
InitializationFlag init, Scope* scope, bool* was_added,
int var_begin_pos, int var_end_pos) { … }
Statement* Parser::BuildInitializationBlock(
DeclarationParsingResult* parsing_result) { … }
Statement* Parser::DeclareFunction(const AstRawString* variable_name,
FunctionLiteral* function, VariableMode mode,
VariableKind kind, int beg_pos, int end_pos,
ZonePtrList<const AstRawString>* names) { … }
Statement* Parser::DeclareClass(const AstRawString* variable_name,
Expression* value,
ZonePtrList<const AstRawString>* names,
int class_token_pos, int end_pos) { … }
Statement* Parser::DeclareNative(const AstRawString* name, int pos) { … }
Block* Parser::IgnoreCompletion(Statement* statement) { … }
Statement* Parser::RewriteSwitchStatement(SwitchStatement* switch_statement,
Scope* scope) { … }
void Parser::InitializeVariables(
ScopedPtrList<Statement>* statements, VariableKind kind,
const DeclarationParsingResult::Declaration* declaration) { … }
Block* Parser::RewriteCatchPattern(CatchInfo* catch_info) { … }
void Parser::ReportVarRedeclarationIn(const AstRawString* name, Scope* scope) { … }
Statement* Parser::RewriteTryStatement(Block* try_block, Block* catch_block,
const SourceRange& catch_range,
Block* finally_block,
const SourceRange& finally_range,
const CatchInfo& catch_info, int pos) { … }
void Parser::ParseGeneratorFunctionBody(int pos, FunctionKind kind,
ScopedPtrList<Statement>* body) { … }
void Parser::ParseAndRewriteAsyncGeneratorFunctionBody(
int pos, FunctionKind kind, ScopedPtrList<Statement>* body) { … }
void Parser::DeclareFunctionNameVar(const AstRawString* function_name,
FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope) { … }
Block* Parser::RewriteForVarInLegacy(const ForInfo& for_info) { … }
void Parser::DesugarBindingInForEachStatement(ForInfo* for_info,
Block** body_block,
Expression** each_variable) { … }
Block* Parser::CreateForEachStatementTDZ(Block* init_block,
const ForInfo& for_info) { … }
Statement* Parser::DesugarLexicalBindingsInForStatement(
ForStatement* loop, Statement* init, Expression* cond, Statement* next,
Statement* body, Scope* inner_scope, const ForInfo& for_info) { … }
void ParserFormalParameters::ValidateDuplicate(Parser* parser) const { … }
void ParserFormalParameters::ValidateStrictMode(Parser* parser) const { … }
void Parser::AddArrowFunctionFormalParameters(
ParserFormalParameters* parameters, Expression* expr, int end_pos) { … }
void Parser::DeclareArrowFunctionFormalParameters(
ParserFormalParameters* parameters, Expression* expr,
const Scanner::Location& params_loc) { … }
void Parser::ReindexArrowFunctionFormalParameters(
ParserFormalParameters* parameters) { … }
void Parser::PrepareGeneratorVariables() { … }
FunctionLiteral* Parser::ParseFunctionLiteral(
const AstRawString* function_name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_pos, FunctionSyntaxKind function_syntax_kind,
LanguageMode language_mode,
ZonePtrList<const AstRawString>* arguments_for_wrapped_function) { … }
bool Parser::SkipFunction(const AstRawString* function_name, FunctionKind kind,
FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope, int* num_parameters,
int* function_length,
ProducedPreparseData** produced_preparse_data) { … }
Block* Parser::BuildParameterInitializationBlock(
const ParserFormalParameters& parameters) { … }
Scope* Parser::NewHiddenCatchScope() { … }
Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) { … }
void Parser::ParseFunction(
ScopedPtrList<Statement>* body, const AstRawString* function_name, int pos,
FunctionKind kind, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope, int* num_parameters, int* function_length,
bool* has_duplicate_parameters, int* expected_property_count,
int* suspend_count,
ZonePtrList<const AstRawString>* arguments_for_wrapped_function) { … }
void Parser::DeclareClassVariable(ClassScope* scope, const AstRawString* name,
ClassInfo* class_info, int class_token_pos) { … }
VariableProxy* Parser::CreateSyntheticContextVariableProxy(
ClassScope* scope, ClassInfo* class_info, const AstRawString* name,
bool is_static) { … }
VariableProxy* Parser::CreatePrivateNameVariable(ClassScope* scope,
VariableMode mode,
IsStaticFlag is_static_flag,
const AstRawString* name) { … }
void Parser::AddInstanceFieldOrStaticElement(ClassLiteralProperty* property,
ClassInfo* class_info,
bool is_static) { … }
void Parser::DeclarePublicClassField(ClassScope* scope,
ClassLiteralProperty* property,
bool is_static, bool is_computed_name,
ClassInfo* class_info) { … }
void Parser::DeclarePrivateClassMember(ClassScope* scope,
const AstRawString* property_name,
ClassLiteralProperty* property,
ClassLiteralProperty::Kind kind,
bool is_static, ClassInfo* class_info) { … }
void Parser::DeclarePublicClassMethod(const AstRawString* class_name,
ClassLiteralProperty* property,
bool is_constructor,
ClassInfo* class_info) { … }
void Parser::AddClassStaticBlock(Block* block, ClassInfo* class_info) { … }
FunctionLiteral* Parser::CreateInitializerFunction(
const AstRawString* class_name, DeclarationScope* scope,
int function_literal_id, Statement* initializer_stmt) { … }
FunctionLiteral* Parser::CreateStaticElementsInitializer(
const AstRawString* name, ClassInfo* class_info) { … }
FunctionLiteral* Parser::CreateInstanceMembersInitializer(
const AstRawString* name, ClassInfo* class_info) { … }
Expression* Parser::RewriteClassLiteral(ClassScope* block_scope,
const AstRawString* name,
ClassInfo* class_info, int pos) { … }
void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) { … }
void Parser::InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope) { … }
template <typename IsolateT>
void Parser::HandleSourceURLComments(IsolateT* isolate,
DirectHandle<Script> script) { … }
template void Parser::HandleSourceURLComments(Isolate* isolate,
DirectHandle<Script> script);
template void Parser::HandleSourceURLComments(LocalIsolate* isolate,
DirectHandle<Script> script);
void Parser::UpdateStatistics(Isolate* isolate, DirectHandle<Script> script) { … }
void Parser::UpdateStatistics(
DirectHandle<Script> script,
base::SmallVector<v8::Isolate::UseCounterFeature, 8>* use_counts,
int* preparse_skipped) { … }
void Parser::ParseOnBackground(LocalIsolate* isolate, ParseInfo* info,
DirectHandle<Script> script, int start_position,
int end_position, int function_literal_id) { … }
Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { … }
void Parser::AddTemplateSpan(TemplateLiteralState* state, bool should_cook,
bool tail) { … }
void Parser::AddTemplateExpression(TemplateLiteralState* state,
Expression* expression) { … }
Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
Expression* tag) { … }
void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) { … }
#if V8_ENABLE_WEBASSEMBLY
void Parser::SetAsmModule() { … }
#endif
Expression* Parser::ExpressionListToExpression(
const ScopedPtrList<Expression>& args) { … }
void Parser::SetFunctionNameFromPropertyName(LiteralProperty* property,
const AstRawString* name,
const AstRawString* prefix) { … }
void Parser::SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
const AstRawString* name,
const AstRawString* prefix) { … }
void Parser::SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier) { … }
void Parser::SetFunctionName(Expression* value, const AstRawString* name,
const AstRawString* prefix) { … }
}