Commit 1a60e929 authored by Toon Verwaest's avatar Toon Verwaest Committed by V8 LUCI CQ

[parser] Move extension_ from parserbase to parser

The preparser doesn't support extension parsing so always return false
there, and move the field to the parser instead.

Change-Id: Ie9ad0bd710858120467eb709ec92e59b38eaffba
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3009214Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75588}
parent 758816f4
......@@ -241,14 +241,13 @@ class ParserBase {
const Impl* impl() const { return static_cast<const Impl*>(this); }
ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
v8::Extension* extension, AstValueFactory* ast_value_factory,
AstValueFactory* ast_value_factory,
PendingCompilationErrorHandler* pending_error_handler,
RuntimeCallStats* runtime_call_stats, Logger* logger,
UnoptimizedCompileFlags flags, bool parsing_on_main_thread)
: scope_(nullptr),
original_scope_(nullptr),
function_state_(nullptr),
extension_(extension),
fni_(ast_value_factory),
ast_value_factory_(ast_value_factory),
ast_node_factory_(ast_value_factory, zone),
......@@ -1539,7 +1538,6 @@ class ParserBase {
Scope* object_literal_scope_ = nullptr;
Scope* original_scope_; // The top scope for the current parsing item.
FunctionState* function_state_; // Function state stack.
v8::Extension* extension_;
FuncNameInferrer fni_;
AstValueFactory* ast_value_factory_; // Not owned.
typename Types::Factory ast_node_factory_;
......@@ -1948,7 +1946,7 @@ ParserBase<Impl>::ParsePrimaryExpression() {
return ParseTemplateLiteral(impl()->NullExpression(), beg_pos, false);
case Token::MOD:
if (flags().allow_natives_syntax() || extension_ != nullptr) {
if (flags().allow_natives_syntax() || impl()->ParsingExtension()) {
return ParseV8Intrinsic();
}
break;
......@@ -5403,10 +5401,10 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
}
}
// If we have an extension, we allow a native function declaration.
// A native function declaration starts with "native function" with
// no line-terminator between the two words.
if (extension_ != nullptr && peek() == Token::FUNCTION &&
// We allow a native function declaration if we're parsing the source for an
// extension. A native function declaration starts with "native function"
// with no line-terminator between the two words.
if (impl()->ParsingExtension() && peek() == Token::FUNCTION &&
!scanner()->HasLineTerminatorBeforeNext() && impl()->IsNative(expr) &&
!scanner()->literal_contains_escapes()) {
return ParseNativeDeclaration();
......
......@@ -345,7 +345,7 @@ Expression* Parser::ExpressionFromLiteral(Token::Value token, int pos) {
Expression* Parser::NewV8Intrinsic(const AstRawString* name,
const ScopedPtrList<Expression>& args,
int pos) {
if (extension_ != nullptr) {
if (ParsingExtension()) {
// The extension structures are only accessible while parsing the
// very first time, not when reparsing because of lazy compilation.
GetClosureScope()->ForceEagerCompilation();
......@@ -421,7 +421,7 @@ Expression* Parser::NewV8RuntimeFunctionForFuzzing(
Parser::Parser(ParseInfo* info)
: ParserBase<Parser>(
info->zone(), &scanner_, info->stack_limit(), info->extension(),
info->zone(), &scanner_, info->stack_limit(),
info->GetOrCreateAstValueFactory(), info->pending_error_handler(),
info->runtime_call_stats(), info->logger(), info->flags(), true),
info_(info),
......@@ -1785,7 +1785,7 @@ Statement* Parser::DeclareNative(const AstRawString* name, int pos) {
// other functions are set up when entering the surrounding scope.
VariableProxy* proxy = DeclareBoundVariable(name, VariableMode::kVar, pos);
NativeFunctionLiteral* lit =
factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition);
factory()->NewNativeFunctionLiteral(name, extension(), kNoSourcePosition);
return factory()->NewExpressionStatement(
factory()->NewAssignment(Token::INIT, proxy, lit, kNoSourcePosition),
pos);
......@@ -2559,7 +2559,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// that tracks unresolved variables.
DCHECK_IMPLIES(parse_lazily(), info()->flags().allow_lazy_compile());
DCHECK_IMPLIES(parse_lazily(), has_error() || allow_lazy_);
DCHECK_IMPLIES(parse_lazily(), extension_ == nullptr);
DCHECK_IMPLIES(parse_lazily(), extension() == nullptr);
const bool is_lazy =
eager_compile_hint == FunctionLiteral::kShouldLazyCompile;
......
......@@ -586,6 +586,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return !property->IsPrototype();
}
V8_INLINE v8::Extension* extension() const { return info_->extension(); }
V8_INLINE bool ParsingExtension() const { return extension() != nullptr; }
V8_INLINE bool IsNative(Expression* expr) const {
DCHECK_NOT_NULL(expr);
return expr->IsVariableProxy() &&
......
......@@ -935,10 +935,9 @@ class PreParser : public ParserBase<PreParser> {
PendingCompilationErrorHandler* pending_error_handler,
RuntimeCallStats* runtime_call_stats, Logger* logger,
UnoptimizedCompileFlags flags, bool parsing_on_main_thread = true)
: ParserBase<PreParser>(zone, scanner, stack_limit, nullptr,
ast_value_factory, pending_error_handler,
runtime_call_stats, logger, flags,
parsing_on_main_thread),
: ParserBase<PreParser>(zone, scanner, stack_limit, ast_value_factory,
pending_error_handler, runtime_call_stats, logger,
flags, parsing_on_main_thread),
use_counts_(nullptr),
preparse_data_builder_(nullptr),
preparse_data_builder_buffer_() {
......@@ -1326,6 +1325,14 @@ class PreParser : public ParserBase<PreParser> {
return false;
}
V8_INLINE bool ParsingExtension() const {
// Preparsing is disabled for extensions (because the extension
// details aren't passed to lazily compiled functions), so we
// don't accept "native function" in the preparser and there is
// no need to keep track of "native".
return false;
}
V8_INLINE bool IsNative(const PreParserExpression& expr) const {
// Preparsing is disabled for extensions (because the extension
// details aren't passed to lazily compiled functions), so we
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment