Commit 9b986bf9 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

[objects] Use function syntax kind enum instead of bits on SFI and ParseInfo

- Rename FunctionLiteral::FunctionType to FunctionSyntaxKind.

- Re-express IsWrappedBit, IsDeclarationBit, IsAnonymousExpressionBit,
  and IsNamedExpressionBit in SFI::flags as FunctionSyntaxKind. This
  frees up 1 bit in SFI::flags.

- Re-express the analogous bits in ParseInfo as FunctionSyntaxKind.

- Simplifies some logic in the back-and-forth passing of this info
  between SFI and ParseInfo.

- Drive-by fix parsing class member initializations as kAccessorOrMethod.

Bug: v8:9644
Change-Id: I6c165d5016d968f5057a32136385ddcdc4a46ef1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1767263Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63388}
parent 070cc9d1
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/execution/isolate.h" #include "src/execution/isolate.h"
#include "src/heap/factory.h" #include "src/heap/factory.h"
#include "src/objects/function-syntax-kind.h"
#include "src/objects/literal-objects.h" #include "src/objects/literal-objects.h"
#include "src/objects/smi.h" #include "src/objects/smi.h"
#include "src/parsing/token.h" #include "src/parsing/token.h"
...@@ -2200,14 +2201,6 @@ class Throw final : public Expression { ...@@ -2200,14 +2201,6 @@ class Throw final : public Expression {
class FunctionLiteral final : public Expression { class FunctionLiteral final : public Expression {
public: public:
enum FunctionType {
kAnonymousExpression,
kNamedExpression,
kDeclaration,
kAccessorOrMethod,
kWrapped,
};
enum ParameterFlag : uint8_t { enum ParameterFlag : uint8_t {
kNoDuplicateParameters, kNoDuplicateParameters,
kHasDuplicateParameters kHasDuplicateParameters
...@@ -2229,12 +2222,8 @@ class FunctionLiteral final : public Expression { ...@@ -2229,12 +2222,8 @@ class FunctionLiteral final : public Expression {
int function_token_position() const { return function_token_position_; } int function_token_position() const { return function_token_position_; }
int start_position() const; int start_position() const;
int end_position() const; int end_position() const;
bool is_declaration() const { return function_type() == kDeclaration; }
bool is_named_expression() const {
return function_type() == kNamedExpression;
}
bool is_anonymous_expression() const { bool is_anonymous_expression() const {
return function_type() == kAnonymousExpression; return syntax_kind() == FunctionSyntaxKind::kAnonymousExpression;
} }
void mark_as_oneshot_iife() { void mark_as_oneshot_iife() {
...@@ -2244,7 +2233,6 @@ class FunctionLiteral final : public Expression { ...@@ -2244,7 +2233,6 @@ class FunctionLiteral final : public Expression {
bool is_toplevel() const { bool is_toplevel() const {
return function_literal_id() == kFunctionLiteralIdTopLevel; return function_literal_id() == kFunctionLiteralIdTopLevel;
} }
bool is_wrapped() const { return function_type() == kWrapped; }
V8_EXPORT_PRIVATE LanguageMode language_mode() const; V8_EXPORT_PRIVATE LanguageMode language_mode() const;
static bool NeedsHomeObject(Expression* expr); static bool NeedsHomeObject(Expression* expr);
...@@ -2314,8 +2302,8 @@ class FunctionLiteral final : public Expression { ...@@ -2314,8 +2302,8 @@ class FunctionLiteral final : public Expression {
V8_EXPORT_PRIVATE bool ShouldEagerCompile() const; V8_EXPORT_PRIVATE bool ShouldEagerCompile() const;
V8_EXPORT_PRIVATE void SetShouldEagerCompile(); V8_EXPORT_PRIVATE void SetShouldEagerCompile();
FunctionType function_type() const { FunctionSyntaxKind syntax_kind() const {
return FunctionTypeBits::decode(bit_field_); return FunctionSyntaxKindBits::decode(bit_field_);
} }
FunctionKind kind() const; FunctionKind kind() const;
...@@ -2367,7 +2355,7 @@ class FunctionLiteral final : public Expression { ...@@ -2367,7 +2355,7 @@ class FunctionLiteral final : public Expression {
AstValueFactory* ast_value_factory, DeclarationScope* scope, AstValueFactory* ast_value_factory, DeclarationScope* scope,
const ScopedPtrList<Statement>& body, const ScopedPtrList<Statement>& body,
int expected_property_count, int parameter_count, int expected_property_count, int parameter_count,
int function_length, FunctionType function_type, int function_length, FunctionSyntaxKind function_syntax_kind,
ParameterFlag has_duplicate_parameters, ParameterFlag has_duplicate_parameters,
EagerCompileHint eager_compile_hint, int position, EagerCompileHint eager_compile_hint, int position,
bool has_braces, int function_literal_id, bool has_braces, int function_literal_id,
...@@ -2384,19 +2372,21 @@ class FunctionLiteral final : public Expression { ...@@ -2384,19 +2372,21 @@ class FunctionLiteral final : public Expression {
body_(0, nullptr), body_(0, nullptr),
raw_inferred_name_(ast_value_factory->empty_cons_string()), raw_inferred_name_(ast_value_factory->empty_cons_string()),
produced_preparse_data_(produced_preparse_data) { produced_preparse_data_(produced_preparse_data) {
bit_field_ |= bit_field_ |= FunctionSyntaxKindBits::encode(function_syntax_kind) |
FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | Pretenure::encode(false) |
HasDuplicateParameters::encode(has_duplicate_parameters == HasDuplicateParameters::encode(has_duplicate_parameters ==
kHasDuplicateParameters) | kHasDuplicateParameters) |
DontOptimizeReasonField::encode(BailoutReason::kNoReason) | DontOptimizeReasonField::encode(BailoutReason::kNoReason) |
RequiresInstanceMembersInitializer::encode(false) | RequiresInstanceMembersInitializer::encode(false) |
HasBracesField::encode(has_braces) | OneshotIIFEBit::encode(false); HasBracesField::encode(has_braces) |
OneshotIIFEBit::encode(false);
if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile(); if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile();
body.CopyTo(&body_, zone); body.CopyTo(&body_, zone);
} }
using FunctionTypeBits = Expression::NextBitField<FunctionType, 3>; using FunctionSyntaxKindBits =
using Pretenure = FunctionTypeBits::Next<bool, 1>; Expression::NextBitField<FunctionSyntaxKind, 3>;
using Pretenure = FunctionSyntaxKindBits::Next<bool, 1>;
using HasDuplicateParameters = Pretenure::Next<bool, 1>; using HasDuplicateParameters = Pretenure::Next<bool, 1>;
using DontOptimizeReasonField = using DontOptimizeReasonField =
HasDuplicateParameters::Next<BailoutReason, 8>; HasDuplicateParameters::Next<BailoutReason, 8>;
...@@ -3221,13 +3211,13 @@ class AstNodeFactory final { ...@@ -3221,13 +3211,13 @@ class AstNodeFactory final {
const ScopedPtrList<Statement>& body, int expected_property_count, const ScopedPtrList<Statement>& body, int expected_property_count,
int parameter_count, int function_length, int parameter_count, int function_length,
FunctionLiteral::ParameterFlag has_duplicate_parameters, FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
FunctionLiteral::EagerCompileHint eager_compile_hint, int position, FunctionLiteral::EagerCompileHint eager_compile_hint, int position,
bool has_braces, int function_literal_id, bool has_braces, int function_literal_id,
ProducedPreparseData* produced_preparse_data = nullptr) { ProducedPreparseData* produced_preparse_data = nullptr) {
return new (zone_) FunctionLiteral( return new (zone_) FunctionLiteral(
zone_, name, ast_value_factory_, scope, body, expected_property_count, zone_, name, ast_value_factory_, scope, body, expected_property_count,
parameter_count, function_length, function_type, parameter_count, function_length, function_syntax_kind,
has_duplicate_parameters, eager_compile_hint, position, has_braces, has_duplicate_parameters, eager_compile_hint, position, has_braces,
function_literal_id, produced_preparse_data); function_literal_id, produced_preparse_data);
} }
...@@ -3241,7 +3231,7 @@ class AstNodeFactory final { ...@@ -3241,7 +3231,7 @@ class AstNodeFactory final {
return new (zone_) FunctionLiteral( return new (zone_) FunctionLiteral(
zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope,
body, expected_property_count, parameter_count, parameter_count, body, expected_property_count, parameter_count, parameter_count,
FunctionLiteral::kAnonymousExpression, FunctionSyntaxKind::kAnonymousExpression,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kShouldLazyCompile, 0, /* has_braces */ false, FunctionLiteral::kShouldLazyCompile, 0, /* has_braces */ false,
kFunctionLiteralIdTopLevel); kFunctionLiteralIdTopLevel);
......
...@@ -2107,7 +2107,7 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction( ...@@ -2107,7 +2107,7 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
script->set_wrapped_arguments(*arguments); script->set_wrapped_arguments(*arguments);
parse_info.set_eval(); // Use an eval scope as declaration scope. parse_info.set_eval(); // Use an eval scope as declaration scope.
parse_info.set_wrapped_as_function(); parse_info.set_function_syntax_kind(FunctionSyntaxKind::kWrapped);
// TODO(delphick): Remove this and instead make the wrapped and wrapper // TODO(delphick): Remove this and instead make the wrapped and wrapper
// functions fully non-lazy instead thus preventing source positions from // functions fully non-lazy instead thus preventing source positions from
// being omitted. // being omitted.
......
...@@ -1508,6 +1508,7 @@ void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT ...@@ -1508,6 +1508,7 @@ void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT
os << "\n - inferred name: " << Brief(inferred_name()); os << "\n - inferred name: " << Brief(inferred_name());
} }
os << "\n - kind: " << kind(); os << "\n - kind: " << kind();
os << "\n - syntax kind: " << syntax_kind();
if (needs_home_object()) { if (needs_home_object()) {
os << "\n - needs_home_object"; os << "\n - needs_home_object";
} }
...@@ -1524,13 +1525,6 @@ void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT ...@@ -1524,13 +1525,6 @@ void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT
// Script files are often large, hard to read. // Script files are often large, hard to read.
// os << "\n - script ="; // os << "\n - script =";
// script()->Print(os); // script()->Print(os);
if (is_named_expression()) {
os << "\n - named expression";
} else if (is_anonymous_expression()) {
os << "\n - anonymous expression";
} else if (is_declaration()) {
os << "\n - declaration";
}
os << "\n - function token position: " << function_token_position(); os << "\n - function token position: " << function_token_position();
os << "\n - start position: " << StartPosition(); os << "\n - start position: " << StartPosition();
os << "\n - end position: " << EndPosition(); os << "\n - end position: " << EndPosition();
......
// Copyright 2019 the V8 project authors. All rights reserved. // Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -21,12 +20,12 @@ enum FunctionKind : uint8_t { ...@@ -21,12 +20,12 @@ enum FunctionKind : uint8_t {
// BEGIN default constructors // BEGIN default constructors
kDefaultBaseConstructor, kDefaultBaseConstructor,
// END base constructors // END base constructors
// BEGIN derived cosntructors // BEGIN derived constructors
kDefaultDerivedConstructor, kDefaultDerivedConstructor,
// END default constructors // END default constructors
kDerivedConstructor, kDerivedConstructor,
// END derived costructors // END derived constructors
// END class cosntructors // END class constructors
// END constructable functions. // END constructable functions.
// BEGIN accessors // BEGIN accessors
kGetterFunction, kGetterFunction,
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_FUNCTION_SYNTAX_KIND_H_
#define V8_OBJECTS_FUNCTION_SYNTAX_KIND_H_
#include "src/utils/utils.h"
namespace v8 {
namespace internal {
enum class FunctionSyntaxKind : uint8_t {
kAnonymousExpression,
kNamedExpression,
kDeclaration,
kAccessorOrMethod,
kWrapped,
kLastFunctionSyntaxKind = kWrapped,
};
inline const char* FunctionSyntaxKind2String(FunctionSyntaxKind kind) {
switch (kind) {
case FunctionSyntaxKind::kAnonymousExpression:
return "AnonymousExpression";
case FunctionSyntaxKind::kNamedExpression:
return "NamedExpression";
case FunctionSyntaxKind::kDeclaration:
return "Declaration";
case FunctionSyntaxKind::kAccessorOrMethod:
return "AccessorOrMethod";
case FunctionSyntaxKind::kWrapped:
return "Wrapped";
}
UNREACHABLE();
}
inline std::ostream& operator<<(std::ostream& os, FunctionSyntaxKind kind) {
return os << FunctionSyntaxKind2String(kind);
}
} // namespace internal
} // namespace v8
#endif // V8_OBJECTS_FUNCTION_SYNTAX_KIND_H_
...@@ -5335,12 +5335,9 @@ void SharedFunctionInfo::InitFromFunctionLiteral( ...@@ -5335,12 +5335,9 @@ void SharedFunctionInfo::InitFromFunctionLiteral(
lit->end_position()); lit->end_position());
needs_position_info = false; needs_position_info = false;
} }
shared_info->set_is_declaration(lit->is_declaration()); shared_info->set_syntax_kind(lit->syntax_kind());
shared_info->set_is_named_expression(lit->is_named_expression());
shared_info->set_is_anonymous_expression(lit->is_anonymous_expression());
shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
shared_info->set_language_mode(lit->language_mode()); shared_info->set_language_mode(lit->language_mode());
shared_info->set_is_wrapped(lit->is_wrapped());
shared_info->set_function_literal_id(lit->function_literal_id()); shared_info->set_function_literal_id(lit->function_literal_id());
// shared_info->set_kind(lit->kind()); // shared_info->set_kind(lit->kind());
// FunctionKind must have already been set. // FunctionKind must have already been set.
......
...@@ -200,14 +200,13 @@ int SharedFunctionInfo::function_token_position() const { ...@@ -200,14 +200,13 @@ int SharedFunctionInfo::function_token_position() const {
} }
} }
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, is_wrapped, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, syntax_kind,
SharedFunctionInfo::IsWrappedBit) SharedFunctionInfo::FunctionSyntaxKindBits)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, allows_lazy_compilation, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, allows_lazy_compilation,
SharedFunctionInfo::AllowLazyCompilationBit) SharedFunctionInfo::AllowLazyCompilationBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, has_duplicate_parameters, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, has_duplicate_parameters,
SharedFunctionInfo::HasDuplicateParametersBit) SharedFunctionInfo::HasDuplicateParametersBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, is_declaration,
SharedFunctionInfo::IsDeclarationBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, native, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, native,
SharedFunctionInfo::IsNativeBit) SharedFunctionInfo::IsNativeBit)
...@@ -219,13 +218,9 @@ BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, ...@@ -219,13 +218,9 @@ BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags,
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, name_should_print_as_anonymous, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, name_should_print_as_anonymous,
SharedFunctionInfo::NameShouldPrintAsAnonymousBit) SharedFunctionInfo::NameShouldPrintAsAnonymousBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, is_anonymous_expression,
SharedFunctionInfo::IsAnonymousExpressionBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, has_reported_binary_coverage, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, has_reported_binary_coverage,
SharedFunctionInfo::HasReportedBinaryCoverageBit) SharedFunctionInfo::HasReportedBinaryCoverageBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, is_named_expression,
SharedFunctionInfo::IsNamedExpressionBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, is_toplevel, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, is_toplevel,
SharedFunctionInfo::IsTopLevelBit) SharedFunctionInfo::IsTopLevelBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags,
...@@ -271,6 +266,10 @@ void SharedFunctionInfo::set_kind(FunctionKind kind) { ...@@ -271,6 +266,10 @@ void SharedFunctionInfo::set_kind(FunctionKind kind) {
UpdateFunctionMapIndex(); UpdateFunctionMapIndex();
} }
bool SharedFunctionInfo::is_wrapped() const {
return syntax_kind() == FunctionSyntaxKind::kWrapped;
}
bool SharedFunctionInfo::needs_home_object() const { bool SharedFunctionInfo::needs_home_object() const {
return NeedsHomeObjectBit::decode(flags()); return NeedsHomeObjectBit::decode(flags());
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "src/codegen/bailout-reason.h" #include "src/codegen/bailout-reason.h"
#include "src/objects/compressed-slots.h" #include "src/objects/compressed-slots.h"
#include "src/objects/function-kind.h" #include "src/objects/function-kind.h"
#include "src/objects/function-syntax-kind.h"
#include "src/objects/objects.h" #include "src/objects/objects.h"
#include "src/objects/script.h" #include "src/objects/script.h"
#include "src/objects/slots.h" #include "src/objects/slots.h"
...@@ -433,9 +434,6 @@ class SharedFunctionInfo : public HeapObject { ...@@ -433,9 +434,6 @@ class SharedFunctionInfo : public HeapObject {
// [flags] Bit field containing various flags about the function. // [flags] Bit field containing various flags about the function.
DECL_INT32_ACCESSORS(flags) DECL_INT32_ACCESSORS(flags)
// Is this function a named function expression in the source code.
DECL_BOOLEAN_ACCESSORS(is_named_expression)
// Is this function a top-level function (scripts, evals). // Is this function a top-level function (scripts, evals).
DECL_BOOLEAN_ACCESSORS(is_toplevel) DECL_BOOLEAN_ACCESSORS(is_toplevel)
...@@ -446,8 +444,11 @@ class SharedFunctionInfo : public HeapObject { ...@@ -446,8 +444,11 @@ class SharedFunctionInfo : public HeapObject {
inline LanguageMode language_mode() const; inline LanguageMode language_mode() const;
inline void set_language_mode(LanguageMode language_mode); inline void set_language_mode(LanguageMode language_mode);
// How the function appears in source text.
DECL_PRIMITIVE_ACCESSORS(syntax_kind, FunctionSyntaxKind)
// Indicates whether the source is implicitly wrapped in a function. // Indicates whether the source is implicitly wrapped in a function.
DECL_BOOLEAN_ACCESSORS(is_wrapped) inline bool is_wrapped() const;
// True if the function has any duplicated parameter names. // True if the function has any duplicated parameter names.
DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
...@@ -458,9 +459,6 @@ class SharedFunctionInfo : public HeapObject { ...@@ -458,9 +459,6 @@ class SharedFunctionInfo : public HeapObject {
// global object. // global object.
DECL_BOOLEAN_ACCESSORS(native) DECL_BOOLEAN_ACCESSORS(native)
// Whether this function was created from a FunctionDeclaration.
DECL_BOOLEAN_ACCESSORS(is_declaration)
// Indicates that asm->wasm conversion failed and should not be re-attempted. // Indicates that asm->wasm conversion failed and should not be re-attempted.
DECL_BOOLEAN_ACCESSORS(is_asm_wasm_broken) DECL_BOOLEAN_ACCESSORS(is_asm_wasm_broken)
...@@ -470,11 +468,6 @@ class SharedFunctionInfo : public HeapObject { ...@@ -470,11 +468,6 @@ class SharedFunctionInfo : public HeapObject {
// see a binding for it. // see a binding for it.
DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
// Indicates that the function is either an anonymous expression
// or an arrow function (the name field can be set through the API,
// which does not change this flag).
DECL_BOOLEAN_ACCESSORS(is_anonymous_expression)
// Indicates that the function represented by the shared function info was // Indicates that the function represented by the shared function info was
// classed as an immediately invoked function execution (IIFE) function and // classed as an immediately invoked function execution (IIFE) function and
// is only executed once. // is only executed once.
...@@ -684,21 +677,18 @@ class SharedFunctionInfo : public HeapObject { ...@@ -684,21 +677,18 @@ class SharedFunctionInfo : public HeapObject {
V(FunctionKindBits, FunctionKind, 5, _) \ V(FunctionKindBits, FunctionKind, 5, _) \
V(IsNativeBit, bool, 1, _) \ V(IsNativeBit, bool, 1, _) \
V(IsStrictBit, bool, 1, _) \ V(IsStrictBit, bool, 1, _) \
V(IsWrappedBit, bool, 1, _) \ V(FunctionSyntaxKindBits, FunctionSyntaxKind, 3, _) \
V(IsClassConstructorBit, bool, 1, _) \ V(IsClassConstructorBit, bool, 1, _) \
V(HasDuplicateParametersBit, bool, 1, _) \ V(HasDuplicateParametersBit, bool, 1, _) \
V(AllowLazyCompilationBit, bool, 1, _) \ V(AllowLazyCompilationBit, bool, 1, _) \
V(NeedsHomeObjectBit, bool, 1, _) \ V(NeedsHomeObjectBit, bool, 1, _) \
V(IsDeclarationBit, bool, 1, _) \
V(IsAsmWasmBrokenBit, bool, 1, _) \ V(IsAsmWasmBrokenBit, bool, 1, _) \
V(FunctionMapIndexBits, int, 5, _) \ V(FunctionMapIndexBits, int, 5, _) \
V(DisabledOptimizationReasonBits, BailoutReason, 4, _) \ V(DisabledOptimizationReasonBits, BailoutReason, 4, _) \
V(RequiresInstanceMembersInitializer, bool, 1, _) \ V(RequiresInstanceMembersInitializer, bool, 1, _) \
V(ConstructAsBuiltinBit, bool, 1, _) \ V(ConstructAsBuiltinBit, bool, 1, _) \
V(IsAnonymousExpressionBit, bool, 1, _) \
V(NameShouldPrintAsAnonymousBit, bool, 1, _) \ V(NameShouldPrintAsAnonymousBit, bool, 1, _) \
V(HasReportedBinaryCoverageBit, bool, 1, _) \ V(HasReportedBinaryCoverageBit, bool, 1, _) \
V(IsNamedExpressionBit, bool, 1, _) \
V(IsTopLevelBit, bool, 1, _) \ V(IsTopLevelBit, bool, 1, _) \
V(IsOneshotIIFEOrPropertiesAreFinalBit, bool, 1, _) \ V(IsOneshotIIFEOrPropertiesAreFinalBit, bool, 1, _) \
V(IsSafeToSkipArgumentsAdaptorBit, bool, 1, _) V(IsSafeToSkipArgumentsAdaptorBit, bool, 1, _)
...@@ -710,6 +700,8 @@ class SharedFunctionInfo : public HeapObject { ...@@ -710,6 +700,8 @@ class SharedFunctionInfo : public HeapObject {
DisabledOptimizationReasonBits::kMax); DisabledOptimizationReasonBits::kMax);
STATIC_ASSERT(kLastFunctionKind <= FunctionKindBits::kMax); STATIC_ASSERT(kLastFunctionKind <= FunctionKindBits::kMax);
STATIC_ASSERT(FunctionSyntaxKind::kLastFunctionSyntaxKind <=
FunctionSyntaxKindBits::kMax);
// Indicates that this function uses a super property (or an eval that may // Indicates that this function uses a super property (or an eval that may
// use a super property). // use a super property).
......
...@@ -28,6 +28,7 @@ ParseInfo::ParseInfo(AccountingAllocator* zone_allocator) ...@@ -28,6 +28,7 @@ ParseInfo::ParseInfo(AccountingAllocator* zone_allocator)
stack_limit_(0), stack_limit_(0),
hash_seed_(0), hash_seed_(0),
function_kind_(FunctionKind::kNormalFunction), function_kind_(FunctionKind::kNormalFunction),
function_syntax_kind_(FunctionSyntaxKind::kDeclaration),
script_id_(-1), script_id_(-1),
start_position_(0), start_position_(0),
end_position_(0), end_position_(0),
...@@ -75,15 +76,13 @@ ParseInfo::ParseInfo(Isolate* isolate) ...@@ -75,15 +76,13 @@ ParseInfo::ParseInfo(Isolate* isolate)
template <typename T> template <typename T>
void ParseInfo::SetFunctionInfo(T function) { void ParseInfo::SetFunctionInfo(T function) {
set_is_named_expression(function->is_named_expression());
set_language_mode(function->language_mode()); set_language_mode(function->language_mode());
set_function_kind(function->kind()); set_function_kind(function->kind());
set_declaration(function->is_declaration()); set_function_syntax_kind(function->syntax_kind());
set_requires_instance_members_initializer( set_requires_instance_members_initializer(
function->requires_instance_members_initializer()); function->requires_instance_members_initializer());
set_toplevel(function->is_toplevel()); set_toplevel(function->is_toplevel());
set_is_oneshot_iife(function->is_oneshot_iife()); set_is_oneshot_iife(function->is_oneshot_iife());
set_wrapped_as_function(function->is_wrapped());
} }
ParseInfo::ParseInfo(Isolate* isolate, Handle<SharedFunctionInfo> shared) ParseInfo::ParseInfo(Isolate* isolate, Handle<SharedFunctionInfo> shared)
...@@ -221,7 +220,9 @@ void ParseInfo::SetScriptForToplevelCompile(Isolate* isolate, ...@@ -221,7 +220,9 @@ void ParseInfo::SetScriptForToplevelCompile(Isolate* isolate,
set_toplevel(); set_toplevel();
set_collect_type_profile(isolate->is_collecting_type_profile() && set_collect_type_profile(isolate->is_collecting_type_profile() &&
script->IsUserJavaScript()); script->IsUserJavaScript());
set_wrapped_as_function(script->is_wrapped()); if (script->is_wrapped()) {
set_function_syntax_kind(FunctionSyntaxKind::kWrapped);
}
} }
void ParseInfo::set_script(Handle<Script> script) { void ParseInfo::set_script(Handle<Script> script) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/handles/handles.h" #include "src/handles/handles.h"
#include "src/objects/function-kind.h" #include "src/objects/function-kind.h"
#include "src/objects/function-syntax-kind.h"
#include "src/objects/script.h" #include "src/objects/script.h"
#include "src/parsing/pending-compilation-error-handler.h" #include "src/parsing/pending-compilation-error-handler.h"
#include "src/parsing/preparse-data.h" #include "src/parsing/preparse-data.h"
...@@ -75,8 +76,6 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -75,8 +76,6 @@ class V8_EXPORT_PRIVATE ParseInfo {
FLAG_ACCESSOR(kStrictMode, is_strict_mode, set_strict_mode) FLAG_ACCESSOR(kStrictMode, is_strict_mode, set_strict_mode)
FLAG_ACCESSOR(kModule, is_module, set_module) FLAG_ACCESSOR(kModule, is_module, set_module)
FLAG_ACCESSOR(kAllowLazyParsing, allow_lazy_parsing, set_allow_lazy_parsing) FLAG_ACCESSOR(kAllowLazyParsing, allow_lazy_parsing, set_allow_lazy_parsing)
FLAG_ACCESSOR(kIsNamedExpression, is_named_expression,
set_is_named_expression)
FLAG_ACCESSOR(kLazyCompile, lazy_compile, set_lazy_compile) FLAG_ACCESSOR(kLazyCompile, lazy_compile, set_lazy_compile)
FLAG_ACCESSOR(kCollectTypeProfile, collect_type_profile, FLAG_ACCESSOR(kCollectTypeProfile, collect_type_profile,
set_collect_type_profile) set_collect_type_profile)
...@@ -88,10 +87,7 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -88,10 +87,7 @@ class V8_EXPORT_PRIVATE ParseInfo {
set_block_coverage_enabled) set_block_coverage_enabled)
FLAG_ACCESSOR(kOnBackgroundThread, on_background_thread, FLAG_ACCESSOR(kOnBackgroundThread, on_background_thread,
set_on_background_thread) set_on_background_thread)
FLAG_ACCESSOR(kWrappedAsFunction, is_wrapped_as_function,
set_wrapped_as_function)
FLAG_ACCESSOR(kAllowEvalCache, allow_eval_cache, set_allow_eval_cache) FLAG_ACCESSOR(kAllowEvalCache, allow_eval_cache, set_allow_eval_cache)
FLAG_ACCESSOR(kIsDeclaration, is_declaration, set_declaration)
FLAG_ACCESSOR(kRequiresInstanceMembersInitializer, FLAG_ACCESSOR(kRequiresInstanceMembersInitializer,
requires_instance_members_initializer, requires_instance_members_initializer,
set_requires_instance_members_initializer) set_requires_instance_members_initializer)
...@@ -192,6 +188,17 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -192,6 +188,17 @@ class V8_EXPORT_PRIVATE ParseInfo {
function_kind_ = function_kind; function_kind_ = function_kind;
} }
FunctionSyntaxKind function_syntax_kind() const {
return function_syntax_kind_;
}
void set_function_syntax_kind(FunctionSyntaxKind function_syntax_kind) {
function_syntax_kind_ = function_syntax_kind;
}
bool is_wrapped_as_function() const {
return function_syntax_kind() == FunctionSyntaxKind::kWrapped;
}
int max_function_literal_id() const { return max_function_literal_id_; } int max_function_literal_id() const { return max_function_literal_id_; }
void set_max_function_literal_id(int max_function_literal_id) { void set_max_function_literal_id(int max_function_literal_id) {
max_function_literal_id_ = max_function_literal_id; max_function_literal_id_ = max_function_literal_id;
...@@ -280,7 +287,7 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -280,7 +287,7 @@ class V8_EXPORT_PRIVATE ParseInfo {
void SetFunctionInfo(T function); void SetFunctionInfo(T function);
// Various configuration flags for parsing. // Various configuration flags for parsing.
enum Flag : uint64_t { enum Flag : uint32_t {
// ---------- Input flags --------------------------- // ---------- Input flags ---------------------------
kToplevel = 1 << 0, kToplevel = 1 << 0,
kEager = 1 << 1, kEager = 1 << 1,
...@@ -290,41 +297,39 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -290,41 +297,39 @@ class V8_EXPORT_PRIVATE ParseInfo {
kParseRestriction = 1 << 5, kParseRestriction = 1 << 5,
kModule = 1 << 6, kModule = 1 << 6,
kAllowLazyParsing = 1 << 7, kAllowLazyParsing = 1 << 7,
kIsNamedExpression = 1 << 8, kLazyCompile = 1 << 8,
kLazyCompile = 1 << 9, kCollectTypeProfile = 1 << 9,
kCollectTypeProfile = 1 << 10, kCoverageEnabled = 1 << 10,
kCoverageEnabled = 1 << 11, kBlockCoverageEnabled = 1 << 11,
kBlockCoverageEnabled = 1 << 12, kIsAsmWasmBroken = 1 << 12,
kIsAsmWasmBroken = 1 << 13, kOnBackgroundThread = 1 << 13,
kOnBackgroundThread = 1 << 14, kAllowEvalCache = 1 << 14,
kWrappedAsFunction = 1 << 15, // Implicitly wrapped as function. kRequiresInstanceMembersInitializer = 1 << 15,
kAllowEvalCache = 1 << 16, kContainsAsmModule = 1 << 16,
kIsDeclaration = 1 << 17, kMightAlwaysOpt = 1 << 17,
kRequiresInstanceMembersInitializer = 1 << 18, kAllowLazyCompile = 1 << 18,
kContainsAsmModule = 1 << 19, kAllowNativeSyntax = 1 << 19,
kMightAlwaysOpt = 1 << 20, kAllowHarmonyPublicFields = 1 << 20,
kAllowLazyCompile = 1 << 21, kAllowHarmonyStaticFields = 1 << 21,
kAllowNativeSyntax = 1 << 22, kAllowHarmonyDynamicImport = 1 << 22,
kAllowHarmonyPublicFields = 1 << 23, kAllowHarmonyImportMeta = 1 << 23,
kAllowHarmonyStaticFields = 1 << 24, kAllowHarmonyOptionalChaining = 1 << 24,
kAllowHarmonyDynamicImport = 1 << 25, kAllowHarmonyPrivateFields = 1 << 25,
kAllowHarmonyImportMeta = 1 << 26, kAllowHarmonyPrivateMethods = 1 << 26,
kAllowHarmonyOptionalChaining = 1 << 27, kIsOneshotIIFE = 1 << 27,
kAllowHarmonyPrivateFields = 1 << 28, kCollectSourcePositions = 1 << 28,
kAllowHarmonyPrivateMethods = 1 << 29, kAllowHarmonyNullish = 1 << 29,
kIsOneshotIIFE = 1 << 30,
kCollectSourcePositions = static_cast<uint64_t>(1) << 31,
kAllowHarmonyNullish = static_cast<uint64_t>(1) << 32,
}; };
//------------- Inputs to parsing and scope analysis ----------------------- //------------- Inputs to parsing and scope analysis -----------------------
std::unique_ptr<Zone> zone_; std::unique_ptr<Zone> zone_;
uint64_t flags_; uint32_t flags_;
v8::Extension* extension_; v8::Extension* extension_;
DeclarationScope* script_scope_; DeclarationScope* script_scope_;
uintptr_t stack_limit_; uintptr_t stack_limit_;
uint64_t hash_seed_; uint64_t hash_seed_;
FunctionKind function_kind_; FunctionKind function_kind_;
FunctionSyntaxKind function_syntax_kind_;
int script_id_; int script_id_;
int start_position_; int start_position_;
int end_position_; int end_position_;
......
...@@ -1128,7 +1128,7 @@ class ParserBase { ...@@ -1128,7 +1128,7 @@ class ParserBase {
void ParseFunctionBody(StatementListT* body, IdentifierT function_name, void ParseFunctionBody(StatementListT* body, IdentifierT function_name,
int pos, const FormalParametersT& parameters, int pos, const FormalParametersT& parameters,
FunctionKind kind, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
FunctionBodyType body_type); FunctionBodyType body_type);
// Check if the scope has conflicting var/let declarations from different // Check if the scope has conflicting var/let declarations from different
...@@ -2236,7 +2236,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info, ...@@ -2236,7 +2236,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
ExpressionT value = impl()->ParseFunctionLiteral( ExpressionT value = impl()->ParseFunctionLiteral(
prop_info->name, scanner()->location(), kSkipFunctionNameCheck, kind, prop_info->name, scanner()->location(), kSkipFunctionNameCheck, kind,
name_token_position, FunctionLiteral::kAccessorOrMethod, name_token_position, FunctionSyntaxKind::kAccessorOrMethod,
language_mode(), nullptr); language_mode(), nullptr);
ClassLiteralPropertyT result = factory()->NewClassLiteralProperty( ClassLiteralPropertyT result = factory()->NewClassLiteralProperty(
...@@ -2268,7 +2268,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info, ...@@ -2268,7 +2268,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
FunctionLiteralT value = impl()->ParseFunctionLiteral( FunctionLiteralT value = impl()->ParseFunctionLiteral(
prop_info->name, scanner()->location(), kSkipFunctionNameCheck, kind, prop_info->name, scanner()->location(), kSkipFunctionNameCheck, kind,
name_token_position, FunctionLiteral::kAccessorOrMethod, name_token_position, FunctionSyntaxKind::kAccessorOrMethod,
language_mode(), nullptr); language_mode(), nullptr);
ClassLiteralProperty::Kind property_kind = ClassLiteralProperty::Kind property_kind =
...@@ -2449,8 +2449,8 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info, ...@@ -2449,8 +2449,8 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info,
ExpressionT value = impl()->ParseFunctionLiteral( ExpressionT value = impl()->ParseFunctionLiteral(
name, scanner()->location(), kSkipFunctionNameCheck, kind, name, scanner()->location(), kSkipFunctionNameCheck, kind,
next_loc.beg_pos, FunctionLiteral::kAccessorOrMethod, language_mode(), next_loc.beg_pos, FunctionSyntaxKind::kAccessorOrMethod,
nullptr); language_mode(), nullptr);
ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty( ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty(
name_expression, value, ObjectLiteralProperty::COMPUTED, name_expression, value, ObjectLiteralProperty::COMPUTED,
...@@ -2481,8 +2481,8 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info, ...@@ -2481,8 +2481,8 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info,
FunctionLiteralT value = impl()->ParseFunctionLiteral( FunctionLiteralT value = impl()->ParseFunctionLiteral(
name, scanner()->location(), kSkipFunctionNameCheck, kind, name, scanner()->location(), kSkipFunctionNameCheck, kind,
next_loc.beg_pos, FunctionLiteral::kAccessorOrMethod, language_mode(), next_loc.beg_pos, FunctionSyntaxKind::kAccessorOrMethod,
nullptr); language_mode(), nullptr);
ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty( ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty(
name_expression, value, name_expression, value,
...@@ -3355,8 +3355,8 @@ ParserBase<Impl>::ParseFunctionExpression() { ...@@ -3355,8 +3355,8 @@ ParserBase<Impl>::ParseFunctionExpression() {
IdentifierT name = impl()->NullIdentifier(); IdentifierT name = impl()->NullIdentifier();
bool is_strict_reserved_name = Token::IsStrictReservedWord(peek()); bool is_strict_reserved_name = Token::IsStrictReservedWord(peek());
Scanner::Location function_name_location = Scanner::Location::invalid(); Scanner::Location function_name_location = Scanner::Location::invalid();
FunctionLiteral::FunctionType function_type = FunctionSyntaxKind function_syntax_kind =
FunctionLiteral::kAnonymousExpression; FunctionSyntaxKind::kAnonymousExpression;
if (impl()->ParsingDynamicFunctionDeclaration()) { if (impl()->ParsingDynamicFunctionDeclaration()) {
// We don't want dynamic functions to actually declare their name // We don't want dynamic functions to actually declare their name
// "anonymous". We just want that name in the toString(). // "anonymous". We just want that name in the toString().
...@@ -3367,14 +3367,14 @@ ParserBase<Impl>::ParseFunctionExpression() { ...@@ -3367,14 +3367,14 @@ ParserBase<Impl>::ParseFunctionExpression() {
} else if (peek_any_identifier()) { } else if (peek_any_identifier()) {
name = ParseIdentifier(function_kind); name = ParseIdentifier(function_kind);
function_name_location = scanner()->location(); function_name_location = scanner()->location();
function_type = FunctionLiteral::kNamedExpression; function_syntax_kind = FunctionSyntaxKind::kNamedExpression;
} }
FunctionLiteralT result = impl()->ParseFunctionLiteral( FunctionLiteralT result = impl()->ParseFunctionLiteral(
name, function_name_location, name, function_name_location,
is_strict_reserved_name ? kFunctionNameIsStrictReserved is_strict_reserved_name ? kFunctionNameIsStrictReserved
: kFunctionNameValidityUnknown, : kFunctionNameValidityUnknown,
function_kind, function_token_position, function_type, language_mode(), function_kind, function_token_position, function_syntax_kind,
nullptr); language_mode(), nullptr);
// TODO(verwaest): FailureFunctionLiteral? // TODO(verwaest): FailureFunctionLiteral?
if (impl()->IsNull(result)) return impl()->FailureExpression(); if (impl()->IsNull(result)) return impl()->FailureExpression();
return result; return result;
...@@ -3882,7 +3882,7 @@ ParserBase<Impl>::ParseHoistableDeclaration( ...@@ -3882,7 +3882,7 @@ ParserBase<Impl>::ParseHoistableDeclaration(
FunctionLiteralT function = impl()->ParseFunctionLiteral( FunctionLiteralT function = impl()->ParseFunctionLiteral(
name, scanner()->location(), name_validity, function_kind, pos, name, scanner()->location(), name_validity, function_kind, pos,
FunctionLiteral::kDeclaration, language_mode(), nullptr); FunctionSyntaxKind::kDeclaration, language_mode(), nullptr);
// In ES6, a function behaves as a lexical binding, except in // In ES6, a function behaves as a lexical binding, except in
// a script scope, or the initial scope of eval or another function. // a script scope, or the initial scope of eval or another function.
...@@ -3992,7 +3992,7 @@ template <typename Impl> ...@@ -3992,7 +3992,7 @@ template <typename Impl>
void ParserBase<Impl>::ParseFunctionBody( void ParserBase<Impl>::ParseFunctionBody(
StatementListT* body, IdentifierT function_name, int pos, StatementListT* body, IdentifierT function_name, int pos,
const FormalParametersT& parameters, FunctionKind kind, const FormalParametersT& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionBodyType body_type) { FunctionSyntaxKind function_syntax_kind, FunctionBodyType body_type) {
FunctionBodyParsingScope body_parsing_scope(impl()); FunctionBodyParsingScope body_parsing_scope(impl());
if (IsResumableFunction(kind)) impl()->PrepareGeneratorVariables(); if (IsResumableFunction(kind)) impl()->PrepareGeneratorVariables();
...@@ -4035,9 +4035,9 @@ void ParserBase<Impl>::ParseFunctionBody( ...@@ -4035,9 +4035,9 @@ void ParserBase<Impl>::ParseFunctionBody(
DCHECK_EQ(FunctionBodyType::kBlock, body_type); DCHECK_EQ(FunctionBodyType::kBlock, body_type);
// If we are parsing the source as if it is wrapped in a function, the // If we are parsing the source as if it is wrapped in a function, the
// source ends without a closing brace. // source ends without a closing brace.
Token::Value closing_token = function_type == FunctionLiteral::kWrapped Token::Value closing_token =
? Token::EOS function_syntax_kind == FunctionSyntaxKind::kWrapped ? Token::EOS
: Token::RBRACE; : Token::RBRACE;
if (IsAsyncGeneratorFunction(kind)) { if (IsAsyncGeneratorFunction(kind)) {
impl()->ParseAndRewriteAsyncGeneratorFunctionBody(pos, kind, impl()->ParseAndRewriteAsyncGeneratorFunctionBody(pos, kind,
...@@ -4110,7 +4110,8 @@ void ParserBase<Impl>::ParseFunctionBody( ...@@ -4110,7 +4110,8 @@ void ParserBase<Impl>::ParseFunctionBody(
function_scope->DeclareArguments(ast_value_factory()); function_scope->DeclareArguments(ast_value_factory());
} }
impl()->DeclareFunctionNameVar(function_name, function_type, function_scope); impl()->DeclareFunctionNameVar(function_name, function_syntax_kind,
function_scope);
inner_body.MergeInto(body); inner_body.MergeInto(body);
} }
...@@ -4237,7 +4238,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -4237,7 +4238,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
int dummy_function_length = -1; int dummy_function_length = -1;
DCHECK_NE(kind & FunctionKind::kArrowFunction, 0); DCHECK_NE(kind & FunctionKind::kArrowFunction, 0);
bool did_preparse_successfully = impl()->SkipFunction( bool did_preparse_successfully = impl()->SkipFunction(
nullptr, kind, FunctionLiteral::kAnonymousExpression, nullptr, kind, FunctionSyntaxKind::kAnonymousExpression,
formal_parameters.scope, &dummy_num_parameters, formal_parameters.scope, &dummy_num_parameters,
&dummy_function_length, &produced_preparse_data); &dummy_function_length, &produced_preparse_data);
...@@ -4273,7 +4274,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -4273,7 +4274,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
AcceptINScope scope(this, true); AcceptINScope scope(this, true);
ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition, ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition,
parameters, kind, parameters, kind,
FunctionLiteral::kAnonymousExpression, FunctionSyntaxKind::kAnonymousExpression,
FunctionBodyType::kBlock); FunctionBodyType::kBlock);
CHECK(has_error()); CHECK(has_error());
return impl()->FailureExpression(); return impl()->FailureExpression();
...@@ -4283,7 +4284,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -4283,7 +4284,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
AcceptINScope scope(this, true); AcceptINScope scope(this, true);
ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition, ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition,
formal_parameters, kind, formal_parameters, kind,
FunctionLiteral::kAnonymousExpression, FunctionSyntaxKind::kAnonymousExpression,
FunctionBodyType::kBlock); FunctionBodyType::kBlock);
expected_property_count = function_state.expected_property_count(); expected_property_count = function_state.expected_property_count();
} }
...@@ -4292,7 +4293,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -4292,7 +4293,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
has_braces = false; has_braces = false;
ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition, ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition,
formal_parameters, kind, formal_parameters, kind,
FunctionLiteral::kAnonymousExpression, FunctionSyntaxKind::kAnonymousExpression,
FunctionBodyType::kExpression); FunctionBodyType::kExpression);
expected_property_count = function_state.expected_property_count(); expected_property_count = function_state.expected_property_count();
} }
...@@ -4312,7 +4313,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -4312,7 +4313,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
expected_property_count, formal_parameters.num_parameters(), expected_property_count, formal_parameters.num_parameters(),
formal_parameters.function_length, formal_parameters.function_length,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, eager_compile_hint, FunctionSyntaxKind::kAnonymousExpression, eager_compile_hint,
formal_parameters.scope->start_position(), has_braces, formal_parameters.scope->start_position(), has_braces,
function_literal_id, produced_preparse_data); function_literal_id, produced_preparse_data);
...@@ -4476,7 +4477,7 @@ ParserBase<Impl>::ParseAsyncFunctionLiteral() { ...@@ -4476,7 +4477,7 @@ ParserBase<Impl>::ParseAsyncFunctionLiteral() {
int pos = position(); int pos = position();
Consume(Token::FUNCTION); Consume(Token::FUNCTION);
IdentifierT name = impl()->NullIdentifier(); IdentifierT name = impl()->NullIdentifier();
FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression; FunctionSyntaxKind syntax_kind = FunctionSyntaxKind::kAnonymousExpression;
ParseFunctionFlags flags = ParseFunctionFlag::kIsAsync; ParseFunctionFlags flags = ParseFunctionFlag::kIsAsync;
if (Check(Token::MUL)) flags |= ParseFunctionFlag::kIsGenerator; if (Check(Token::MUL)) flags |= ParseFunctionFlag::kIsGenerator;
...@@ -4494,14 +4495,14 @@ ParserBase<Impl>::ParseAsyncFunctionLiteral() { ...@@ -4494,14 +4495,14 @@ ParserBase<Impl>::ParseAsyncFunctionLiteral() {
scanner()->CurrentSymbol(ast_value_factory()) == scanner()->CurrentSymbol(ast_value_factory()) ==
ast_value_factory()->anonymous_string()); ast_value_factory()->anonymous_string());
} else if (peek_any_identifier()) { } else if (peek_any_identifier()) {
type = FunctionLiteral::kNamedExpression; syntax_kind = FunctionSyntaxKind::kNamedExpression;
name = ParseIdentifier(kind); name = ParseIdentifier(kind);
} }
FunctionLiteralT result = impl()->ParseFunctionLiteral( FunctionLiteralT result = impl()->ParseFunctionLiteral(
name, scanner()->location(), name, scanner()->location(),
is_strict_reserved ? kFunctionNameIsStrictReserved is_strict_reserved ? kFunctionNameIsStrictReserved
: kFunctionNameValidityUnknown, : kFunctionNameValidityUnknown,
kind, pos, type, language_mode(), nullptr); kind, pos, syntax_kind, language_mode(), nullptr);
if (impl()->IsNull(result)) return impl()->FailureExpression(); if (impl()->IsNull(result)) return impl()->FailureExpression();
return result; return result;
} }
......
...@@ -78,8 +78,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, ...@@ -78,8 +78,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
FunctionLiteral* function_literal = factory()->NewFunctionLiteral( FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
name, function_scope, body, expected_property_count, parameter_count, name, function_scope, body, expected_property_count, parameter_count,
parameter_count, FunctionLiteral::kNoDuplicateParameters, parameter_count, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, default_eager_compile_hint(), pos, FunctionSyntaxKind::kAnonymousExpression, default_eager_compile_hint(),
true, GetNextFunctionLiteralId()); pos, true, GetNextFunctionLiteralId());
return function_literal; return function_literal;
} }
...@@ -677,7 +677,7 @@ void Parser::ParseWrapped(Isolate* isolate, ParseInfo* info, ...@@ -677,7 +677,7 @@ void Parser::ParseWrapped(Isolate* isolate, ParseInfo* info,
FunctionLiteral* function_literal = ParseFunctionLiteral( FunctionLiteral* function_literal = ParseFunctionLiteral(
function_name, location, kSkipFunctionNameCheck, kNormalFunction, function_name, location, kSkipFunctionNameCheck, kNormalFunction,
kNoSourcePosition, FunctionLiteral::kWrapped, LanguageMode::kSloppy, kNoSourcePosition, FunctionSyntaxKind::kWrapped, LanguageMode::kSloppy,
arguments_for_wrapped_function); arguments_for_wrapped_function);
Statement* return_statement = factory()->NewReturnStatement( Statement* return_statement = factory()->NewReturnStatement(
...@@ -729,20 +729,6 @@ FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info, ...@@ -729,20 +729,6 @@ FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info,
return result; return result;
} }
static FunctionLiteral::FunctionType ComputeFunctionType(ParseInfo* info) {
if (info->is_wrapped_as_function()) {
return FunctionLiteral::kWrapped;
} else if (info->is_declaration()) {
return FunctionLiteral::kDeclaration;
} else if (info->is_named_expression()) {
return FunctionLiteral::kNamedExpression;
} else if (IsConciseMethod(info->function_kind()) ||
IsAccessorFunction(info->function_kind())) {
return FunctionLiteral::kAccessorOrMethod;
}
return FunctionLiteral::kAnonymousExpression;
}
FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info, FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
const AstRawString* raw_name) { const AstRawString* raw_name) {
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr); DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
...@@ -771,8 +757,10 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info, ...@@ -771,8 +757,10 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
BlockState block_state(&scope_, outer); BlockState block_state(&scope_, outer);
DCHECK(is_sloppy(outer->language_mode()) || DCHECK(is_sloppy(outer->language_mode()) ||
is_strict(info->language_mode())); is_strict(info->language_mode()));
FunctionLiteral::FunctionType function_type = ComputeFunctionType(info);
FunctionKind kind = info->function_kind(); FunctionKind kind = info->function_kind();
DCHECK_IMPLIES(
IsConciseMethod(kind) || IsAccessorFunction(kind),
info->function_syntax_kind() == FunctionSyntaxKind::kAccessorOrMethod);
if (IsArrowFunction(kind)) { if (IsArrowFunction(kind)) {
if (IsAsyncFunction(kind)) { if (IsAsyncFunction(kind)) {
...@@ -858,8 +846,8 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info, ...@@ -858,8 +846,8 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
: nullptr; : nullptr;
result = ParseFunctionLiteral( result = ParseFunctionLiteral(
raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind, raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind,
kNoSourcePosition, function_type, info->language_mode(), kNoSourcePosition, info->function_syntax_kind(),
arguments_for_wrapped_function); info->language_mode(), arguments_for_wrapped_function);
} }
if (has_error()) return nullptr; if (has_error()) return nullptr;
...@@ -1793,9 +1781,9 @@ void Parser::ParseAndRewriteAsyncGeneratorFunctionBody( ...@@ -1793,9 +1781,9 @@ void Parser::ParseAndRewriteAsyncGeneratorFunctionBody(
} }
void Parser::DeclareFunctionNameVar(const AstRawString* function_name, void Parser::DeclareFunctionNameVar(const AstRawString* function_name,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope) { DeclarationScope* function_scope) {
if (function_type == FunctionLiteral::kNamedExpression && if (function_syntax_kind == FunctionSyntaxKind::kNamedExpression &&
function_scope->LookupLocal(function_name) == nullptr) { function_scope->LookupLocal(function_name) == nullptr) {
DCHECK_EQ(function_scope, scope()); DCHECK_EQ(function_scope, scope());
function_scope->DeclareFunctionVar(function_name); function_scope->DeclareFunctionVar(function_name);
...@@ -2240,7 +2228,7 @@ void Parser::PrepareGeneratorVariables() { ...@@ -2240,7 +2228,7 @@ void Parser::PrepareGeneratorVariables() {
FunctionLiteral* Parser::ParseFunctionLiteral( FunctionLiteral* Parser::ParseFunctionLiteral(
const AstRawString* function_name, Scanner::Location function_name_location, const AstRawString* function_name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind, FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_pos, FunctionLiteral::FunctionType function_type, int function_token_pos, FunctionSyntaxKind function_syntax_kind,
LanguageMode language_mode, LanguageMode language_mode,
ZonePtrList<const AstRawString>* arguments_for_wrapped_function) { ZonePtrList<const AstRawString>* arguments_for_wrapped_function) {
// Function :: // Function ::
...@@ -2252,7 +2240,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2252,7 +2240,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Setter :: // Setter ::
// '(' PropertySetParameterList ')' '{' FunctionBody '}' // '(' PropertySetParameterList ')' '{' FunctionBody '}'
bool is_wrapped = function_type == FunctionLiteral::kWrapped; bool is_wrapped = function_syntax_kind == FunctionSyntaxKind::kWrapped;
DCHECK_EQ(is_wrapped, arguments_for_wrapped_function != nullptr); DCHECK_EQ(is_wrapped, arguments_for_wrapped_function != nullptr);
int pos = function_token_pos == kNoSourcePosition ? peek_position() int pos = function_token_pos == kNoSourcePosition ? peek_position()
...@@ -2387,15 +2375,15 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2387,15 +2375,15 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// try to lazy parse in the first place, we'll have to parse eagerly. // try to lazy parse in the first place, we'll have to parse eagerly.
bool did_preparse_successfully = bool did_preparse_successfully =
should_preparse && should_preparse &&
SkipFunction(function_name, kind, function_type, scope, &num_parameters, SkipFunction(function_name, kind, function_syntax_kind, scope,
&function_length, &produced_preparse_data); &num_parameters, &function_length, &produced_preparse_data);
if (!did_preparse_successfully) { if (!did_preparse_successfully) {
// If skipping aborted, it rewound the scanner until before the LPAREN. // If skipping aborted, it rewound the scanner until before the LPAREN.
// Consume it in that case. // Consume it in that case.
if (should_preparse) Consume(Token::LPAREN); if (should_preparse) Consume(Token::LPAREN);
should_post_parallel_task = false; should_post_parallel_task = false;
ParseFunction(&body, function_name, pos, kind, function_type, scope, ParseFunction(&body, function_name, pos, kind, function_syntax_kind, scope,
&num_parameters, &function_length, &has_duplicate_parameters, &num_parameters, &function_length, &has_duplicate_parameters,
&expected_property_count, &suspend_count, &expected_property_count, &suspend_count,
arguments_for_wrapped_function); arguments_for_wrapped_function);
...@@ -2441,8 +2429,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2441,8 +2429,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Note that the FunctionLiteral needs to be created in the main Zone again. // Note that the FunctionLiteral needs to be created in the main Zone again.
FunctionLiteral* function_literal = factory()->NewFunctionLiteral( FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
function_name, scope, body, expected_property_count, num_parameters, function_name, scope, body, expected_property_count, num_parameters,
function_length, duplicate_parameters, function_type, eager_compile_hint, function_length, duplicate_parameters, function_syntax_kind,
pos, true, function_literal_id, produced_preparse_data); eager_compile_hint, pos, true, function_literal_id,
produced_preparse_data);
function_literal->set_function_token_position(function_token_pos); function_literal->set_function_token_position(function_token_pos);
function_literal->set_suspend_count(suspend_count); function_literal->set_suspend_count(suspend_count);
...@@ -2460,7 +2449,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2460,7 +2449,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
} }
bool Parser::SkipFunction(const AstRawString* function_name, FunctionKind kind, bool Parser::SkipFunction(const AstRawString* function_name, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope, int* num_parameters, DeclarationScope* function_scope, int* num_parameters,
int* function_length, int* function_length,
ProducedPreparseData** produced_preparse_data) { ProducedPreparseData** produced_preparse_data) {
...@@ -2515,7 +2504,7 @@ bool Parser::SkipFunction(const AstRawString* function_name, FunctionKind kind, ...@@ -2515,7 +2504,7 @@ bool Parser::SkipFunction(const AstRawString* function_name, FunctionKind kind,
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse");
PreParser::PreParseResult result = reusable_preparser()->PreParseFunction( PreParser::PreParseResult result = reusable_preparser()->PreParseFunction(
function_name, kind, function_type, function_scope, use_counts_, function_name, kind, function_syntax_kind, function_scope, use_counts_,
produced_preparse_data, this->script_id()); produced_preparse_data, this->script_id());
if (result == PreParser::kPreParseStackOverflow) { if (result == PreParser::kPreParseStackOverflow) {
...@@ -2680,7 +2669,7 @@ Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) { ...@@ -2680,7 +2669,7 @@ Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) {
void Parser::ParseFunction( void Parser::ParseFunction(
ScopedPtrList<Statement>* body, const AstRawString* function_name, int pos, ScopedPtrList<Statement>* body, const AstRawString* function_name, int pos,
FunctionKind kind, FunctionLiteral::FunctionType function_type, FunctionKind kind, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope, int* num_parameters, int* function_length, DeclarationScope* function_scope, int* num_parameters, int* function_length,
bool* has_duplicate_parameters, int* expected_property_count, bool* has_duplicate_parameters, int* expected_property_count,
int* suspend_count, int* suspend_count,
...@@ -2689,7 +2678,7 @@ void Parser::ParseFunction( ...@@ -2689,7 +2678,7 @@ void Parser::ParseFunction(
FunctionState function_state(&function_state_, &scope_, function_scope); FunctionState function_state(&function_state_, &scope_, function_scope);
bool is_wrapped = function_type == FunctionLiteral::kWrapped; bool is_wrapped = function_syntax_kind == FunctionSyntaxKind::kWrapped;
int expected_parameters_end_pos = parameters_end_pos_; int expected_parameters_end_pos = parameters_end_pos_;
if (expected_parameters_end_pos != kNoSourcePosition) { if (expected_parameters_end_pos != kNoSourcePosition) {
...@@ -2751,8 +2740,8 @@ void Parser::ParseFunction( ...@@ -2751,8 +2740,8 @@ void Parser::ParseFunction(
*function_length = formals.function_length; *function_length = formals.function_length;
AcceptINScope scope(this, true); AcceptINScope scope(this, true);
ParseFunctionBody(body, function_name, pos, formals, kind, function_type, ParseFunctionBody(body, function_name, pos, formals, kind,
FunctionBodyType::kBlock); function_syntax_kind, FunctionBodyType::kBlock);
*has_duplicate_parameters = formals.has_duplicate(); *has_duplicate_parameters = formals.has_duplicate();
...@@ -2882,7 +2871,7 @@ FunctionLiteral* Parser::CreateInitializerFunction( ...@@ -2882,7 +2871,7 @@ FunctionLiteral* Parser::CreateInitializerFunction(
FunctionLiteral* result = factory()->NewFunctionLiteral( FunctionLiteral* result = factory()->NewFunctionLiteral(
ast_value_factory()->GetOneByteString(name), scope, statements, 0, 0, 0, ast_value_factory()->GetOneByteString(name), scope, statements, 0, 0, 0,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, FunctionSyntaxKind::kAccessorOrMethod,
FunctionLiteral::kShouldEagerCompile, scope->start_position(), false, FunctionLiteral::kShouldEagerCompile, scope->start_position(), false,
GetNextFunctionLiteralId()); GetNextFunctionLiteralId());
......
...@@ -291,7 +291,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -291,7 +291,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
void ParseAndRewriteAsyncGeneratorFunctionBody( void ParseAndRewriteAsyncGeneratorFunctionBody(
int pos, FunctionKind kind, ScopedPtrList<Statement>* body); int pos, FunctionKind kind, ScopedPtrList<Statement>* body);
void DeclareFunctionNameVar(const AstRawString* function_name, void DeclareFunctionNameVar(const AstRawString* function_name,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope); DeclarationScope* function_scope);
Statement* DeclareFunction(const AstRawString* variable_name, Statement* DeclareFunction(const AstRawString* variable_name,
...@@ -366,7 +366,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -366,7 +366,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
FunctionLiteral* ParseFunctionLiteral( FunctionLiteral* ParseFunctionLiteral(
const AstRawString* name, Scanner::Location function_name_location, const AstRawString* name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind, FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_position, FunctionLiteral::FunctionType type, int function_token_position, FunctionSyntaxKind type,
LanguageMode language_mode, LanguageMode language_mode,
ZonePtrList<const AstRawString>* arguments_for_wrapped_function); ZonePtrList<const AstRawString>* arguments_for_wrapped_function);
...@@ -418,7 +418,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -418,7 +418,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// parsing or could not identify an error correctly, meaning the caller needs // parsing or could not identify an error correctly, meaning the caller needs
// to fully reparse. In this case it resets the scanner and preparser state. // to fully reparse. In this case it resets the scanner and preparser state.
bool SkipFunction(const AstRawString* function_name, FunctionKind kind, bool SkipFunction(const AstRawString* function_name, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope, int* num_parameters, DeclarationScope* function_scope, int* num_parameters,
int* function_length, int* function_length,
ProducedPreparseData** produced_preparsed_scope_data); ProducedPreparseData** produced_preparsed_scope_data);
...@@ -429,7 +429,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -429,7 +429,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
void ParseFunction( void ParseFunction(
ScopedPtrList<Statement>* body, const AstRawString* function_name, ScopedPtrList<Statement>* body, const AstRawString* function_name,
int pos, FunctionKind kind, FunctionLiteral::FunctionType function_type, int pos, FunctionKind kind, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope, int* num_parameters, DeclarationScope* function_scope, int* num_parameters,
int* function_length, bool* has_duplicate_parameters, int* function_length, bool* has_duplicate_parameters,
int* expected_property_count, int* suspend_count, int* expected_property_count, int* suspend_count,
......
...@@ -107,9 +107,9 @@ void PreParserFormalParameters::ValidateStrictMode(PreParser* preparser) const { ...@@ -107,9 +107,9 @@ void PreParserFormalParameters::ValidateStrictMode(PreParser* preparser) const {
PreParser::PreParseResult PreParser::PreParseFunction( PreParser::PreParseResult PreParser::PreParseFunction(
const AstRawString* function_name, FunctionKind kind, const AstRawString* function_name, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind, DeclarationScope* function_scope,
DeclarationScope* function_scope, int* use_counts, int* use_counts, ProducedPreparseData** produced_preparse_data,
ProducedPreparseData** produced_preparse_data, int script_id) { int script_id) {
DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type()); DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type());
use_counts_ = use_counts; use_counts_ = use_counts;
set_script_id(script_id); set_script_id(script_id);
...@@ -229,7 +229,8 @@ PreParser::PreParseResult PreParser::PreParseFunction( ...@@ -229,7 +229,8 @@ PreParser::PreParseResult PreParser::PreParseFunction(
// arguments'. // arguments'.
function_scope->DeclareArguments(ast_value_factory()); function_scope->DeclareArguments(ast_value_factory());
DeclareFunctionNameVar(function_name, function_type, function_scope); DeclareFunctionNameVar(function_name, function_syntax_kind,
function_scope);
if (preparse_data_builder_->HasData()) { if (preparse_data_builder_->HasData()) {
*produced_preparse_data = *produced_preparse_data =
...@@ -267,12 +268,12 @@ PreParser::PreParseResult PreParser::PreParseFunction( ...@@ -267,12 +268,12 @@ PreParser::PreParseResult PreParser::PreParseFunction(
PreParser::Expression PreParser::ParseFunctionLiteral( PreParser::Expression PreParser::ParseFunctionLiteral(
Identifier function_name, Scanner::Location function_name_location, Identifier function_name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind, FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_pos, FunctionLiteral::FunctionType function_type, int function_token_pos, FunctionSyntaxKind function_syntax_kind,
LanguageMode language_mode, LanguageMode language_mode,
ZonePtrList<const AstRawString>* arguments_for_wrapped_function) { ZonePtrList<const AstRawString>* arguments_for_wrapped_function) {
// Wrapped functions are not parsed in the preparser. // Wrapped functions are not parsed in the preparser.
DCHECK_NULL(arguments_for_wrapped_function); DCHECK_NULL(arguments_for_wrapped_function);
DCHECK_NE(FunctionLiteral::kWrapped, function_type); DCHECK_NE(FunctionSyntaxKind::kWrapped, function_syntax_kind);
// Function :: // Function ::
// '(' FormalParameterList? ')' '{' FunctionBody '}' // '(' FormalParameterList? ')' '{' FunctionBody '}'
const RuntimeCallCounterId counters[2] = { const RuntimeCallCounterId counters[2] = {
...@@ -323,8 +324,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -323,8 +324,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
int pos = function_token_pos == kNoSourcePosition ? peek_position() int pos = function_token_pos == kNoSourcePosition ? peek_position()
: function_token_pos; : function_token_pos;
AcceptINScope scope(this, true); AcceptINScope scope(this, true);
ParseFunctionBody(&body, function_name, pos, formals, kind, function_type, ParseFunctionBody(&body, function_name, pos, formals, kind,
FunctionBodyType::kBlock); function_syntax_kind, FunctionBodyType::kBlock);
// Parsing the body may change the language mode in our scope. // Parsing the body may change the language mode in our scope.
language_mode = function_scope->language_mode(); language_mode = function_scope->language_mode();
......
...@@ -665,7 +665,7 @@ class PreParserFactory { ...@@ -665,7 +665,7 @@ class PreParserFactory {
const PreParserScopedStatementList& body, int expected_property_count, const PreParserScopedStatementList& body, int expected_property_count,
int parameter_count, int function_length, int parameter_count, int function_length,
FunctionLiteral::ParameterFlag has_duplicate_parameters, FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
FunctionLiteral::EagerCompileHint eager_compile_hint, int position, FunctionLiteral::EagerCompileHint eager_compile_hint, int position,
bool has_braces, int function_literal_id, bool has_braces, int function_literal_id,
ProducedPreparseData* produced_preparse_data = nullptr) { ProducedPreparseData* produced_preparse_data = nullptr) {
...@@ -970,9 +970,9 @@ class PreParser : public ParserBase<PreParser> { ...@@ -970,9 +970,9 @@ class PreParser : public ParserBase<PreParser> {
// the final '}'. // the final '}'.
PreParseResult PreParseFunction( PreParseResult PreParseFunction(
const AstRawString* function_name, FunctionKind kind, const AstRawString* function_name, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind, DeclarationScope* function_scope,
DeclarationScope* function_scope, int* use_counts, int* use_counts, ProducedPreparseData** produced_preparser_scope_data,
ProducedPreparseData** produced_preparser_scope_data, int script_id); int script_id);
PreparseDataBuilder* preparse_data_builder() const { PreparseDataBuilder* preparse_data_builder() const {
return preparse_data_builder_; return preparse_data_builder_;
...@@ -1012,7 +1012,7 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1012,7 +1012,7 @@ class PreParser : public ParserBase<PreParser> {
} }
V8_INLINE bool SkipFunction(const AstRawString* name, FunctionKind kind, V8_INLINE bool SkipFunction(const AstRawString* name, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope, DeclarationScope* function_scope,
int* num_parameters, int* function_length, int* num_parameters, int* function_length,
ProducedPreparseData** produced_preparse_data) { ProducedPreparseData** produced_preparse_data) {
...@@ -1022,7 +1022,7 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1022,7 +1022,7 @@ class PreParser : public ParserBase<PreParser> {
Expression ParseFunctionLiteral( Expression ParseFunctionLiteral(
Identifier name, Scanner::Location function_name_location, Identifier name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind, FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_pos, FunctionLiteral::FunctionType function_type, int function_token_pos, FunctionSyntaxKind function_syntax_kind,
LanguageMode language_mode, LanguageMode language_mode,
ZonePtrList<const AstRawString>* arguments_for_wrapped_function); ZonePtrList<const AstRawString>* arguments_for_wrapped_function);
...@@ -1164,11 +1164,10 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1164,11 +1164,10 @@ class PreParser : public ParserBase<PreParser> {
int pos, FunctionKind kind, PreParserScopedStatementList* body) { int pos, FunctionKind kind, PreParserScopedStatementList* body) {
ParseStatementList(body, Token::RBRACE); ParseStatementList(body, Token::RBRACE);
} }
V8_INLINE void DeclareFunctionNameVar( V8_INLINE void DeclareFunctionNameVar(const AstRawString* function_name,
const AstRawString* function_name, FunctionSyntaxKind function_syntax_kind,
FunctionLiteral::FunctionType function_type, DeclarationScope* function_scope) {
DeclarationScope* function_scope) { if (function_syntax_kind == FunctionSyntaxKind::kNamedExpression &&
if (function_type == FunctionLiteral::kNamedExpression &&
function_scope->LookupLocal(function_name) == nullptr) { function_scope->LookupLocal(function_name) == nullptr) {
DCHECK_EQ(function_scope, scope()); DCHECK_EQ(function_scope, scope());
function_scope->DeclareFunctionVar(function_name); function_scope->DeclareFunctionVar(function_name);
...@@ -1177,9 +1176,9 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1177,9 +1176,9 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE void DeclareFunctionNameVar( V8_INLINE void DeclareFunctionNameVar(
const PreParserIdentifier& function_name, const PreParserIdentifier& function_name,
FunctionLiteral::FunctionType function_type, FunctionSyntaxKind function_syntax_kind,
DeclarationScope* function_scope) { DeclarationScope* function_scope) {
DeclareFunctionNameVar(function_name.string_, function_type, DeclareFunctionNameVar(function_name.string_, function_syntax_kind,
function_scope); function_scope);
} }
......
...@@ -92,7 +92,7 @@ class CompilerDispatcherTest : public TestWithNativeContext { ...@@ -92,7 +92,7 @@ class CompilerDispatcherTest : public TestWithNativeContext {
ast_node_factory.NewFunctionLiteral( ast_node_factory.NewFunctionLiteral(
function_name, function_scope, statements, -1, -1, -1, function_name, function_scope, statements, -1, -1, -1,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, FunctionSyntaxKind::kAnonymousExpression,
FunctionLiteral::kShouldEagerCompile, shared->StartPosition(), true, FunctionLiteral::kShouldEagerCompile, shared->StartPosition(), true,
shared->function_literal_id(), nullptr); shared->function_literal_id(), nullptr);
......
...@@ -71,7 +71,7 @@ class BackgroundCompileTaskTest : public TestWithNativeContext { ...@@ -71,7 +71,7 @@ class BackgroundCompileTaskTest : public TestWithNativeContext {
ast_node_factory.NewFunctionLiteral( ast_node_factory.NewFunctionLiteral(
function_name, function_scope, statements, -1, -1, -1, function_name, function_scope, statements, -1, -1, -1,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, FunctionSyntaxKind::kAnonymousExpression,
FunctionLiteral::kShouldEagerCompile, shared->StartPosition(), true, FunctionLiteral::kShouldEagerCompile, shared->StartPosition(), true,
shared->function_literal_id(), nullptr); shared->function_literal_id(), nullptr);
......
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