diff options
author | Michaël Zasso <targos@protonmail.com> | 2020-10-15 20:17:08 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2020-10-18 20:16:47 +0200 |
commit | a1d639ba5de4ff34e34fb575fbb6cc1d41ec3cce (patch) | |
tree | abc7d41c12f1495b1208fa4449cb2508c92c5e85 /deps/v8/src/parsing | |
parent | 089d654dd85f8e548597329f60a41d6029260caa (diff) | |
download | node-new-a1d639ba5de4ff34e34fb575fbb6cc1d41ec3cce.tar.gz |
deps: update V8 to 8.6.395
PR-URL: https://github.com/nodejs/node/pull/35415
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/src/parsing')
-rw-r--r-- | deps/v8/src/parsing/literal-buffer.cc | 5 | ||||
-rw-r--r-- | deps/v8/src/parsing/parse-info.cc | 6 | ||||
-rw-r--r-- | deps/v8/src/parsing/parser-base.h | 65 | ||||
-rw-r--r-- | deps/v8/src/parsing/parser.cc | 28 | ||||
-rw-r--r-- | deps/v8/src/parsing/parser.h | 67 | ||||
-rw-r--r-- | deps/v8/src/parsing/parsing.cc | 24 | ||||
-rw-r--r-- | deps/v8/src/parsing/parsing.h | 29 | ||||
-rw-r--r-- | deps/v8/src/parsing/pending-compilation-error-handler.cc | 33 | ||||
-rw-r--r-- | deps/v8/src/parsing/pending-compilation-error-handler.h | 26 | ||||
-rw-r--r-- | deps/v8/src/parsing/preparse-data-impl.h | 9 | ||||
-rw-r--r-- | deps/v8/src/parsing/preparse-data.cc | 43 | ||||
-rw-r--r-- | deps/v8/src/parsing/preparse-data.h | 9 | ||||
-rw-r--r-- | deps/v8/src/parsing/preparser.cc | 6 | ||||
-rw-r--r-- | deps/v8/src/parsing/preparser.h | 10 | ||||
-rw-r--r-- | deps/v8/src/parsing/rewriter.h | 2 | ||||
-rw-r--r-- | deps/v8/src/parsing/scanner-inl.h | 2 | ||||
-rw-r--r-- | deps/v8/src/parsing/scanner.cc | 64 | ||||
-rw-r--r-- | deps/v8/src/parsing/scanner.h | 14 | ||||
-rw-r--r-- | deps/v8/src/parsing/token.h | 4 |
19 files changed, 251 insertions, 195 deletions
diff --git a/deps/v8/src/parsing/literal-buffer.cc b/deps/v8/src/parsing/literal-buffer.cc index 70b1903279..7d0188cad9 100644 --- a/deps/v8/src/parsing/literal-buffer.cc +++ b/deps/v8/src/parsing/literal-buffer.cc @@ -5,7 +5,7 @@ #include "src/parsing/literal-buffer.h" #include "src/execution/isolate.h" -#include "src/execution/off-thread-isolate.h" +#include "src/execution/local-isolate.h" #include "src/heap/factory.h" #include "src/utils/memcopy.h" @@ -21,8 +21,7 @@ Handle<String> LiteralBuffer::Internalize(LocalIsolate* isolate) const { } template Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const; -template Handle<String> LiteralBuffer::Internalize( - OffThreadIsolate* isolate) const; +template Handle<String> LiteralBuffer::Internalize(LocalIsolate* isolate) const; int LiteralBuffer::NewCapacity(int min_capacity) { return min_capacity < (kMaxGrowth / (kGrowthFactor - 1)) diff --git a/deps/v8/src/parsing/parse-info.cc b/deps/v8/src/parsing/parse-info.cc index 37432e05b7..5fd685505c 100644 --- a/deps/v8/src/parsing/parse-info.cc +++ b/deps/v8/src/parsing/parse-info.cc @@ -179,7 +179,7 @@ ParseInfo::ParseInfo(const UnoptimizedCompileFlags flags, UnoptimizedCompileState* state) : flags_(flags), state_(state), - zone_(std::make_unique<Zone>(state->allocator(), ZONE_NAME)), + zone_(std::make_unique<Zone>(state->allocator(), "parser-zone")), extension_(nullptr), script_scope_(nullptr), stack_limit_(0), @@ -271,7 +271,7 @@ template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) ScriptOriginOptions origin_options, NativesFlag natives); template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) Handle<Script> ParseInfo::CreateScript( - OffThreadIsolate* isolate, Handle<String> source, + LocalIsolate* isolate, Handle<String> source, MaybeHandle<FixedArray> maybe_wrapped_arguments, ScriptOriginOptions origin_options, NativesFlag natives); @@ -286,7 +286,7 @@ AstValueFactory* ParseInfo::GetOrCreateAstValueFactory() { void ParseInfo::AllocateSourceRangeMap() { DCHECK(flags().block_coverage_enabled()); DCHECK_NULL(source_range_map()); - set_source_range_map(new (zone()) SourceRangeMap(zone())); + set_source_range_map(zone()->New<SourceRangeMap>(zone())); } void ParseInfo::ResetCharacterStream() { character_stream_.reset(); } diff --git a/deps/v8/src/parsing/parser-base.h b/deps/v8/src/parsing/parser-base.h index 903ce2bb7f..754f9d72a0 100644 --- a/deps/v8/src/parsing/parser-base.h +++ b/deps/v8/src/parsing/parser-base.h @@ -328,7 +328,7 @@ class ParserBase { BlockState(Zone* zone, Scope** scope_stack) : BlockState(scope_stack, - new (zone) Scope(zone, *scope_stack, BLOCK_SCOPE)) {} + zone->New<Scope>(zone, *scope_stack, BLOCK_SCOPE)) {} ~BlockState() { *scope_stack_ = outer_scope_; } @@ -693,11 +693,14 @@ class ParserBase { // Add {label} to both {labels} and {own_labels}. if (*labels == nullptr) { DCHECK_NULL(*own_labels); - *labels = new (zone()) ZonePtrList<const AstRawString>(1, zone()); - *own_labels = new (zone()) ZonePtrList<const AstRawString>(1, zone()); + *labels = + zone()->template New<ZonePtrList<const AstRawString>>(1, zone()); + *own_labels = + zone()->template New<ZonePtrList<const AstRawString>>(1, zone()); } else { if (*own_labels == nullptr) { - *own_labels = new (zone()) ZonePtrList<const AstRawString>(1, zone()); + *own_labels = + zone()->template New<ZonePtrList<const AstRawString>>(1, zone()); } } (*labels)->Add(label, zone()); @@ -758,24 +761,24 @@ class ParserBase { } DeclarationScope* NewScriptScope(REPLMode repl_mode) const { - return new (zone()) - DeclarationScope(zone(), ast_value_factory(), repl_mode); + return zone()->template New<DeclarationScope>(zone(), ast_value_factory(), + repl_mode); } DeclarationScope* NewVarblockScope() const { - return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); + return zone()->template New<DeclarationScope>(zone(), scope(), BLOCK_SCOPE); } ModuleScope* NewModuleScope(DeclarationScope* parent) const { - return new (zone()) ModuleScope(parent, ast_value_factory()); + return zone()->template New<ModuleScope>(parent, ast_value_factory()); } DeclarationScope* NewEvalScope(Scope* parent) const { - return new (zone()) DeclarationScope(zone(), parent, EVAL_SCOPE); + return zone()->template New<DeclarationScope>(zone(), parent, EVAL_SCOPE); } ClassScope* NewClassScope(Scope* parent, bool is_anonymous) const { - return new (zone()) ClassScope(zone(), parent, is_anonymous); + return zone()->template New<ClassScope>(zone(), parent, is_anonymous); } Scope* NewScope(ScopeType scope_type) const { @@ -786,13 +789,13 @@ class ParserBase { // should automatically use scope() as parent, and be fine with // NewScope(ScopeType) above. Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type) const { - // Must always use the specific constructors for the blacklisted scope + // Must always use the specific constructors for the blocklisted scope // types. DCHECK_NE(FUNCTION_SCOPE, scope_type); DCHECK_NE(SCRIPT_SCOPE, scope_type); DCHECK_NE(MODULE_SCOPE, scope_type); DCHECK_NOT_NULL(parent); - return new (zone()) Scope(zone(), parent, scope_type); + return zone()->template New<Scope>(zone(), parent, scope_type); } // Creates a function scope that always allocates in zone(). The function @@ -802,8 +805,8 @@ class ParserBase { Zone* parse_zone = nullptr) const { DCHECK(ast_value_factory()); if (parse_zone == nullptr) parse_zone = zone(); - DeclarationScope* result = new (zone()) - DeclarationScope(parse_zone, scope(), FUNCTION_SCOPE, kind); + DeclarationScope* result = zone()->template New<DeclarationScope>( + parse_zone, scope(), FUNCTION_SCOPE, kind); // Record presence of an inner function scope function_state_->RecordFunctionOrEvalCall(); @@ -1400,9 +1403,10 @@ class ParserBase { // optimizations. This checks if expression is an eval call, and if yes, // forwards the information to scope. Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression, + bool is_optional_call, Scope* scope) { if (impl()->IsIdentifier(expression) && - impl()->IsEval(impl()->AsIdentifier(expression))) { + impl()->IsEval(impl()->AsIdentifier(expression)) && !is_optional_call) { function_state_->RecordFunctionOrEvalCall(); scope->RecordEvalCall(); @@ -1829,7 +1833,7 @@ ParserBase<Impl>::ParsePrimaryExpression() { case Token::THIS: { Consume(Token::THIS); - return impl()->ThisExpression(); + return impl()->NewThisExpression(beg_pos); } case Token::ASSIGN_DIV: @@ -2755,8 +2759,7 @@ ParserBase<Impl>::ParseAssignmentExpressionCoverGrammar() { Token::Value op = peek(); if (!Token::IsArrowOrAssignmentOp(op)) return expression; - if ((op == Token::ASSIGN_NULLISH || op == Token::ASSIGN_OR || - op == Token::ASSIGN_AND) && + if (Token::IsLogicalAssignmentOp(op) && !flags().allow_harmony_logical_assignment()) { return expression; } @@ -2830,13 +2833,8 @@ ParserBase<Impl>::ParseAssignmentExpressionCoverGrammar() { ExpressionT right = ParseAssignmentExpression(); - if (op == Token::ASSIGN) { - // We try to estimate the set of properties set by constructors. We define a - // new property whenever there is an assignment to a property of 'this'. We - // should probably only add properties if we haven't seen them before. - // Otherwise we'll probably overestimate the number of properties. - if (impl()->IsThisProperty(expression)) function_state_->AddProperty(); - + // Anonymous function name inference applies to =, ||=, &&=, and ??=. + if (op == Token::ASSIGN || Token::IsLogicalAssignmentOp(op)) { impl()->CheckAssigningFunctionLiteralToProperty(expression, right); // Check if the right hand side is a call to avoid inferring a @@ -2850,10 +2848,20 @@ ParserBase<Impl>::ParseAssignmentExpressionCoverGrammar() { impl()->SetFunctionNameFromIdentifierRef(right, expression); } else { + fni_.RemoveLastFunction(); + } + + if (op == Token::ASSIGN) { + // We try to estimate the set of properties set by constructors. We define a + // new property whenever there is an assignment to a property of 'this'. We + // should probably only add properties if we haven't seen them before. + // Otherwise we'll probably overestimate the number of properties. + if (impl()->IsThisProperty(expression)) function_state_->AddProperty(); + } else { + // Only initializers (i.e. no compound assignments) are allowed in patterns. expression_scope()->RecordPatternError( Scanner::Location(lhs_beg_pos, end_position()), MessageTemplate::kInvalidDestructuringTarget); - fni_.RemoveLastFunction(); } return factory()->NewAssignment(op, expression, right, op_position); @@ -3351,7 +3359,7 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) { // These calls are marked as potentially direct eval calls. Whether // they are actually direct calls to eval is determined at run time. Call::PossiblyEval is_possibly_eval = - CheckPossibleEvalCall(result, scope()); + CheckPossibleEvalCall(result, is_optional, scope()); if (has_spread) { result = impl()->SpreadCall(result, args, pos, is_possibly_eval, @@ -5277,7 +5285,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement( auto labels_copy = labels == nullptr ? labels - : new (zone()) ZonePtrList<const AstRawString>(*labels, zone()); + : zone()->template New<ZonePtrList<const AstRawString>>(*labels, + zone()); then_statement = ParseScopedStatement(labels_copy); } diff --git a/deps/v8/src/parsing/parser.cc b/deps/v8/src/parsing/parser.cc index 63b8b9c6f9..e8a8e60589 100644 --- a/deps/v8/src/parsing/parser.cc +++ b/deps/v8/src/parsing/parser.cc @@ -357,8 +357,8 @@ Expression* Parser::NewV8Intrinsic(const AstRawString* name, const Runtime::Function* function = Runtime::FunctionForName(name->raw_data(), name->length()); - // Be more premissive when fuzzing. Intrinsics are not supported. - if (FLAG_allow_natives_for_fuzzing) { + // Be more permissive when fuzzing. Intrinsics are not supported. + if (FLAG_fuzzing) { return NewV8RuntimeFunctionForFuzzing(function, args, pos); } @@ -392,13 +392,13 @@ Expression* Parser::NewV8Intrinsic(const AstRawString* name, Expression* Parser::NewV8RuntimeFunctionForFuzzing( const Runtime::Function* function, const ScopedPtrList<Expression>& args, int pos) { - CHECK(FLAG_allow_natives_for_fuzzing); + CHECK(FLAG_fuzzing); - // Intrinsics are not supported for fuzzing. Only allow whitelisted runtime + // Intrinsics are not supported for fuzzing. Only allow allowlisted runtime // functions. Also prevent later errors due to too few arguments and just // ignore this call. if (function == nullptr || - !Runtime::IsWhitelistedForFuzzing(function->function_id) || + !Runtime::IsAllowListedForFuzzing(function->function_id) || function->nargs > args.length()) { return factory()->NewUndefinedLiteral(kNoSourcePosition); } @@ -423,7 +423,7 @@ Parser::Parser(ParseInfo* info) info->runtime_call_stats(), info->logger(), info->flags(), true), info_(info), scanner_(info->character_stream(), flags()), - preparser_zone_(info->zone()->allocator(), ZONE_NAME), + preparser_zone_(info->zone()->allocator(), "pre-parser-zone"), reusable_preparser_(nullptr), mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. source_range_map_(info->source_range_map()), @@ -718,7 +718,7 @@ ZonePtrList<const AstRawString>* Parser::PrepareWrappedArguments( Handle<FixedArray> arguments = maybe_wrapped_arguments_.ToHandleChecked(); int arguments_length = arguments->length(); ZonePtrList<const AstRawString>* arguments_for_wrapped_function = - new (zone) ZonePtrList<const AstRawString>(arguments_length, zone); + zone->New<ZonePtrList<const AstRawString>>(arguments_length, zone); for (int i = 0; i < arguments_length; i++) { const AstRawString* argument_string = ast_value_factory()->GetString( Handle<String>(String::cast(arguments->get(i)), isolate)); @@ -1085,7 +1085,7 @@ ZoneChunkList<Parser::ExportClauseData>* Parser::ParseExportClause( // IdentifierName // IdentifierName 'as' IdentifierName ZoneChunkList<ExportClauseData>* export_data = - new (zone()) ZoneChunkList<ExportClauseData>(zone()); + zone()->New<ZoneChunkList<ExportClauseData>>(zone()); Expect(Token::LBRACE); @@ -1138,7 +1138,7 @@ ZonePtrList<const Parser::NamedImport>* Parser::ParseNamedImports(int pos) { Expect(Token::LBRACE); - auto result = new (zone()) ZonePtrList<const NamedImport>(1, zone()); + auto result = zone()->New<ZonePtrList<const NamedImport>>(1, zone()); while (peek() != Token::RBRACE) { const AstRawString* import_name = ParsePropertyName(); const AstRawString* local_name = import_name; @@ -1163,7 +1163,7 @@ ZonePtrList<const Parser::NamedImport>* Parser::ParseNamedImports(int pos) { kNeedsInitialization, position()); NamedImport* import = - new (zone()) NamedImport(import_name, local_name, location); + zone()->New<NamedImport>(import_name, local_name, location); result->Add(import, zone()); if (peek() == Token::RBRACE) break; @@ -3092,10 +3092,12 @@ void Parser::HandleSourceURLComments(LocalIsolate* isolate, template void Parser::HandleSourceURLComments(Isolate* isolate, Handle<Script> script); -template void Parser::HandleSourceURLComments(OffThreadIsolate* isolate, +template void Parser::HandleSourceURLComments(LocalIsolate* isolate, Handle<Script> script); void Parser::UpdateStatistics(Isolate* isolate, Handle<Script> script) { + CHECK_NOT_NULL(isolate); + // Move statistics to Isolate. for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; ++feature) { @@ -3148,7 +3150,7 @@ void Parser::ParseOnBackground(ParseInfo* info, int start_position, } Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { - return new (zone()) TemplateLiteral(zone(), pos); + return zone()->New<TemplateLiteral>(zone(), pos); } void Parser::AddTemplateSpan(TemplateLiteralState* state, bool should_cook, @@ -3191,7 +3193,7 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start, // Call TagFn ScopedPtrList<Expression> call_args(pointer_buffer()); call_args.Add(template_object); - call_args.AddAll(*expressions); + call_args.AddAll(expressions->ToConstVector()); return factory()->NewTaggedTemplate(tag, call_args, pos); } } diff --git a/deps/v8/src/parsing/parser.h b/deps/v8/src/parsing/parser.h index 472c9a71ab..46abe16d4f 100644 --- a/deps/v8/src/parsing/parser.h +++ b/deps/v8/src/parsing/parser.h @@ -170,10 +170,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { friend class i::ArrowHeadParsingScope<ParserTypes<Parser>>; friend bool v8::internal::parsing::ParseProgram( ParseInfo*, Handle<Script>, MaybeHandle<ScopeInfo> maybe_outer_scope_info, - Isolate*, parsing::ReportErrorsAndStatisticsMode stats_mode); + Isolate*, parsing::ReportStatisticsMode stats_mode); friend bool v8::internal::parsing::ParseFunction( ParseInfo*, Handle<SharedFunctionInfo> shared_info, Isolate*, - parsing::ReportErrorsAndStatisticsMode stats_mode); + parsing::ReportStatisticsMode stats_mode); bool AllowsLazyParsingWithoutUnresolvedVariables() const { return !MaybeParsingArrowhead() && @@ -541,10 +541,14 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { return property != nullptr && property->obj()->IsThisExpression(); } - // Returns true if the expression is of type "obj.#foo". + // Returns true if the expression is of type "obj.#foo" or "obj?.#foo". V8_INLINE static bool IsPrivateReference(Expression* expression) { DCHECK_NOT_NULL(expression); Property* property = expression->AsProperty(); + if (expression->IsOptionalChain()) { + Expression* expr_inner = expression->AsOptionalChain()->expression(); + property = expr_inner->AsProperty(); + } return property != nullptr && property->IsPrivateReference(); } @@ -782,6 +786,11 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { return factory()->ThisExpression(); } + class ThisExpression* NewThisExpression(int pos) { + UseThis(); + return factory()->NewThisExpression(pos); + } + Expression* NewSuperPropertyReference(int pos); Expression* NewSuperCallReference(int pos); Expression* NewTargetExpression(int pos); @@ -818,18 +827,18 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { } V8_INLINE ZonePtrList<Expression>* NewExpressionList(int size) const { - return new (zone()) ZonePtrList<Expression>(size, zone()); + return zone()->New<ZonePtrList<Expression>>(size, zone()); } V8_INLINE ZonePtrList<ObjectLiteral::Property>* NewObjectPropertyList( int size) const { - return new (zone()) ZonePtrList<ObjectLiteral::Property>(size, zone()); + return zone()->New<ZonePtrList<ObjectLiteral::Property>>(size, zone()); } V8_INLINE ZonePtrList<ClassLiteral::Property>* NewClassPropertyList( int size) const { - return new (zone()) ZonePtrList<ClassLiteral::Property>(size, zone()); + return zone()->New<ZonePtrList<ClassLiteral::Property>>(size, zone()); } V8_INLINE ZonePtrList<Statement>* NewStatementList(int size) const { - return new (zone()) ZonePtrList<Statement>(size, zone()); + return zone()->New<ZonePtrList<Statement>>(size, zone()); } Expression* NewV8Intrinsic(const AstRawString* name, @@ -850,10 +859,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { int initializer_end_position, bool is_rest) { parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest); - auto parameter = new (parameters->scope->zone()) - ParserFormalParameters::Parameter(pattern, initializer, - scanner()->location().beg_pos, - initializer_end_position, is_rest); + auto parameter = + parameters->scope->zone()->New<ParserFormalParameters::Parameter>( + pattern, initializer, scanner()->location().beg_pos, + initializer_end_position, is_rest); parameters->params.Add(parameter); } @@ -914,7 +923,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { SourceRange range = ranges->GetRange(SourceRangeKind::kRight); source_range_map_->Insert( - nary_op, new (zone()) NaryOperationSourceRanges(zone(), range)); + nary_op, zone()->New<NaryOperationSourceRanges>(zone(), range)); } V8_INLINE void AppendNaryOperationSourceRange(NaryOperation* node, @@ -932,14 +941,14 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { int32_t continuation_position) { if (source_range_map_ == nullptr) return; source_range_map_->Insert( - node, new (zone()) BlockSourceRanges(continuation_position)); + node, zone()->New<BlockSourceRanges>(continuation_position)); } V8_INLINE void RecordCaseClauseSourceRange(CaseClause* node, const SourceRange& body_range) { if (source_range_map_ == nullptr) return; source_range_map_->Insert(node, - new (zone()) CaseClauseSourceRanges(body_range)); + zone()->New<CaseClauseSourceRanges>(body_range)); } V8_INLINE void RecordConditionalSourceRange(Expression* node, @@ -948,20 +957,20 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { if (source_range_map_ == nullptr) return; source_range_map_->Insert( node->AsConditional(), - new (zone()) ConditionalSourceRanges(then_range, else_range)); + zone()->New<ConditionalSourceRanges>(then_range, else_range)); } V8_INLINE void RecordFunctionLiteralSourceRange(FunctionLiteral* node) { if (source_range_map_ == nullptr) return; - source_range_map_->Insert(node, new (zone()) FunctionLiteralSourceRanges); + source_range_map_->Insert(node, zone()->New<FunctionLiteralSourceRanges>()); } V8_INLINE void RecordBinaryOperationSourceRange( Expression* node, const SourceRange& right_range) { if (source_range_map_ == nullptr) return; - source_range_map_->Insert(node->AsBinaryOperation(), - new (zone()) - BinaryOperationSourceRanges(right_range)); + source_range_map_->Insert( + node->AsBinaryOperation(), + zone()->New<BinaryOperationSourceRanges>(right_range)); } V8_INLINE void RecordJumpStatementSourceRange(Statement* node, @@ -969,7 +978,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { if (source_range_map_ == nullptr) return; source_range_map_->Insert( static_cast<JumpStatement*>(node), - new (zone()) JumpStatementSourceRanges(continuation_position)); + zone()->New<JumpStatementSourceRanges>(continuation_position)); } V8_INLINE void RecordIfStatementSourceRange(Statement* node, @@ -978,22 +987,22 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { if (source_range_map_ == nullptr) return; source_range_map_->Insert( node->AsIfStatement(), - new (zone()) IfStatementSourceRanges(then_range, else_range)); + zone()->New<IfStatementSourceRanges>(then_range, else_range)); } V8_INLINE void RecordIterationStatementSourceRange( IterationStatement* node, const SourceRange& body_range) { if (source_range_map_ == nullptr) return; source_range_map_->Insert( - node, new (zone()) IterationStatementSourceRanges(body_range)); + node, zone()->New<IterationStatementSourceRanges>(body_range)); } V8_INLINE void RecordSuspendSourceRange(Expression* node, int32_t continuation_position) { if (source_range_map_ == nullptr) return; - source_range_map_->Insert(static_cast<Suspend*>(node), - new (zone()) - SuspendSourceRanges(continuation_position)); + source_range_map_->Insert( + static_cast<Suspend*>(node), + zone()->New<SuspendSourceRanges>(continuation_position)); } V8_INLINE void RecordSwitchStatementSourceRange( @@ -1001,7 +1010,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { if (source_range_map_ == nullptr) return; source_range_map_->Insert( node->AsSwitchStatement(), - new (zone()) SwitchStatementSourceRanges(continuation_position)); + zone()->New<SwitchStatementSourceRanges>(continuation_position)); } V8_INLINE void RecordThrowSourceRange(Statement* node, @@ -1010,21 +1019,21 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ExpressionStatement* expr_stmt = static_cast<ExpressionStatement*>(node); Throw* throw_expr = expr_stmt->expression()->AsThrow(); source_range_map_->Insert( - throw_expr, new (zone()) ThrowSourceRanges(continuation_position)); + throw_expr, zone()->New<ThrowSourceRanges>(continuation_position)); } V8_INLINE void RecordTryCatchStatementSourceRange( TryCatchStatement* node, const SourceRange& body_range) { if (source_range_map_ == nullptr) return; source_range_map_->Insert( - node, new (zone()) TryCatchStatementSourceRanges(body_range)); + node, zone()->New<TryCatchStatementSourceRanges>(body_range)); } V8_INLINE void RecordTryFinallyStatementSourceRange( TryFinallyStatement* node, const SourceRange& body_range) { if (source_range_map_ == nullptr) return; source_range_map_->Insert( - node, new (zone()) TryFinallyStatementSourceRanges(body_range)); + node, zone()->New<TryFinallyStatementSourceRanges>(body_range)); } // Generate the next internal variable name for binding an exported namespace diff --git a/deps/v8/src/parsing/parsing.cc b/deps/v8/src/parsing/parsing.cc index e126874d7d..53f6cf045b 100644 --- a/deps/v8/src/parsing/parsing.cc +++ b/deps/v8/src/parsing/parsing.cc @@ -7,6 +7,7 @@ #include <memory> #include "src/ast/ast.h" +#include "src/base/v8-fallthrough.h" #include "src/execution/vm-state-inl.h" #include "src/handles/maybe-handles.h" #include "src/objects/objects-inl.h" @@ -24,14 +25,13 @@ namespace { void MaybeReportErrorsAndStatistics(ParseInfo* info, Handle<Script> script, Isolate* isolate, Parser* parser, - ReportErrorsAndStatisticsMode mode) { - if (mode == ReportErrorsAndStatisticsMode::kYes) { - if (info->literal() == nullptr) { - info->pending_error_handler()->PrepareErrors(isolate, - info->ast_value_factory()); - info->pending_error_handler()->ReportErrors(isolate, script); - } - parser->UpdateStatistics(isolate, script); + ReportStatisticsMode mode) { + switch (mode) { + case ReportStatisticsMode::kYes: + parser->UpdateStatistics(isolate, script); + break; + case ReportStatisticsMode::kNo: + break; } } @@ -39,7 +39,7 @@ void MaybeReportErrorsAndStatistics(ParseInfo* info, Handle<Script> script, bool ParseProgram(ParseInfo* info, Handle<Script> script, MaybeHandle<ScopeInfo> maybe_outer_scope_info, - Isolate* isolate, ReportErrorsAndStatisticsMode mode) { + Isolate* isolate, ReportStatisticsMode mode) { DCHECK(info->flags().is_toplevel()); DCHECK_NULL(info->literal()); @@ -62,12 +62,12 @@ bool ParseProgram(ParseInfo* info, Handle<Script> script, } bool ParseProgram(ParseInfo* info, Handle<Script> script, Isolate* isolate, - ReportErrorsAndStatisticsMode mode) { + ReportStatisticsMode mode) { return ParseProgram(info, script, kNullMaybeHandle, isolate, mode); } bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info, - Isolate* isolate, ReportErrorsAndStatisticsMode mode) { + Isolate* isolate, ReportStatisticsMode mode) { DCHECK(!info->flags().is_toplevel()); DCHECK(!shared_info.is_null()); DCHECK_NULL(info->literal()); @@ -93,7 +93,7 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info, } bool ParseAny(ParseInfo* info, Handle<SharedFunctionInfo> shared_info, - Isolate* isolate, ReportErrorsAndStatisticsMode mode) { + Isolate* isolate, ReportStatisticsMode mode) { DCHECK(!shared_info.is_null()); if (info->flags().is_toplevel()) { MaybeHandle<ScopeInfo> maybe_outer_scope_info; diff --git a/deps/v8/src/parsing/parsing.h b/deps/v8/src/parsing/parsing.h index f235017139..f105b630d4 100644 --- a/deps/v8/src/parsing/parsing.h +++ b/deps/v8/src/parsing/parsing.h @@ -15,36 +15,37 @@ class SharedFunctionInfo; namespace parsing { -enum class ReportErrorsAndStatisticsMode { kYes, kNo }; +enum class ReportStatisticsMode { kYes, kNo }; // Parses the top-level source code represented by the parse info and sets its // function literal. Returns false (and deallocates any allocated AST nodes) if // parsing failed. -V8_EXPORT_PRIVATE bool ParseProgram( - ParseInfo* info, Handle<Script> script, Isolate* isolate, - ReportErrorsAndStatisticsMode mode = ReportErrorsAndStatisticsMode::kYes); +V8_EXPORT_PRIVATE bool ParseProgram(ParseInfo* info, Handle<Script> script, + Isolate* isolate, + ReportStatisticsMode mode); // Parses the top-level source code represented by the parse info and sets its // function literal. Allows passing an |outer_scope| for programs that exist in // another scope (e.g. eval). Returns false (and deallocates any allocated AST // nodes) if parsing failed. -V8_EXPORT_PRIVATE bool ParseProgram( - ParseInfo* info, Handle<Script> script, MaybeHandle<ScopeInfo> outer_scope, - Isolate* isolate, - ReportErrorsAndStatisticsMode mode = ReportErrorsAndStatisticsMode::kYes); +V8_EXPORT_PRIVATE bool ParseProgram(ParseInfo* info, Handle<Script> script, + MaybeHandle<ScopeInfo> outer_scope, + Isolate* isolate, + ReportStatisticsMode mode); // Like ParseProgram but for an individual function which already has a // allocated shared function info. -V8_EXPORT_PRIVATE bool ParseFunction( - ParseInfo* info, Handle<SharedFunctionInfo> shared_info, Isolate* isolate, - ReportErrorsAndStatisticsMode mode = ReportErrorsAndStatisticsMode::kYes); +V8_EXPORT_PRIVATE bool ParseFunction(ParseInfo* info, + Handle<SharedFunctionInfo> shared_info, + Isolate* isolate, + ReportStatisticsMode mode); // If you don't know whether info->is_toplevel() is true or not, use this method // to dispatch to either of the above functions. Prefer to use the above methods // whenever possible. -V8_EXPORT_PRIVATE bool ParseAny( - ParseInfo* info, Handle<SharedFunctionInfo> shared_info, Isolate* isolate, - ReportErrorsAndStatisticsMode mode = ReportErrorsAndStatisticsMode::kYes); +V8_EXPORT_PRIVATE bool ParseAny(ParseInfo* info, + Handle<SharedFunctionInfo> shared_info, + Isolate* isolate, ReportStatisticsMode mode); } // namespace parsing } // namespace internal diff --git a/deps/v8/src/parsing/pending-compilation-error-handler.cc b/deps/v8/src/parsing/pending-compilation-error-handler.cc index f131b7ad8e..dccd6dba77 100644 --- a/deps/v8/src/parsing/pending-compilation-error-handler.cc +++ b/deps/v8/src/parsing/pending-compilation-error-handler.cc @@ -5,13 +5,13 @@ #include "src/parsing/pending-compilation-error-handler.h" #include "src/ast/ast-value-factory.h" +#include "src/base/export-template.h" #include "src/base/logging.h" #include "src/debug/debug.h" #include "src/execution/isolate.h" #include "src/execution/messages.h" -#include "src/execution/off-thread-isolate.h" #include "src/handles/handles.h" -#include "src/heap/off-thread-factory-inl.h" +#include "src/heap/local-heap-inl.h" #include "src/objects/objects-inl.h" namespace v8 { @@ -20,17 +20,15 @@ namespace internal { void PendingCompilationErrorHandler::MessageDetails::SetString( Handle<String> string, Isolate* isolate) { DCHECK_NE(type_, kMainThreadHandle); - DCHECK_NE(type_, kOffThreadTransferHandle); type_ = kMainThreadHandle; arg_handle_ = string; } void PendingCompilationErrorHandler::MessageDetails::SetString( - Handle<String> string, OffThreadIsolate* isolate) { + Handle<String> string, LocalIsolate* isolate) { DCHECK_NE(type_, kMainThreadHandle); - DCHECK_NE(type_, kOffThreadTransferHandle); - type_ = kOffThreadTransferHandle; - arg_transfer_handle_ = isolate->TransferHandle(string); + type_ = kMainThreadHandle; + arg_handle_ = isolate->heap()->NewPersistentHandle(string); } template <typename LocalIsolate> @@ -39,15 +37,18 @@ void PendingCompilationErrorHandler::MessageDetails::Prepare( switch (type_) { case kAstRawString: return SetString(arg_->string(), isolate); + case kNone: case kConstCharString: // We can delay allocation until ArgumentString(isolate). // TODO(leszeks): We don't actually have to transfer this string, since // it's a root. return; + case kMainThreadHandle: - case kOffThreadTransferHandle: - UNREACHABLE(); + // The message details might already be prepared, so skip them if this is + // the case. + return; } } @@ -56,8 +57,6 @@ Handle<String> PendingCompilationErrorHandler::MessageDetails::ArgumentString( switch (type_) { case kMainThreadHandle: return arg_handle_; - case kOffThreadTransferHandle: - return arg_transfer_handle_.ToHandle(); case kNone: return isolate->factory()->undefined_string(); case kConstCharString: @@ -112,7 +111,7 @@ void PendingCompilationErrorHandler::PrepareWarnings(LocalIsolate* isolate) { } template void PendingCompilationErrorHandler::PrepareWarnings(Isolate* isolate); template void PendingCompilationErrorHandler::PrepareWarnings( - OffThreadIsolate* isolate); + LocalIsolate* isolate); void PendingCompilationErrorHandler::ReportWarnings( Isolate* isolate, Handle<Script> script) const { @@ -139,10 +138,12 @@ void PendingCompilationErrorHandler::PrepareErrors( ast_value_factory->Internalize(isolate); error_details_.Prepare(isolate); } -template void PendingCompilationErrorHandler::PrepareErrors( - Isolate* isolate, AstValueFactory* ast_value_factory); -template void PendingCompilationErrorHandler::PrepareErrors( - OffThreadIsolate* isolate, AstValueFactory* ast_value_factory); +template EXPORT_TEMPLATE_DEFINE( + V8_EXPORT_PRIVATE) void PendingCompilationErrorHandler:: + PrepareErrors(Isolate* isolate, AstValueFactory* ast_value_factory); +template EXPORT_TEMPLATE_DEFINE( + V8_EXPORT_PRIVATE) void PendingCompilationErrorHandler:: + PrepareErrors(LocalIsolate* isolate, AstValueFactory* ast_value_factory); void PendingCompilationErrorHandler::ReportErrors(Isolate* isolate, Handle<Script> script) const { diff --git a/deps/v8/src/parsing/pending-compilation-error-handler.h b/deps/v8/src/parsing/pending-compilation-error-handler.h index 4d15ac91ca..b71e4fcdc3 100644 --- a/deps/v8/src/parsing/pending-compilation-error-handler.h +++ b/deps/v8/src/parsing/pending-compilation-error-handler.h @@ -7,10 +7,10 @@ #include <forward_list> +#include "src/base/export-template.h" #include "src/base/macros.h" #include "src/common/globals.h" #include "src/common/message-template.h" -#include "src/execution/off-thread-isolate.h" #include "src/handles/handles.h" namespace v8 { @@ -49,8 +49,10 @@ class PendingCompilationErrorHandler { // Handle errors detected during parsing. template <typename LocalIsolate> + EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) void PrepareErrors(LocalIsolate* isolate, AstValueFactory* ast_value_factory); - void ReportErrors(Isolate* isolate, Handle<Script> script) const; + V8_EXPORT_PRIVATE void ReportErrors(Isolate* isolate, + Handle<Script> script) const; // Handle warnings detected during compilation. template <typename LocalIsolate> @@ -103,16 +105,10 @@ class PendingCompilationErrorHandler { void Prepare(LocalIsolate* isolate); private: - enum Type { - kNone, - kAstRawString, - kConstCharString, - kMainThreadHandle, - kOffThreadTransferHandle - }; + enum Type { kNone, kAstRawString, kConstCharString, kMainThreadHandle }; void SetString(Handle<String> string, Isolate* isolate); - void SetString(Handle<String> string, OffThreadIsolate* isolate); + void SetString(Handle<String> string, LocalIsolate* isolate); int start_position_; int end_position_; @@ -121,7 +117,6 @@ class PendingCompilationErrorHandler { const AstRawString* arg_; const char* char_arg_; Handle<String> arg_handle_; - OffThreadTransferHandle<String> arg_transfer_handle_; }; Type type_; }; @@ -139,6 +134,15 @@ class PendingCompilationErrorHandler { DISALLOW_COPY_AND_ASSIGN(PendingCompilationErrorHandler); }; +extern template void PendingCompilationErrorHandler::PrepareErrors( + Isolate* isolate, AstValueFactory* ast_value_factory); +extern template void PendingCompilationErrorHandler::PrepareErrors( + LocalIsolate* isolate, AstValueFactory* ast_value_factory); +extern template void PendingCompilationErrorHandler::PrepareWarnings( + Isolate* isolate); +extern template void PendingCompilationErrorHandler::PrepareWarnings( + LocalIsolate* isolate); + } // namespace internal } // namespace v8 #endif // V8_PARSING_PENDING_COMPILATION_ERROR_HANDLER_H_ diff --git a/deps/v8/src/parsing/preparse-data-impl.h b/deps/v8/src/parsing/preparse-data-impl.h index 707e76236d..4d29c2b7ef 100644 --- a/deps/v8/src/parsing/preparse-data-impl.h +++ b/deps/v8/src/parsing/preparse-data-impl.h @@ -5,11 +5,10 @@ #ifndef V8_PARSING_PREPARSE_DATA_IMPL_H_ #define V8_PARSING_PREPARSE_DATA_IMPL_H_ -#include "src/parsing/preparse-data.h" - #include <memory> #include "src/common/assert-scope.h" +#include "src/parsing/preparse-data.h" namespace v8 { namespace internal { @@ -37,8 +36,6 @@ class BaseConsumedPreparseData : public ConsumedPreparseData { public: class ByteData : public PreparseByteDataConstants { public: - ByteData() {} - // Reading from the ByteData is only allowed when a ReadingScope is on the // stack. This ensures that we have a DisallowHeapAllocation in place // whenever ByteData holds a raw pointer into the heap. @@ -202,7 +199,7 @@ class ZonePreparseData : public ZoneObject { int child_length); Handle<PreparseData> Serialize(Isolate* isolate); - Handle<PreparseData> Serialize(OffThreadIsolate* isolate); + Handle<PreparseData> Serialize(LocalIsolate* isolate); int children_length() const { return static_cast<int>(children_.size()); } @@ -225,7 +222,7 @@ class ZonePreparseData : public ZoneObject { ZonePreparseData* PreparseDataBuilder::ByteData::CopyToZone( Zone* zone, int children_length) { DCHECK(is_finalized_); - return new (zone) ZonePreparseData(zone, &zone_byte_data_, children_length); + return zone->New<ZonePreparseData>(zone, &zone_byte_data_, children_length); } // Implementation of ConsumedPreparseData for PreparseData diff --git a/deps/v8/src/parsing/preparse-data.cc b/deps/v8/src/parsing/preparse-data.cc index d421cb868c..b18788bfe7 100644 --- a/deps/v8/src/parsing/preparse-data.cc +++ b/deps/v8/src/parsing/preparse-data.cc @@ -9,7 +9,6 @@ #include "src/ast/scopes.h" #include "src/ast/variables.h" #include "src/handles/handles.h" -#include "src/heap/off-thread-factory.h" #include "src/objects/objects-inl.h" #include "src/objects/shared-function-info.h" #include "src/parsing/parser.h" @@ -17,6 +16,7 @@ #include "src/parsing/preparser.h" #include "src/roots/roots.h" #include "src/zone/zone-list-inl.h" // crbug.com/v8/8816 +#include "src/zone/zone-utils.h" namespace v8 { namespace internal { @@ -104,9 +104,9 @@ PreparseDataBuilder::PreparseDataBuilder(Zone* zone, void PreparseDataBuilder::DataGatheringScope::Start( DeclarationScope* function_scope) { Zone* main_zone = preparser_->main_zone(); - builder_ = new (main_zone) - PreparseDataBuilder(main_zone, preparser_->preparse_data_builder(), - preparser_->preparse_data_builder_buffer()); + builder_ = main_zone->New<PreparseDataBuilder>( + main_zone, preparser_->preparse_data_builder(), + preparser_->preparse_data_builder_buffer()); preparser_->set_preparse_data_builder(builder_); function_scope->set_preparse_data_builder(builder_); } @@ -128,9 +128,11 @@ void PreparseDataBuilder::ByteData::Start(std::vector<uint8_t>* buffer) { DCHECK_EQ(index_, 0); } +// This struct is just a type tag for Zone::NewArray<T>(size_t) call. +struct RawPreparseData {}; + void PreparseDataBuilder::ByteData::Finalize(Zone* zone) { - uint8_t* raw_zone_data = - static_cast<uint8_t*>(ZoneAllocationPolicy(zone).New(index_)); + uint8_t* raw_zone_data = zone->NewArray<uint8_t, RawPreparseData>(index_); memcpy(raw_zone_data, byte_data_->data(), index_); byte_data_->resize(0); zone_byte_data_ = Vector<uint8_t>(raw_zone_data, index_); @@ -252,7 +254,8 @@ void PreparseDataBuilder::AddChild(PreparseDataBuilder* child) { void PreparseDataBuilder::FinalizeChildren(Zone* zone) { DCHECK(!finalized_children_); - Vector<PreparseDataBuilder*> children = children_buffer_.CopyTo(zone); + Vector<PreparseDataBuilder*> children = + CloneVector(zone, children_buffer_.ToConstVector()); children_buffer_.Rewind(); children_ = children; #ifdef DEBUG @@ -335,8 +338,8 @@ void PreparseDataBuilder::SaveScopeAllocationData(DeclarationScope* scope, CHECK_LE(byte_data_.length(), std::numeric_limits<uint32_t>::max()); byte_data_.SaveCurrentSizeAtFirstUint32(); - // For a data integrity check, write a value between data about skipped inner - // funcs and data about variables. + // For a data integrity check, write a value between data about skipped + // inner funcs and data about variables. byte_data_.Reserve(kUint32Size * 3); byte_data_.WriteUint32(kMagicValue); byte_data_.WriteUint32(scope->start_position()); @@ -433,8 +436,8 @@ Handle<PreparseData> PreparseDataBuilder::ByteData::CopyToHeap( return data; } -Handle<PreparseData> PreparseDataBuilder::ByteData::CopyToOffThreadHeap( - OffThreadIsolate* isolate, int children_length) { +Handle<PreparseData> PreparseDataBuilder::ByteData::CopyToLocalHeap( + LocalIsolate* isolate, int children_length) { DCHECK(is_finalized_); int data_length = zone_byte_data_.length(); Handle<PreparseData> data = @@ -459,11 +462,11 @@ Handle<PreparseData> PreparseDataBuilder::Serialize(Isolate* isolate) { return data; } -Handle<PreparseData> PreparseDataBuilder::Serialize(OffThreadIsolate* isolate) { +Handle<PreparseData> PreparseDataBuilder::Serialize(LocalIsolate* isolate) { DCHECK(HasData()); DCHECK(!ThisOrParentBailedOut()); Handle<PreparseData> data = - byte_data_.CopyToOffThreadHeap(isolate, num_inner_with_data_); + byte_data_.CopyToLocalHeap(isolate, num_inner_with_data_); int i = 0; DCHECK(finalized_children_); for (const auto& builder : children_) { @@ -501,7 +504,7 @@ class BuilderProducedPreparseData final : public ProducedPreparseData { return builder_->Serialize(isolate); } - Handle<PreparseData> Serialize(OffThreadIsolate* isolate) final { + Handle<PreparseData> Serialize(LocalIsolate* isolate) final { return builder_->Serialize(isolate); } @@ -523,7 +526,7 @@ class OnHeapProducedPreparseData final : public ProducedPreparseData { return data_; } - Handle<PreparseData> Serialize(OffThreadIsolate* isolate) final { + Handle<PreparseData> Serialize(LocalIsolate* isolate) final { // Not required. UNREACHABLE(); } @@ -545,7 +548,7 @@ class ZoneProducedPreparseData final : public ProducedPreparseData { return data_->Serialize(isolate); } - Handle<PreparseData> Serialize(OffThreadIsolate* isolate) final { + Handle<PreparseData> Serialize(LocalIsolate* isolate) final { return data_->Serialize(isolate); } @@ -557,17 +560,17 @@ class ZoneProducedPreparseData final : public ProducedPreparseData { ProducedPreparseData* ProducedPreparseData::For(PreparseDataBuilder* builder, Zone* zone) { - return new (zone) BuilderProducedPreparseData(builder); + return zone->New<BuilderProducedPreparseData>(builder); } ProducedPreparseData* ProducedPreparseData::For(Handle<PreparseData> data, Zone* zone) { - return new (zone) OnHeapProducedPreparseData(data); + return zone->New<OnHeapProducedPreparseData>(data); } ProducedPreparseData* ProducedPreparseData::For(ZonePreparseData* data, Zone* zone) { - return new (zone) ZoneProducedPreparseData(data); + return zone->New<ZoneProducedPreparseData>(data); } template <class Data> @@ -791,7 +794,7 @@ Handle<PreparseData> ZonePreparseData::Serialize(Isolate* isolate) { return result; } -Handle<PreparseData> ZonePreparseData::Serialize(OffThreadIsolate* isolate) { +Handle<PreparseData> ZonePreparseData::Serialize(LocalIsolate* isolate) { int data_size = static_cast<int>(byte_data()->size()); int child_data_length = children_length(); Handle<PreparseData> result = diff --git a/deps/v8/src/parsing/preparse-data.h b/deps/v8/src/parsing/preparse-data.h index aa31326f9f..622338ac25 100644 --- a/deps/v8/src/parsing/preparse-data.h +++ b/deps/v8/src/parsing/preparse-data.h @@ -10,6 +10,7 @@ #include "src/common/globals.h" #include "src/handles/handles.h" #include "src/handles/maybe-handles.h" +#include "src/utils/scoped-list.h" #include "src/utils/vector.h" #include "src/zone/zone-chunk-list.h" #include "src/zone/zone-containers.h" @@ -138,8 +139,8 @@ class V8_EXPORT_PRIVATE PreparseDataBuilder : public ZoneObject, void Finalize(Zone* zone); Handle<PreparseData> CopyToHeap(Isolate* isolate, int children_length); - Handle<PreparseData> CopyToOffThreadHeap(OffThreadIsolate* isolate, - int children_length); + Handle<PreparseData> CopyToLocalHeap(LocalIsolate* isolate, + int children_length); inline ZonePreparseData* CopyToZone(Zone* zone, int children_length); void Reserve(size_t bytes); @@ -208,7 +209,7 @@ class V8_EXPORT_PRIVATE PreparseDataBuilder : public ZoneObject, friend class BuilderProducedPreparseData; Handle<PreparseData> Serialize(Isolate* isolate); - Handle<PreparseData> Serialize(OffThreadIsolate* isolate); + Handle<PreparseData> Serialize(LocalIsolate* isolate); ZonePreparseData* Serialize(Zone* zone); void FinalizeChildren(Zone* zone); @@ -254,7 +255,7 @@ class ProducedPreparseData : public ZoneObject { // If there is data (if the Scope contains skippable inner functions), move // the data into the heap and return a Handle to it; otherwise return a null // MaybeHandle. - virtual Handle<PreparseData> Serialize(OffThreadIsolate* isolate) = 0; + virtual Handle<PreparseData> Serialize(LocalIsolate* isolate) = 0; // If there is data (if the Scope contains skippable inner functions), return // an off-heap ZonePreparseData representing the data; otherwise diff --git a/deps/v8/src/parsing/preparser.cc b/deps/v8/src/parsing/preparser.cc index f9af109d81..6da0faa74a 100644 --- a/deps/v8/src/parsing/preparser.cc +++ b/deps/v8/src/parsing/preparser.cc @@ -57,7 +57,7 @@ PreParserIdentifier GetIdentifierHelper(Scanner* scanner, return PreParserIdentifier::Default(); } -} // unnamed namespace +} // namespace PreParserIdentifier PreParser::GetIdentifier() const { const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory()); @@ -325,10 +325,6 @@ PreParser::Expression PreParser::ParseFunctionLiteral( // Parsing the body may change the language mode in our scope. language_mode = function_scope->language_mode(); - if (is_sloppy(language_mode)) { - function_scope->HoistSloppyBlockFunctions(nullptr); - } - // Validate name and parameter names. We can do this only after parsing the // function, since the function can declare itself strict. CheckFunctionName(language_mode, function_name, function_name_validity, diff --git a/deps/v8/src/parsing/preparser.h b/deps/v8/src/parsing/preparser.h index 5280e3d226..af53b8dc87 100644 --- a/deps/v8/src/parsing/preparser.h +++ b/deps/v8/src/parsing/preparser.h @@ -575,6 +575,10 @@ class PreParserFactory { } PreParserExpression NewOptionalChain(const PreParserExpression& expr) { + // Needed to track `delete a?.#b` early errors + if (expr.IsPrivateReference()) { + return PreParserExpression::PrivateReference(); + } return PreParserExpression::Default(); } @@ -645,6 +649,7 @@ class PreParserFactory { bool optional_chain = false) { if (possibly_eval == Call::IS_POSSIBLY_EVAL) { DCHECK(expression.IsIdentifier() && expression.AsIdentifier().IsEval()); + DCHECK(!optional_chain); return PreParserExpression::CallEval(); } return PreParserExpression::Call(); @@ -1528,6 +1533,11 @@ class PreParser : public ParserBase<PreParser> { return PreParserExpression::This(); } + V8_INLINE PreParserExpression NewThisExpression(int pos) { + UseThis(); + return PreParserExpression::This(); + } + V8_INLINE PreParserExpression NewSuperPropertyReference(int pos) { scope()->NewUnresolved(factory()->ast_node_factory(), ast_value_factory()->this_function_string(), pos, diff --git a/deps/v8/src/parsing/rewriter.h b/deps/v8/src/parsing/rewriter.h index e820c0e53b..e2095b74f6 100644 --- a/deps/v8/src/parsing/rewriter.h +++ b/deps/v8/src/parsing/rewriter.h @@ -7,7 +7,7 @@ #include "src/base/macros.h" #include "src/base/optional.h" -#include "src/zone/zone.h" +#include "src/zone/zone-type-traits.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/parsing/scanner-inl.h b/deps/v8/src/parsing/scanner-inl.h index bd4d0284d8..b255dccc05 100644 --- a/deps/v8/src/parsing/scanner-inl.h +++ b/deps/v8/src/parsing/scanner-inl.h @@ -305,7 +305,7 @@ V8_INLINE Token::Value Scanner::ScanIdentifierOrKeywordInner() { // Special case for escapes at the start of an identifier. escaped = true; uc32 c = ScanIdentifierUnicodeEscape(); - DCHECK(!IsIdentifierStart(-1)); + DCHECK(!IsIdentifierStart(Invalid())); if (c == '\\' || !IsIdentifierStart(c)) { return Token::ILLEGAL; } diff --git a/deps/v8/src/parsing/scanner.cc b/deps/v8/src/parsing/scanner.cc index 52a1bf0724..9a04bdc510 100644 --- a/deps/v8/src/parsing/scanner.cc +++ b/deps/v8/src/parsing/scanner.cc @@ -107,6 +107,12 @@ void Scanner::Initialize() { Scan(); } +// static +bool Scanner::IsInvalid(uc32 c) { + DCHECK(c == Invalid() || base::IsInRange(c, 0u, String::kMaxCodePoint)); + return c == Scanner::Invalid(); +} + template <bool capture_raw, bool unicode> uc32 Scanner::ScanHexNumber(int expected_length) { DCHECK_LE(expected_length, 4); // prevent overflow @@ -120,7 +126,7 @@ uc32 Scanner::ScanHexNumber(int expected_length) { unicode ? MessageTemplate::kInvalidUnicodeEscapeSequence : MessageTemplate::kInvalidHexEscapeSequence); - return -1; + return Invalid(); } x = x * 16 + d; Advance<capture_raw>(); @@ -130,17 +136,17 @@ uc32 Scanner::ScanHexNumber(int expected_length) { } template <bool capture_raw> -uc32 Scanner::ScanUnlimitedLengthHexNumber(int max_value, int beg_pos) { +uc32 Scanner::ScanUnlimitedLengthHexNumber(uc32 max_value, int beg_pos) { uc32 x = 0; int d = HexValue(c0_); - if (d < 0) return -1; + if (d < 0) return Invalid(); while (d >= 0) { x = x * 16 + d; if (x > max_value) { ReportScannerError(Location(beg_pos, source_pos() + 1), MessageTemplate::kUndefinedUnicodeCodePoint); - return -1; + return Invalid(); } Advance<capture_raw>(); d = HexValue(c0_); @@ -386,7 +392,7 @@ bool Scanner::ScanEscape() { case 't' : c = '\t'; break; case 'u' : { c = ScanUnicodeEscape<capture_raw>(); - if (c < 0) return false; + if (IsInvalid(c)) return false; break; } case 'v': @@ -394,19 +400,27 @@ bool Scanner::ScanEscape() { break; case 'x': { c = ScanHexNumber<capture_raw>(2); - if (c < 0) return false; + if (IsInvalid(c)) return false; break; } - case '0': // Fall through. - case '1': // fall through - case '2': // fall through - case '3': // fall through - case '4': // fall through - case '5': // fall through - case '6': // fall through + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': case '7': c = ScanOctalEscape<capture_raw>(c, 2); break; + case '8': + case '9': + // '\8' and '\9' are disallowed in strict mode. + // Re-use the octal error state to propagate the error. + octal_pos_ = Location(source_pos() - 2, source_pos() - 1); + octal_message_ = capture_raw ? MessageTemplate::kTemplate8Or9Escape + : MessageTemplate::kStrict8Or9Escape; + break; } // Other escaped characters are interpreted as their non-escaped version. @@ -416,6 +430,7 @@ bool Scanner::ScanEscape() { template <bool capture_raw> uc32 Scanner::ScanOctalEscape(uc32 c, int length) { + DCHECK('0' <= c && c <= '7'); uc32 x = c - '0'; int i = 0; for (; i < length; i++) { @@ -553,7 +568,7 @@ Token::Value Scanner::ScanTemplateSpan() { scanner_error_state.MoveErrorTo(next_); octal_error_state.MoveErrorTo(next_); } - } else if (c < 0) { + } else if (c == kEndOfInput) { // Unterminated template literal break; } else { @@ -585,7 +600,7 @@ Handle<String> Scanner::SourceUrl(LocalIsolate* isolate) const { } template Handle<String> Scanner::SourceUrl(Isolate* isolate) const; -template Handle<String> Scanner::SourceUrl(OffThreadIsolate* isolate) const; +template Handle<String> Scanner::SourceUrl(LocalIsolate* isolate) const; template <typename LocalIsolate> Handle<String> Scanner::SourceMappingUrl(LocalIsolate* isolate) const { @@ -597,8 +612,7 @@ Handle<String> Scanner::SourceMappingUrl(LocalIsolate* isolate) const { } template Handle<String> Scanner::SourceMappingUrl(Isolate* isolate) const; -template Handle<String> Scanner::SourceMappingUrl( - OffThreadIsolate* isolate) const; +template Handle<String> Scanner::SourceMappingUrl(LocalIsolate* isolate) const; bool Scanner::ScanDigitsWithNumericSeparators(bool (*predicate)(uc32 ch), bool is_check_first_digit) { @@ -861,7 +875,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) { uc32 Scanner::ScanIdentifierUnicodeEscape() { Advance(); - if (c0_ != 'u') return -1; + if (c0_ != 'u') return Invalid(); Advance(); return ScanUnicodeEscape<false>(); } @@ -873,11 +887,12 @@ uc32 Scanner::ScanUnicodeEscape() { if (c0_ == '{') { int begin = source_pos() - 2; Advance<capture_raw>(); - uc32 cp = ScanUnlimitedLengthHexNumber<capture_raw>(0x10FFFF, begin); - if (cp < 0 || c0_ != '}') { + uc32 cp = + ScanUnlimitedLengthHexNumber<capture_raw>(String::kMaxCodePoint, begin); + if (cp == kInvalidSequence || c0_ != '}') { ReportScannerError(source_pos(), MessageTemplate::kInvalidUnicodeEscapeSequence); - return -1; + return Invalid(); } Advance<capture_raw>(); return cp; @@ -895,7 +910,7 @@ Token::Value Scanner::ScanIdentifierOrKeywordInnerSlow(bool escaped, // Only allow legal identifier part characters. // TODO(verwaest): Make this true. // DCHECK(!IsIdentifierPart('\')); - DCHECK(!IsIdentifierPart(-1)); + DCHECK(!IsIdentifierPart(Invalid())); if (c == '\\' || !IsIdentifierPart(c)) { return Token::ILLEGAL; } @@ -986,8 +1001,9 @@ Maybe<int> Scanner::ScanRegExpFlags() { // Scan regular expression flags. JSRegExp::Flags flags; while (IsIdentifierPart(c0_)) { - JSRegExp::Flags flag = JSRegExp::FlagFromChar(c0_); - if (flag == JSRegExp::kInvalid) return Nothing<int>(); + base::Optional<JSRegExp::Flags> maybe_flag = JSRegExp::FlagFromChar(c0_); + if (!maybe_flag.has_value()) return Nothing<int>(); + JSRegExp::Flags flag = *maybe_flag; if (flags & flag) return Nothing<int>(); Advance(); flags |= flag; diff --git a/deps/v8/src/parsing/scanner.h b/deps/v8/src/parsing/scanner.h index 830067e1ad..6ac7dde01b 100644 --- a/deps/v8/src/parsing/scanner.h +++ b/deps/v8/src/parsing/scanner.h @@ -39,7 +39,7 @@ class Zone; // or one part of a surrogate pair that make a single 21 bit code point. class Utf16CharacterStream { public: - static const uc32 kEndOfInput = -1; + static constexpr uc32 kEndOfInput = static_cast<uc32>(-1); virtual ~Utf16CharacterStream() = default; @@ -267,8 +267,11 @@ class V8_EXPORT_PRIVATE Scanner { }; // -1 is outside of the range of any real source code. - static const int kNoOctalLocation = -1; - static const uc32 kEndOfInput = Utf16CharacterStream::kEndOfInput; + static constexpr uc32 kEndOfInput = Utf16CharacterStream::kEndOfInput; + static constexpr uc32 kInvalidSequence = static_cast<uc32>(-1); + + static constexpr uc32 Invalid() { return Scanner::kInvalidSequence; } + static bool IsInvalid(uc32 c); explicit Scanner(Utf16CharacterStream* source, UnoptimizedCompileFlags flags); @@ -541,7 +544,8 @@ class V8_EXPORT_PRIVATE Scanner { } void PushBack(uc32 ch) { - DCHECK_LE(c0_, static_cast<uc32>(unibrow::Utf16::kMaxNonSurrogateCharCode)); + DCHECK(IsInvalid(c0_) || + base::IsInRange(c0_, 0u, unibrow::Utf16::kMaxNonSurrogateCharCode)); source_->Back(); c0_ = ch; } @@ -623,7 +627,7 @@ class V8_EXPORT_PRIVATE Scanner { // number can be 000000001, so it's very long in characters but its value is // small. template <bool capture_raw> - uc32 ScanUnlimitedLengthHexNumber(int max_value, int beg_pos); + uc32 ScanUnlimitedLengthHexNumber(uc32 max_value, int beg_pos); // Scans a single JavaScript token. V8_INLINE Token::Value ScanSingleToken(); diff --git a/deps/v8/src/parsing/token.h b/deps/v8/src/parsing/token.h index ef92238de2..dabbff0e0e 100644 --- a/deps/v8/src/parsing/token.h +++ b/deps/v8/src/parsing/token.h @@ -284,6 +284,10 @@ class V8_EXPORT_PRIVATE Token { return base::IsInRange(token, INIT, ASSIGN_SUB); } + static bool IsLogicalAssignmentOp(Value token) { + return base::IsInRange(token, ASSIGN_NULLISH, ASSIGN_AND); + } + static bool IsBinaryOp(Value op) { return base::IsInRange(op, COMMA, SUB); } static bool IsCompareOp(Value op) { return base::IsInRange(op, EQ, IN); } |