diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-29 10:46:47 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-02 12:02:10 +0000 |
commit | 99677208ff3b216fdfec551fbe548da5520cd6fb (patch) | |
tree | 476a4865c10320249360e859d8fdd3e01833b03a /chromium/v8/src/ast | |
parent | c30a6232df03e1efbd9f3b226777b07e087a1122 (diff) | |
download | qtwebengine-chromium-99677208ff3b216fdfec551fbe548da5520cd6fb.tar.gz |
BASELINE: Update Chromium to 86.0.4240.124
Change-Id: Ide0ff151e94cd665ae6521a446995d34a9d1d644
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/ast')
-rw-r--r-- | chromium/v8/src/ast/ast-function-literal-id-reindexer.cc | 9 | ||||
-rw-r--r-- | chromium/v8/src/ast/ast-value-factory.cc | 84 | ||||
-rw-r--r-- | chromium/v8/src/ast/ast-value-factory.h | 17 | ||||
-rw-r--r-- | chromium/v8/src/ast/ast.cc | 33 | ||||
-rw-r--r-- | chromium/v8/src/ast/ast.h | 291 | ||||
-rw-r--r-- | chromium/v8/src/ast/modules.cc | 17 | ||||
-rw-r--r-- | chromium/v8/src/ast/scopes.cc | 127 | ||||
-rw-r--r-- | chromium/v8/src/ast/scopes.h | 30 | ||||
-rw-r--r-- | chromium/v8/src/ast/source-range-ast-visitor.cc | 14 |
9 files changed, 338 insertions, 284 deletions
diff --git a/chromium/v8/src/ast/ast-function-literal-id-reindexer.cc b/chromium/v8/src/ast/ast-function-literal-id-reindexer.cc index b583b5e4214..8c9318bfe74 100644 --- a/chromium/v8/src/ast/ast-function-literal-id-reindexer.cc +++ b/chromium/v8/src/ast/ast-function-literal-id-reindexer.cc @@ -54,10 +54,10 @@ void AstFunctionLiteralIdReindexer::VisitClassLiteral(ClassLiteral* expr) { // Private fields have their key and value present in // instance_members_initializer_function, so they will // already have been visited. - if (prop->value()->IsFunctionLiteral()) { - Visit(prop->value()); - } else { + if (prop->kind() == ClassLiteralProperty::Kind::FIELD) { CheckVisited(prop->value()); + } else { + Visit(prop->value()); } } ZonePtrList<ClassLiteral::Property>* props = expr->public_members(); @@ -67,7 +67,8 @@ void AstFunctionLiteralIdReindexer::VisitClassLiteral(ClassLiteral* expr) { // Public fields with computed names have their key // and value present in instance_members_initializer_function, so they will // already have been visited. - if (prop->is_computed_name() && !prop->value()->IsFunctionLiteral()) { + if (prop->is_computed_name() && + prop->kind() == ClassLiteralProperty::Kind::FIELD) { if (!prop->key()->IsLiteral()) { CheckVisited(prop->key()); } diff --git a/chromium/v8/src/ast/ast-value-factory.cc b/chromium/v8/src/ast/ast-value-factory.cc index 23f28b834ac..598096ba10d 100644 --- a/chromium/v8/src/ast/ast-value-factory.cc +++ b/chromium/v8/src/ast/ast-value-factory.cc @@ -29,9 +29,8 @@ #include "src/base/logging.h" #include "src/common/globals.h" -#include "src/execution/off-thread-isolate.h" #include "src/heap/factory-inl.h" -#include "src/heap/off-thread-factory-inl.h" +#include "src/heap/local-factory-inl.h" #include "src/objects/objects-inl.h" #include "src/objects/objects.h" #include "src/strings/char-predicates-inl.h" @@ -46,8 +45,8 @@ namespace { // For using StringToIndex. class OneByteStringStream { public: - explicit OneByteStringStream(Vector<const byte> lb) : - literal_bytes_(lb), pos_(0) {} + explicit OneByteStringStream(Vector<const byte> lb) + : literal_bytes_(lb), pos_(0) {} bool HasMore() { return pos_ < literal_bytes_.length(); } uint16_t GetNext() { return literal_bytes_[pos_++]; } @@ -59,7 +58,8 @@ class OneByteStringStream { } // namespace -void AstRawString::Internalize(Isolate* isolate) { +template <typename LocalIsolate> +void AstRawString::Internalize(LocalIsolate* isolate) { DCHECK(!has_string_); if (literal_bytes_.length() == 0) { set_string(isolate->factory()->empty_string()); @@ -73,27 +73,10 @@ void AstRawString::Internalize(Isolate* isolate) { } } -void AstRawString::Internalize(OffThreadIsolate* isolate) { - DCHECK(!has_string_); - if (literal_bytes_.length() == 0) { - set_string(isolate->factory()->empty_string()); - return; - } - - // For the off-thread case, we already de-duplicated the AstRawStrings during - // construction and don't have access to the main thread string table yet, so - // we just unconditionally create strings and will internalize them properly - // during merging. - Handle<SeqString> string; - if (is_one_byte()) { - string = isolate->factory()->NewOneByteInternalizedString( - Vector<const uint8_t>::cast(literal_bytes_), hash_field()); - } else { - string = isolate->factory()->NewTwoByteInternalizedString( - Vector<const uc16>::cast(literal_bytes_), hash_field()); - } - set_string(string); -} +template EXPORT_TEMPLATE_DEFINE( + V8_EXPORT_PRIVATE) void AstRawString::Internalize(Isolate* isolate); +template EXPORT_TEMPLATE_DEFINE( + V8_EXPORT_PRIVATE) void AstRawString::Internalize(LocalIsolate* isolate); bool AstRawString::AsArrayIndex(uint32_t* index) const { // The StringHasher will set up the hash. Bail out early if we know it @@ -185,8 +168,8 @@ Handle<String> AstConsString::Allocate(LocalIsolate* isolate) const { template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) Handle<String> AstConsString::Allocate<Isolate>(Isolate* isolate) const; template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) - Handle<String> AstConsString::Allocate<OffThreadIsolate>( - OffThreadIsolate* isolate) const; + Handle<String> AstConsString::Allocate<LocalIsolate>( + LocalIsolate* isolate) const; template <typename LocalIsolate> Handle<String> AstConsString::AllocateFlat(LocalIsolate* isolate) const { @@ -246,8 +229,8 @@ Handle<String> AstConsString::AllocateFlat(LocalIsolate* isolate) const { template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) Handle<String> AstConsString::AllocateFlat<Isolate>(Isolate* isolate) const; template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) - Handle<String> AstConsString::AllocateFlat<OffThreadIsolate>( - OffThreadIsolate* isolate) const; + Handle<String> AstConsString::AllocateFlat<LocalIsolate>( + LocalIsolate* isolate) const; std::forward_list<const AstRawString*> AstConsString::ToRawStrings() const { std::forward_list<const AstRawString*> result; @@ -268,21 +251,21 @@ AstStringConstants::AstStringConstants(Isolate* isolate, uint64_t hash_seed) string_table_(AstRawString::Compare), hash_seed_(hash_seed) { DCHECK_EQ(ThreadId::Current(), isolate->thread_id()); -#define F(name, str) \ - { \ - const char* data = str; \ - Vector<const uint8_t> literal(reinterpret_cast<const uint8_t*>(data), \ - static_cast<int>(strlen(data))); \ - uint32_t hash_field = StringHasher::HashSequentialString<uint8_t>( \ - literal.begin(), literal.length(), hash_seed_); \ - name##_string_ = new (&zone_) AstRawString(true, literal, hash_field); \ - /* The Handle returned by the factory is located on the roots */ \ - /* array, not on the temporary HandleScope, so this is safe. */ \ - name##_string_->set_string(isolate->factory()->name##_string()); \ - base::HashMap::Entry* entry = \ - string_table_.InsertNew(name##_string_, name##_string_->Hash()); \ - DCHECK_NULL(entry->value); \ - entry->value = reinterpret_cast<void*>(1); \ +#define F(name, str) \ + { \ + const char* data = str; \ + Vector<const uint8_t> literal(reinterpret_cast<const uint8_t*>(data), \ + static_cast<int>(strlen(data))); \ + uint32_t hash_field = StringHasher::HashSequentialString<uint8_t>( \ + literal.begin(), literal.length(), hash_seed_); \ + name##_string_ = zone_.New<AstRawString>(true, literal, hash_field); \ + /* The Handle returned by the factory is located on the roots */ \ + /* array, not on the temporary HandleScope, so this is safe. */ \ + name##_string_->set_string(isolate->factory()->name##_string()); \ + base::HashMap::Entry* entry = \ + string_table_.InsertNew(name##_string_, name##_string_->Hash()); \ + DCHECK_NULL(entry->value); \ + entry->value = reinterpret_cast<void*>(1); \ } AST_STRING_CONSTANTS(F) #undef F @@ -333,7 +316,7 @@ const AstRawString* AstValueFactory::CloneFromOtherFactory( } AstConsString* AstValueFactory::NewConsString() { - return new (zone()) AstConsString; + return zone()->New<AstConsString>(); } AstConsString* AstValueFactory::NewConsString(const AstRawString* str) { @@ -361,10 +344,9 @@ void AstValueFactory::Internalize(LocalIsolate* isolate) { zone_ = nullptr; } template EXPORT_TEMPLATE_DEFINE( - V8_EXPORT_PRIVATE) void AstValueFactory::Internalize<Isolate>(Isolate* - isolate); -template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void AstValueFactory:: - Internalize<OffThreadIsolate>(OffThreadIsolate* isolate); + V8_EXPORT_PRIVATE) void AstValueFactory::Internalize(Isolate* isolate); +template EXPORT_TEMPLATE_DEFINE( + V8_EXPORT_PRIVATE) void AstValueFactory::Internalize(LocalIsolate* isolate); AstRawString* AstValueFactory::GetString(uint32_t hash_field, bool is_one_byte, Vector<const byte> literal_bytes) { @@ -379,7 +361,7 @@ AstRawString* AstValueFactory::GetString(uint32_t hash_field, bool is_one_byte, int length = literal_bytes.length(); byte* new_literal_bytes = zone()->NewArray<byte>(length); memcpy(new_literal_bytes, literal_bytes.begin(), length); - AstRawString* new_string = new (zone()) AstRawString( + AstRawString* new_string = zone()->New<AstRawString>( is_one_byte, Vector<const byte>(new_literal_bytes, length), hash_field); CHECK_NOT_NULL(new_string); AddString(new_string); diff --git a/chromium/v8/src/ast/ast-value-factory.h b/chromium/v8/src/ast/ast-value-factory.h index 134612f1fd0..17524981235 100644 --- a/chromium/v8/src/ast/ast-value-factory.h +++ b/chromium/v8/src/ast/ast-value-factory.h @@ -45,7 +45,6 @@ namespace v8 { namespace internal { class Isolate; -class OffThreadIsolate; class AstRawString final : public ZoneObject { public: @@ -59,8 +58,8 @@ class AstRawString final : public ZoneObject { V8_EXPORT_PRIVATE bool IsOneByteEqualTo(const char* data) const; uint16_t FirstCharacter() const; - void Internalize(Isolate* isolate); - void Internalize(OffThreadIsolate* isolate); + template <typename LocalIsolate> + void Internalize(LocalIsolate* isolate); // Access the physical representation: bool is_one_byte() const { return is_one_byte_; } @@ -83,6 +82,7 @@ class AstRawString final : public ZoneObject { friend class AstRawStringInternalizationKey; friend class AstStringConstants; friend class AstValueFactory; + friend Zone; // Members accessed only by the AstValueFactory & related classes: static bool Compare(void* a, void* b); @@ -126,6 +126,11 @@ class AstRawString final : public ZoneObject { #endif }; +extern template EXPORT_TEMPLATE_DECLARE( + V8_EXPORT_PRIVATE) void AstRawString::Internalize(Isolate* isolate); +extern template EXPORT_TEMPLATE_DECLARE( + V8_EXPORT_PRIVATE) void AstRawString::Internalize(LocalIsolate* isolate); + class AstConsString final : public ZoneObject { public: AstConsString* AddString(Zone* zone, const AstRawString* s) { @@ -133,8 +138,7 @@ class AstConsString final : public ZoneObject { if (!IsEmpty()) { // We're putting the new string to the head of the list, meaning // the string segments will be in reverse order. - Segment* tmp = new (zone->New(sizeof(Segment))) Segment; - *tmp = segment_; + Segment* tmp = zone->New<Segment>(segment_); segment_.next = tmp; } segment_.string = s; @@ -163,6 +167,7 @@ class AstConsString final : public ZoneObject { private: friend class AstValueFactory; + friend Zone; AstConsString() : string_(), segment_({nullptr, nullptr}) {} @@ -380,7 +385,7 @@ extern template EXPORT_TEMPLATE_DECLARE( extern template EXPORT_TEMPLATE_DECLARE( V8_EXPORT_PRIVATE) void AstValueFactory:: - Internalize<OffThreadIsolate>(OffThreadIsolate* isolate); + Internalize<LocalIsolate>(LocalIsolate* isolate); } // namespace internal } // namespace v8 diff --git a/chromium/v8/src/ast/ast.cc b/chromium/v8/src/ast/ast.cc index 8cd1140154a..b40cf83c820 100644 --- a/chromium/v8/src/ast/ast.cc +++ b/chromium/v8/src/ast/ast.cc @@ -14,8 +14,7 @@ #include "src/builtins/builtins-constructor.h" #include "src/builtins/builtins.h" #include "src/common/assert-scope.h" -#include "src/execution/off-thread-isolate.h" -#include "src/heap/off-thread-factory-inl.h" +#include "src/heap/local-factory-inl.h" #include "src/numbers/conversions-inl.h" #include "src/numbers/double.h" #include "src/objects/contexts.h" @@ -335,10 +334,9 @@ void ObjectLiteral::CalculateEmitStore(Zone* zone) { const auto GETTER = ObjectLiteral::Property::GETTER; const auto SETTER = ObjectLiteral::Property::SETTER; - ZoneAllocationPolicy allocator(zone); - - CustomMatcherZoneHashMap table( - Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, allocator); + CustomMatcherZoneHashMap table(Literal::Match, + ZoneHashMap::kDefaultHashMapCapacity, + ZoneAllocationPolicy(zone)); for (int i = properties()->length() - 1; i >= 0; i--) { ObjectLiteral::Property* property = properties()->at(i); if (property->is_computed_name()) continue; @@ -347,7 +345,7 @@ void ObjectLiteral::CalculateEmitStore(Zone* zone) { DCHECK(!literal->IsNullLiteral()); uint32_t hash = literal->Hash(); - ZoneHashMap::Entry* entry = table.LookupOrInsert(literal, hash, allocator); + ZoneHashMap::Entry* entry = table.LookupOrInsert(literal, hash); if (entry->value == nullptr) { entry->value = property; } else { @@ -522,7 +520,7 @@ void ObjectLiteral::BuildBoilerplateDescription(LocalIsolate* isolate) { template EXPORT_TEMPLATE_DEFINE(V8_BASE_EXPORT) void ObjectLiteral:: BuildBoilerplateDescription(Isolate* isolate); template EXPORT_TEMPLATE_DEFINE(V8_BASE_EXPORT) void ObjectLiteral:: - BuildBoilerplateDescription(OffThreadIsolate* isolate); + BuildBoilerplateDescription(LocalIsolate* isolate); bool ObjectLiteral::IsFastCloningSupported() const { // The CreateShallowObjectLiteratal builtin doesn't copy elements, and object @@ -696,8 +694,9 @@ void ArrayLiteral::BuildBoilerplateDescription(LocalIsolate* isolate) { template EXPORT_TEMPLATE_DEFINE( V8_BASE_EXPORT) void ArrayLiteral::BuildBoilerplateDescription(Isolate* isolate); -template EXPORT_TEMPLATE_DEFINE(V8_BASE_EXPORT) void ArrayLiteral:: - BuildBoilerplateDescription(OffThreadIsolate* isolate); +template EXPORT_TEMPLATE_DEFINE( + V8_BASE_EXPORT) void ArrayLiteral::BuildBoilerplateDescription(LocalIsolate* + isolate); bool ArrayLiteral::IsFastCloningSupported() const { return depth() <= 1 && @@ -737,7 +736,7 @@ template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) Expression* expression, Isolate* isolate); template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) Handle<Object> MaterializedLiteral::GetBoilerplateValue( - Expression* expression, OffThreadIsolate* isolate); + Expression* expression, LocalIsolate* isolate); int MaterializedLiteral::InitDepthAndFlags() { if (IsArrayLiteral()) return AsArrayLiteral()->InitDepthAndFlags(); @@ -772,7 +771,7 @@ void MaterializedLiteral::BuildConstants(LocalIsolate* isolate) { template EXPORT_TEMPLATE_DEFINE( V8_BASE_EXPORT) void MaterializedLiteral::BuildConstants(Isolate* isolate); template EXPORT_TEMPLATE_DEFINE( - V8_BASE_EXPORT) void MaterializedLiteral::BuildConstants(OffThreadIsolate* + V8_BASE_EXPORT) void MaterializedLiteral::BuildConstants(LocalIsolate* isolate); template <typename LocalIsolate> @@ -814,7 +813,7 @@ template EXPORT_TEMPLATE_DEFINE(V8_BASE_EXPORT) Isolate* isolate); template EXPORT_TEMPLATE_DEFINE(V8_BASE_EXPORT) Handle<TemplateObjectDescription> GetTemplateObject::GetOrBuildDescription( - OffThreadIsolate* isolate); + LocalIsolate* isolate); static bool IsCommutativeOperationWithSmiLiteral(Token::Value op) { // Add is not commutative due to potential for string addition. @@ -950,9 +949,7 @@ Call::CallType Call::GetCallType() const { CaseClause::CaseClause(Zone* zone, Expression* label, const ScopedPtrList<Statement>& statements) - : label_(label), statements_(0, nullptr) { - statements.CopyTo(&statements_, zone); -} + : label_(label), statements_(statements.ToConstVector(), zone) {} bool Literal::IsPropertyName() const { if (type() != kString) return false; @@ -1009,7 +1006,7 @@ Handle<Object> Literal::BuildValue(LocalIsolate* isolate) const { template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) Handle<Object> Literal::BuildValue(Isolate* isolate) const; template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) - Handle<Object> Literal::BuildValue(OffThreadIsolate* isolate) const; + Handle<Object> Literal::BuildValue(LocalIsolate* isolate) const; bool Literal::ToBooleanIsTrue() const { switch (type()) { @@ -1063,7 +1060,7 @@ Literal* AstNodeFactory::NewNumberLiteral(double number, int pos) { if (DoubleToSmiInteger(number, &int_value)) { return NewSmiLiteral(int_value, pos); } - return new (zone_) Literal(number, pos); + return zone_->New<Literal>(number, pos); } const char* CallRuntime::debug_name() { diff --git a/chromium/v8/src/ast/ast.h b/chromium/v8/src/ast/ast.h index dab3981c638..4213c60f246 100644 --- a/chromium/v8/src/ast/ast.h +++ b/chromium/v8/src/ast/ast.h @@ -21,6 +21,7 @@ #include "src/objects/smi.h" #include "src/parsing/token.h" #include "src/runtime/runtime.h" +#include "src/zone/zone-list.h" namespace v8 { namespace internal { @@ -116,7 +117,6 @@ namespace internal { // Forward declarations class Isolate; -class OffThreadIsolate; class AstNode; class AstNodeFactory; @@ -143,8 +143,6 @@ class AstNode: public ZoneObject { }; #undef DECLARE_TYPE_ENUM - void* operator new(size_t size, Zone* zone) { return zone->New(size); } - NodeType node_type() const { return NodeTypeField::decode(bit_field_); } int position() const { return position_; } @@ -165,10 +163,6 @@ class AstNode: public ZoneObject { MaterializedLiteral* AsMaterializedLiteral(); private: - // Hidden to prevent accidental usage. It would have to load the - // current zone from the TLS. - void* operator new(size_t size); - int position_; using NodeTypeField = base::BitField<NodeType, 0, 6>; @@ -289,6 +283,7 @@ class Expression : public AstNode { class FailureExpression : public Expression { private: friend class AstNodeFactory; + friend Zone; FailureExpression() : Expression(kNoSourcePosition, kFailureExpression) {} }; @@ -324,11 +319,12 @@ class Block final : public BreakableStatement { void InitializeStatements(const ScopedPtrList<Statement>& statements, Zone* zone) { DCHECK_EQ(0, statements_.length()); - statements.CopyTo(&statements_, zone); + statements_ = ZonePtrList<Statement>(statements.ToConstVector(), zone); } private: friend class AstNodeFactory; + friend Zone; ZonePtrList<Statement> statements_; Scope* scope_; @@ -375,6 +371,7 @@ class VariableDeclaration : public Declaration { private: friend class AstNodeFactory; + friend Zone; using IsNestedField = Declaration::NextBitField<bool, 1>; @@ -397,6 +394,7 @@ class NestedVariableDeclaration final : public VariableDeclaration { private: friend class AstNodeFactory; + friend Zone; NestedVariableDeclaration(Scope* scope, int pos) : VariableDeclaration(pos, true), scope_(scope) {} @@ -417,6 +415,7 @@ class FunctionDeclaration final : public Declaration { private: friend class AstNodeFactory; + friend Zone; FunctionDeclaration(FunctionLiteral* fun, int pos) : Declaration(pos, kFunctionDeclaration), fun_(fun) {} @@ -451,6 +450,7 @@ class DoWhileStatement final : public IterationStatement { private: friend class AstNodeFactory; + friend Zone; explicit DoWhileStatement(int pos) : IterationStatement(pos, kDoWhileStatement), cond_(nullptr) {} @@ -470,6 +470,7 @@ class WhileStatement final : public IterationStatement { private: friend class AstNodeFactory; + friend Zone; explicit WhileStatement(int pos) : IterationStatement(pos, kWhileStatement), cond_(nullptr) {} @@ -494,6 +495,7 @@ class ForStatement final : public IterationStatement { private: friend class AstNodeFactory; + friend Zone; explicit ForStatement(int pos) : IterationStatement(pos, kForStatement), @@ -531,6 +533,7 @@ class ForEachStatement : public IterationStatement { protected: friend class AstNodeFactory; + friend Zone; ForEachStatement(int pos, NodeType type) : IterationStatement(pos, type), each_(nullptr), subject_(nullptr) {} @@ -542,6 +545,7 @@ class ForEachStatement : public IterationStatement { class ForInStatement final : public ForEachStatement { private: friend class AstNodeFactory; + friend Zone; explicit ForInStatement(int pos) : ForEachStatement(pos, kForInStatement) {} }; @@ -553,6 +557,7 @@ class ForOfStatement final : public ForEachStatement { private: friend class AstNodeFactory; + friend Zone; ForOfStatement(int pos, IteratorType type) : ForEachStatement(pos, kForOfStatement), type_(type) {} @@ -567,6 +572,7 @@ class ExpressionStatement final : public Statement { private: friend class AstNodeFactory; + friend Zone; ExpressionStatement(Expression* expression, int pos) : Statement(pos, kExpressionStatement), expression_(expression) {} @@ -587,6 +593,7 @@ class ContinueStatement final : public JumpStatement { private: friend class AstNodeFactory; + friend Zone; ContinueStatement(IterationStatement* target, int pos) : JumpStatement(pos, kContinueStatement), target_(target) {} @@ -601,6 +608,7 @@ class BreakStatement final : public JumpStatement { private: friend class AstNodeFactory; + friend Zone; BreakStatement(BreakableStatement* target, int pos) : JumpStatement(pos, kBreakStatement), target_(target) {} @@ -624,6 +632,7 @@ class ReturnStatement final : public JumpStatement { private: friend class AstNodeFactory; + friend Zone; ReturnStatement(Expression* expression, Type type, int pos, int end_position) : JumpStatement(pos, kReturnStatement), @@ -648,6 +657,7 @@ class WithStatement final : public Statement { private: friend class AstNodeFactory; + friend Zone; WithStatement(Scope* scope, Expression* expression, Statement* statement, int pos) @@ -672,6 +682,7 @@ class CaseClause final : public ZoneObject { private: friend class AstNodeFactory; + friend Zone; CaseClause(Zone* zone, Expression* label, const ScopedPtrList<Statement>& statements); @@ -690,6 +701,7 @@ class SwitchStatement final : public BreakableStatement { private: friend class AstNodeFactory; + friend Zone; SwitchStatement(Zone* zone, Expression* tag, int pos) : BreakableStatement(pos, kSwitchStatement), tag_(tag), cases_(4, zone) {} @@ -718,6 +730,7 @@ class IfStatement final : public Statement { private: friend class AstNodeFactory; + friend Zone; IfStatement(Expression* condition, Statement* then_statement, Statement* else_statement, int pos) @@ -815,6 +828,7 @@ class TryCatchStatement final : public TryStatement { private: friend class AstNodeFactory; + friend Zone; TryCatchStatement(Block* try_block, Scope* scope, Block* catch_block, HandlerTable::CatchPrediction catch_prediction, int pos) @@ -836,6 +850,7 @@ class TryFinallyStatement final : public TryStatement { private: friend class AstNodeFactory; + friend Zone; TryFinallyStatement(Block* try_block, Block* finally_block, int pos) : TryStatement(try_block, pos, kTryFinallyStatement), @@ -848,6 +863,7 @@ class TryFinallyStatement final : public TryStatement { class DebuggerStatement final : public Statement { private: friend class AstNodeFactory; + friend Zone; explicit DebuggerStatement(int pos) : Statement(pos, kDebuggerStatement) {} }; @@ -856,6 +872,7 @@ class DebuggerStatement final : public Statement { class EmptyStatement final : public Statement { private: friend class AstNodeFactory; + friend Zone; EmptyStatement() : Statement(kNoSourcePosition, kEmptyStatement) {} }; @@ -876,6 +893,7 @@ class SloppyBlockFunctionStatement final : public Statement { private: friend class AstNodeFactory; + friend Zone; using TokenField = Statement::NextBitField<Token::Value, 8>; @@ -978,6 +996,7 @@ class Literal final : public Expression { private: friend class AstNodeFactory; + friend Zone; using TypeField = Expression::NextBitField<Type, 4>; @@ -1067,6 +1086,7 @@ class RegExpLiteral final : public MaterializedLiteral { private: friend class AstNodeFactory; + friend Zone; RegExpLiteral(const AstRawString* pattern, int flags, int pos) : MaterializedLiteral(pos, kRegExpLiteral), @@ -1086,6 +1106,7 @@ class AggregateLiteral : public MaterializedLiteral { kIsShallow = 1, kDisableMementos = 1 << 1, kNeedsInitialAllocationSite = 1 << 2, + kIsShallowAndDisableMementos = kIsShallow | kDisableMementos, }; bool is_initialized() const { return 0 < depth_; } @@ -1125,6 +1146,7 @@ class AggregateLiteral : public MaterializedLiteral { protected: friend class AstNodeFactory; + friend Zone; AggregateLiteral(int pos, NodeType type) : MaterializedLiteral(pos, type), depth_(0) { bit_field_ |= @@ -1203,6 +1225,7 @@ class ObjectLiteralProperty final : public LiteralProperty { private: friend class AstNodeFactory; + friend Zone; ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, bool is_computed_name); @@ -1294,18 +1317,18 @@ class ObjectLiteral final : public AggregateLiteral { private: friend class AstNodeFactory; + friend Zone; ObjectLiteral(Zone* zone, const ScopedPtrList<Property>& properties, uint32_t boilerplate_properties, int pos, bool has_rest_property) : AggregateLiteral(pos, kObjectLiteral), boilerplate_properties_(boilerplate_properties), - properties_(0, nullptr) { + properties_(properties.ToConstVector(), zone) { bit_field_ |= HasElementsField::encode(false) | HasRestPropertyField::encode(has_rest_property) | FastElementsField::encode(false) | HasNullPrototypeField::encode(false); - properties.CopyTo(&properties_, zone); } void InitFlagsForPendingNullPrototype(int i); @@ -1368,14 +1391,13 @@ class ArrayLiteral final : public AggregateLiteral { private: friend class AstNodeFactory; + friend Zone; ArrayLiteral(Zone* zone, const ScopedPtrList<Expression>& values, int first_spread_index, int pos) : AggregateLiteral(pos, kArrayLiteral), first_spread_index_(first_spread_index), - values_(0, nullptr) { - values.CopyTo(&values_, zone); - } + values_(values.ToConstVector(), zone) {} int first_spread_index_; Handle<ArrayBoilerplateDescription> boilerplate_description_; @@ -1387,7 +1409,8 @@ enum class HoleCheckMode { kRequired, kElided }; class ThisExpression final : public Expression { private: friend class AstNodeFactory; - ThisExpression() : Expression(kNoSourcePosition, kThisExpression) {} + friend Zone; + explicit ThisExpression(int pos) : Expression(pos, kThisExpression) {} }; class VariableProxy final : public Expression { @@ -1478,6 +1501,7 @@ class VariableProxy final : public Expression { private: friend class AstNodeFactory; + friend Zone; VariableProxy(Variable* var, int start_position); @@ -1519,6 +1543,7 @@ class OptionalChain final : public Expression { private: friend class AstNodeFactory; + friend Zone; explicit OptionalChain(Expression* expression) : Expression(0, kOptionalChain), expression_(expression) {} @@ -1587,6 +1612,7 @@ class Property final : public Expression { private: friend class AstNodeFactory; + friend Zone; Property(Expression* obj, Expression* key, int pos, bool optional_chain) : Expression(pos, kProperty), obj_(obj), key_(key) { @@ -1647,18 +1673,18 @@ class Call final : public Expression { private: friend class AstNodeFactory; + friend Zone; Call(Zone* zone, Expression* expression, const ScopedPtrList<Expression>& arguments, int pos, PossiblyEval possibly_eval, bool optional_chain) : Expression(pos, kCall), expression_(expression), - arguments_(0, nullptr) { + arguments_(arguments.ToConstVector(), zone) { bit_field_ |= IsPossiblyEvalField::encode(possibly_eval == IS_POSSIBLY_EVAL) | IsTaggedTemplateField::encode(false) | IsOptionalChainLinkField::encode(optional_chain); - arguments.CopyTo(&arguments_, zone); } Call(Zone* zone, Expression* expression, @@ -1666,11 +1692,10 @@ class Call final : public Expression { TaggedTemplateTag tag) : Expression(pos, kCall), expression_(expression), - arguments_(0, nullptr) { + arguments_(arguments.ToConstVector(), zone) { bit_field_ |= IsPossiblyEvalField::encode(false) | IsTaggedTemplateField::encode(true) | IsOptionalChainLinkField::encode(false); - arguments.CopyTo(&arguments_, zone); } using IsPossiblyEvalField = Expression::NextBitField<bool, 1>; @@ -1693,14 +1718,13 @@ class CallNew final : public Expression { private: friend class AstNodeFactory; + friend Zone; CallNew(Zone* zone, Expression* expression, const ScopedPtrList<Expression>& arguments, int pos) : Expression(pos, kCallNew), expression_(expression), - arguments_(0, nullptr) { - arguments.CopyTo(&arguments_, zone); - } + arguments_(arguments.ToConstVector(), zone) {} Expression* expression_; ZonePtrList<Expression> arguments_; @@ -1728,22 +1752,19 @@ class CallRuntime final : public Expression { private: friend class AstNodeFactory; + friend Zone; CallRuntime(Zone* zone, const Runtime::Function* function, const ScopedPtrList<Expression>& arguments, int pos) : Expression(pos, kCallRuntime), function_(function), - arguments_(0, nullptr) { - arguments.CopyTo(&arguments_, zone); - } + arguments_(arguments.ToConstVector(), zone) {} CallRuntime(Zone* zone, int context_index, const ScopedPtrList<Expression>& arguments, int pos) : Expression(pos, kCallRuntime), context_index_(context_index), function_(nullptr), - arguments_(0, nullptr) { - arguments.CopyTo(&arguments_, zone); - } + arguments_(arguments.ToConstVector(), zone) {} int context_index_; const Runtime::Function* function_; @@ -1758,6 +1779,7 @@ class UnaryOperation final : public Expression { private: friend class AstNodeFactory; + friend Zone; UnaryOperation(Token::Value op, Expression* expression, int pos) : Expression(pos, kUnaryOperation), expression_(expression) { @@ -1783,6 +1805,7 @@ class BinaryOperation final : public Expression { private: friend class AstNodeFactory; + friend Zone; BinaryOperation(Token::Value op, Expression* left, Expression* right, int pos) : Expression(pos, kBinaryOperation), left_(left), right_(right) { @@ -1815,6 +1838,7 @@ class NaryOperation final : public Expression { private: friend class AstNodeFactory; + friend Zone; NaryOperation(Zone* zone, Token::Value op, Expression* first, size_t initial_subsequent_size) @@ -1866,6 +1890,7 @@ class CountOperation final : public Expression { private: friend class AstNodeFactory; + friend Zone; CountOperation(Token::Value op, bool is_prefix, Expression* expr, int pos) : Expression(pos, kCountOperation), expression_(expr) { @@ -1892,6 +1917,7 @@ class CompareOperation final : public Expression { private: friend class AstNodeFactory; + friend Zone; CompareOperation(Token::Value op, Expression* left, Expression* right, int pos) @@ -1915,6 +1941,7 @@ class Spread final : public Expression { private: friend class AstNodeFactory; + friend Zone; Spread(Expression* expression, int pos, int expr_pos) : Expression(pos, kSpread), @@ -1933,6 +1960,7 @@ class Conditional final : public Expression { private: friend class AstNodeFactory; + friend Zone; Conditional(Expression* condition, Expression* then_expression, Expression* else_expression, int position) @@ -1970,6 +1998,7 @@ class Assignment : public Expression { private: friend class AstNodeFactory; + friend Zone; using TokenField = Expression::NextBitField<Token::Value, 7>; using LookupHoistingModeField = TokenField::Next<bool, 1>; @@ -1984,6 +2013,7 @@ class CompoundAssignment final : public Assignment { private: friend class AstNodeFactory; + friend Zone; CompoundAssignment(Token::Value op, Expression* target, Expression* value, int pos, BinaryOperation* binary_operation) @@ -2018,6 +2048,7 @@ class Suspend : public Expression { private: friend class AstNodeFactory; + friend Zone; friend class Yield; friend class YieldStar; friend class Await; @@ -2036,6 +2067,7 @@ class Suspend : public Expression { class Yield final : public Suspend { private: friend class AstNodeFactory; + friend Zone; Yield(Expression* expression, int pos, OnAbruptResume on_abrupt_resume) : Suspend(kYield, expression, pos, on_abrupt_resume) {} }; @@ -2043,6 +2075,7 @@ class Yield final : public Suspend { class YieldStar final : public Suspend { private: friend class AstNodeFactory; + friend Zone; YieldStar(Expression* expression, int pos) : Suspend(kYieldStar, expression, pos, Suspend::OnAbruptResume::kNoControl) {} @@ -2051,6 +2084,7 @@ class YieldStar final : public Suspend { class Await final : public Suspend { private: friend class AstNodeFactory; + friend Zone; Await(Expression* expression, int pos) : Suspend(kAwait, expression, pos, Suspend::kOnExceptionThrow) {} @@ -2062,6 +2096,7 @@ class Throw final : public Expression { private: friend class AstNodeFactory; + friend Zone; Throw(Expression* exception, int pos) : Expression(pos, kThrow), exception_(exception) {} @@ -2150,7 +2185,7 @@ class FunctionLiteral final : public Expression { } UNREACHABLE(); } - Handle<String> GetInferredName(OffThreadIsolate* isolate) const { + Handle<String> GetInferredName(LocalIsolate* isolate) const { DCHECK(inferred_name_.is_null()); DCHECK_NOT_NULL(raw_inferred_name_); return raw_inferred_name_->GetString(isolate); @@ -2241,6 +2276,7 @@ class FunctionLiteral final : public Expression { private: friend class AstNodeFactory; + friend Zone; FunctionLiteral(Zone* zone, const AstConsString* name, AstValueFactory* ast_value_factory, DeclarationScope* scope, @@ -2260,7 +2296,7 @@ class FunctionLiteral final : public Expression { function_literal_id_(function_literal_id), raw_name_(name), scope_(scope), - body_(0, nullptr), + body_(body.ToConstVector(), zone), raw_inferred_name_(ast_value_factory->empty_cons_string()), produced_preparse_data_(produced_preparse_data) { bit_field_ |= FunctionSyntaxKindBits::encode(function_syntax_kind) | @@ -2272,7 +2308,6 @@ class FunctionLiteral final : public Expression { HasBracesField::encode(has_braces) | OneshotIIFEBit::encode(false); if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile(); - body.CopyTo(&body_, zone); } using FunctionSyntaxKindBits = @@ -2347,6 +2382,7 @@ class ClassLiteralProperty final : public LiteralProperty { private: friend class AstNodeFactory; + friend Zone; ClassLiteralProperty(Expression* key, Expression* value, Kind kind, bool is_static, bool is_computed_name, bool is_private); @@ -2365,6 +2401,7 @@ class InitializeClassMembersStatement final : public Statement { private: friend class AstNodeFactory; + friend Zone; InitializeClassMembersStatement(ZonePtrList<Property>* fields, int pos) : Statement(pos, kInitializeClassMembersStatement), fields_(fields) {} @@ -2410,6 +2447,7 @@ class ClassLiteral final : public Expression { private: friend class AstNodeFactory; + friend Zone; ClassLiteral(ClassScope* scope, Expression* extends, FunctionLiteral* constructor, @@ -2459,6 +2497,7 @@ class NativeFunctionLiteral final : public Expression { private: friend class AstNodeFactory; + friend Zone; NativeFunctionLiteral(const AstRawString* name, v8::Extension* extension, int pos) @@ -2477,6 +2516,7 @@ class SuperPropertyReference final : public Expression { private: friend class AstNodeFactory; + friend Zone; // We take in ThisExpression* only as a proof that it was accessed. SuperPropertyReference(Expression* home_object, int pos) @@ -2495,6 +2535,7 @@ class SuperCallReference final : public Expression { private: friend class AstNodeFactory; + friend Zone; // We take in ThisExpression* only as a proof that it was accessed. SuperCallReference(VariableProxy* new_target_var, @@ -2518,6 +2559,7 @@ class ImportCallExpression final : public Expression { private: friend class AstNodeFactory; + friend Zone; ImportCallExpression(Expression* argument, int pos) : Expression(pos, kImportCallExpression), argument_(argument) {} @@ -2530,6 +2572,7 @@ class ImportCallExpression final : public Expression { class EmptyParentheses final : public Expression { private: friend class AstNodeFactory; + friend Zone; explicit EmptyParentheses(int pos) : Expression(pos, kEmptyParentheses) { mark_parenthesized(); @@ -2553,6 +2596,7 @@ class GetTemplateObject final : public Expression { private: friend class AstNodeFactory; + friend Zone; GetTemplateObject(const ZonePtrList<const AstRawString>* cooked_strings, const ZonePtrList<const AstRawString>* raw_strings, int pos) @@ -2575,6 +2619,7 @@ class TemplateLiteral final : public Expression { private: friend class AstNodeFactory; + friend Zone; TemplateLiteral(const ZonePtrList<const AstRawString>* parts, const ZonePtrList<Expression>* substitutions, int pos) : Expression(pos, kTemplateLiteral), @@ -2690,32 +2735,32 @@ class AstNodeFactory final { AstNodeFactory(AstValueFactory* ast_value_factory, Zone* zone) : zone_(zone), ast_value_factory_(ast_value_factory), - empty_statement_(new (zone) class EmptyStatement()), - this_expression_(new (zone) class ThisExpression()), - failure_expression_(new (zone) class FailureExpression()) {} + empty_statement_(zone->New<class EmptyStatement>()), + this_expression_(zone->New<class ThisExpression>(kNoSourcePosition)), + failure_expression_(zone->New<class FailureExpression>()) {} AstNodeFactory* ast_node_factory() { return this; } AstValueFactory* ast_value_factory() const { return ast_value_factory_; } VariableDeclaration* NewVariableDeclaration(int pos) { - return new (zone_) VariableDeclaration(pos); + return zone_->New<VariableDeclaration>(pos); } NestedVariableDeclaration* NewNestedVariableDeclaration(Scope* scope, int pos) { - return new (zone_) NestedVariableDeclaration(scope, pos); + return zone_->New<NestedVariableDeclaration>(scope, pos); } FunctionDeclaration* NewFunctionDeclaration(FunctionLiteral* fun, int pos) { - return new (zone_) FunctionDeclaration(fun, pos); + return zone_->New<FunctionDeclaration>(fun, pos); } Block* NewBlock(int capacity, bool ignore_completion_value) { - return new (zone_) Block(zone_, capacity, ignore_completion_value, false); + return zone_->New<Block>(zone_, capacity, ignore_completion_value, false); } Block* NewBlock(bool ignore_completion_value, bool is_breakable) { - return new (zone_) Block(ignore_completion_value, is_breakable); + return zone_->New<Block>(ignore_completion_value, is_breakable); } Block* NewBlock(bool ignore_completion_value, @@ -2726,60 +2771,60 @@ class AstNodeFactory final { } #define STATEMENT_WITH_POSITION(NodeType) \ - NodeType* New##NodeType(int pos) { return new (zone_) NodeType(pos); } + NodeType* New##NodeType(int pos) { return zone_->New<NodeType>(pos); } STATEMENT_WITH_POSITION(DoWhileStatement) STATEMENT_WITH_POSITION(WhileStatement) STATEMENT_WITH_POSITION(ForStatement) #undef STATEMENT_WITH_POSITION SwitchStatement* NewSwitchStatement(Expression* tag, int pos) { - return new (zone_) SwitchStatement(zone_, tag, pos); + return zone_->New<SwitchStatement>(zone_, tag, pos); } ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, int pos) { switch (visit_mode) { case ForEachStatement::ENUMERATE: { - return new (zone_) ForInStatement(pos); + return zone_->New<ForInStatement>(pos); } case ForEachStatement::ITERATE: { - return new (zone_) ForOfStatement(pos, IteratorType::kNormal); + return zone_->New<ForOfStatement>(pos, IteratorType::kNormal); } } UNREACHABLE(); } ForOfStatement* NewForOfStatement(int pos, IteratorType type) { - return new (zone_) ForOfStatement(pos, type); + return zone_->New<ForOfStatement>(pos, type); } ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { - return new (zone_) ExpressionStatement(expression, pos); + return zone_->New<ExpressionStatement>(expression, pos); } ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) { - return new (zone_) ContinueStatement(target, pos); + return zone_->New<ContinueStatement>(target, pos); } BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) { - return new (zone_) BreakStatement(target, pos); + return zone_->New<BreakStatement>(target, pos); } ReturnStatement* NewReturnStatement(Expression* expression, int pos, int end_position = kNoSourcePosition) { - return new (zone_) ReturnStatement(expression, ReturnStatement::kNormal, + return zone_->New<ReturnStatement>(expression, ReturnStatement::kNormal, pos, end_position); } ReturnStatement* NewAsyncReturnStatement( Expression* expression, int pos, int end_position = kNoSourcePosition) { - return new (zone_) ReturnStatement( + return zone_->New<ReturnStatement>( expression, ReturnStatement::kAsyncReturn, pos, end_position); } ReturnStatement* NewSyntheticAsyncReturnStatement( Expression* expression, int pos, int end_position = kNoSourcePosition) { - return new (zone_) ReturnStatement( + return zone_->New<ReturnStatement>( expression, ReturnStatement::kSyntheticAsyncReturn, pos, end_position); } @@ -2787,18 +2832,18 @@ class AstNodeFactory final { Expression* expression, Statement* statement, int pos) { - return new (zone_) WithStatement(scope, expression, statement, pos); + return zone_->New<WithStatement>(scope, expression, statement, pos); } IfStatement* NewIfStatement(Expression* condition, Statement* then_statement, Statement* else_statement, int pos) { - return new (zone_) - IfStatement(condition, then_statement, else_statement, pos); + return zone_->New<IfStatement>(condition, then_statement, else_statement, + pos); } TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope, Block* catch_block, int pos) { - return new (zone_) TryCatchStatement(try_block, scope, catch_block, + return zone_->New<TryCatchStatement>(try_block, scope, catch_block, HandlerTable::CAUGHT, pos); } @@ -2806,7 +2851,7 @@ class AstNodeFactory final { Scope* scope, Block* catch_block, int pos) { - return new (zone_) TryCatchStatement(try_block, scope, catch_block, + return zone_->New<TryCatchStatement>(try_block, scope, catch_block, HandlerTable::UNCAUGHT, pos); } @@ -2814,7 +2859,7 @@ class AstNodeFactory final { Scope* scope, Block* catch_block, int pos) { - return new (zone_) TryCatchStatement(try_block, scope, catch_block, + return zone_->New<TryCatchStatement>(try_block, scope, catch_block, HandlerTable::DESUGARING, pos); } @@ -2822,7 +2867,7 @@ class AstNodeFactory final { Scope* scope, Block* catch_block, int pos) { - return new (zone_) TryCatchStatement(try_block, scope, catch_block, + return zone_->New<TryCatchStatement>(try_block, scope, catch_block, HandlerTable::ASYNC_AWAIT, pos); } @@ -2830,17 +2875,17 @@ class AstNodeFactory final { Scope* scope, Block* catch_block, int pos) { - return new (zone_) TryCatchStatement( + return zone_->New<TryCatchStatement>( try_block, scope, catch_block, HandlerTable::UNCAUGHT_ASYNC_AWAIT, pos); } TryFinallyStatement* NewTryFinallyStatement(Block* try_block, Block* finally_block, int pos) { - return new (zone_) TryFinallyStatement(try_block, finally_block, pos); + return zone_->New<TryFinallyStatement>(try_block, finally_block, pos); } DebuggerStatement* NewDebuggerStatement(int pos) { - return new (zone_) DebuggerStatement(pos); + return zone_->New<DebuggerStatement>(pos); } class EmptyStatement* EmptyStatement() { @@ -2858,203 +2903,209 @@ class AstNodeFactory final { return this_expression_; } + class ThisExpression* NewThisExpression(int pos) { + DCHECK_NE(pos, kNoSourcePosition); + return zone_->New<class ThisExpression>(pos); + } + class FailureExpression* FailureExpression() { return failure_expression_; } SloppyBlockFunctionStatement* NewSloppyBlockFunctionStatement( int pos, Variable* var, Token::Value init) { - return new (zone_) - SloppyBlockFunctionStatement(pos, var, init, EmptyStatement()); + return zone_->New<SloppyBlockFunctionStatement>(pos, var, init, + EmptyStatement()); } CaseClause* NewCaseClause(Expression* label, const ScopedPtrList<Statement>& statements) { - return new (zone_) CaseClause(zone_, label, statements); + return zone_->New<CaseClause>(zone_, label, statements); } Literal* NewStringLiteral(const AstRawString* string, int pos) { DCHECK_NOT_NULL(string); - return new (zone_) Literal(string, pos); + return zone_->New<Literal>(string, pos); } // A JavaScript symbol (ECMA-262 edition 6). Literal* NewSymbolLiteral(AstSymbol symbol, int pos) { - return new (zone_) Literal(symbol, pos); + return zone_->New<Literal>(symbol, pos); } Literal* NewNumberLiteral(double number, int pos); Literal* NewSmiLiteral(int number, int pos) { - return new (zone_) Literal(number, pos); + return zone_->New<Literal>(number, pos); } Literal* NewBigIntLiteral(AstBigInt bigint, int pos) { - return new (zone_) Literal(bigint, pos); + return zone_->New<Literal>(bigint, pos); } Literal* NewBooleanLiteral(bool b, int pos) { - return new (zone_) Literal(b, pos); + return zone_->New<Literal>(b, pos); } Literal* NewNullLiteral(int pos) { - return new (zone_) Literal(Literal::kNull, pos); + return zone_->New<Literal>(Literal::kNull, pos); } Literal* NewUndefinedLiteral(int pos) { - return new (zone_) Literal(Literal::kUndefined, pos); + return zone_->New<Literal>(Literal::kUndefined, pos); } Literal* NewTheHoleLiteral() { - return new (zone_) Literal(Literal::kTheHole, kNoSourcePosition); + return zone_->New<Literal>(Literal::kTheHole, kNoSourcePosition); } ObjectLiteral* NewObjectLiteral( const ScopedPtrList<ObjectLiteral::Property>& properties, uint32_t boilerplate_properties, int pos, bool has_rest_property) { - return new (zone_) ObjectLiteral(zone_, properties, boilerplate_properties, + return zone_->New<ObjectLiteral>(zone_, properties, boilerplate_properties, pos, has_rest_property); } ObjectLiteral::Property* NewObjectLiteralProperty( Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, bool is_computed_name) { - return new (zone_) - ObjectLiteral::Property(key, value, kind, is_computed_name); + return zone_->New<ObjectLiteral::Property>(key, value, kind, + is_computed_name); } ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, Expression* value, bool is_computed_name) { - return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, + return zone_->New<ObjectLiteral::Property>(ast_value_factory_, key, value, is_computed_name); } RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, int pos) { - return new (zone_) RegExpLiteral(pattern, flags, pos); + return zone_->New<RegExpLiteral>(pattern, flags, pos); } ArrayLiteral* NewArrayLiteral(const ScopedPtrList<Expression>& values, int pos) { - return new (zone_) ArrayLiteral(zone_, values, -1, pos); + return zone_->New<ArrayLiteral>(zone_, values, -1, pos); } ArrayLiteral* NewArrayLiteral(const ScopedPtrList<Expression>& values, int first_spread_index, int pos) { - return new (zone_) ArrayLiteral(zone_, values, first_spread_index, pos); + return zone_->New<ArrayLiteral>(zone_, values, first_spread_index, pos); } VariableProxy* NewVariableProxy(Variable* var, int start_position = kNoSourcePosition) { - return new (zone_) VariableProxy(var, start_position); + return zone_->New<VariableProxy>(var, start_position); } VariableProxy* NewVariableProxy(const AstRawString* name, VariableKind variable_kind, int start_position = kNoSourcePosition) { DCHECK_NOT_NULL(name); - return new (zone_) VariableProxy(name, variable_kind, start_position); + return zone_->New<VariableProxy>(name, variable_kind, start_position); } // Recreates the VariableProxy in this Zone. VariableProxy* CopyVariableProxy(VariableProxy* proxy) { - return new (zone_) VariableProxy(proxy); + return zone_->New<VariableProxy>(proxy); } Variable* CopyVariable(Variable* variable) { - return new (zone_) Variable(variable); + return zone_->New<Variable>(variable); } OptionalChain* NewOptionalChain(Expression* expression) { - return new (zone_) OptionalChain(expression); + return zone_->New<OptionalChain>(expression); } Property* NewProperty(Expression* obj, Expression* key, int pos, bool optional_chain = false) { - return new (zone_) Property(obj, key, pos, optional_chain); + return zone_->New<Property>(obj, key, pos, optional_chain); } Call* NewCall(Expression* expression, const ScopedPtrList<Expression>& arguments, int pos, Call::PossiblyEval possibly_eval = Call::NOT_EVAL, bool optional_chain = false) { - return new (zone_) - Call(zone_, expression, arguments, pos, possibly_eval, optional_chain); + DCHECK_IMPLIES(possibly_eval == Call::IS_POSSIBLY_EVAL, !optional_chain); + return zone_->New<Call>(zone_, expression, arguments, pos, possibly_eval, + optional_chain); } Call* NewTaggedTemplate(Expression* expression, const ScopedPtrList<Expression>& arguments, int pos) { - return new (zone_) - Call(zone_, expression, arguments, pos, Call::TaggedTemplateTag::kTrue); + return zone_->New<Call>(zone_, expression, arguments, pos, + Call::TaggedTemplateTag::kTrue); } CallNew* NewCallNew(Expression* expression, const ScopedPtrList<Expression>& arguments, int pos) { - return new (zone_) CallNew(zone_, expression, arguments, pos); + return zone_->New<CallNew>(zone_, expression, arguments, pos); } CallRuntime* NewCallRuntime(Runtime::FunctionId id, const ScopedPtrList<Expression>& arguments, int pos) { - return new (zone_) - CallRuntime(zone_, Runtime::FunctionForId(id), arguments, pos); + return zone_->New<CallRuntime>(zone_, Runtime::FunctionForId(id), arguments, + pos); } CallRuntime* NewCallRuntime(const Runtime::Function* function, const ScopedPtrList<Expression>& arguments, int pos) { - return new (zone_) CallRuntime(zone_, function, arguments, pos); + return zone_->New<CallRuntime>(zone_, function, arguments, pos); } CallRuntime* NewCallRuntime(int context_index, const ScopedPtrList<Expression>& arguments, int pos) { - return new (zone_) CallRuntime(zone_, context_index, arguments, pos); + return zone_->New<CallRuntime>(zone_, context_index, arguments, pos); } UnaryOperation* NewUnaryOperation(Token::Value op, Expression* expression, int pos) { - return new (zone_) UnaryOperation(op, expression, pos); + return zone_->New<UnaryOperation>(op, expression, pos); } BinaryOperation* NewBinaryOperation(Token::Value op, Expression* left, Expression* right, int pos) { - return new (zone_) BinaryOperation(op, left, right, pos); + return zone_->New<BinaryOperation>(op, left, right, pos); } NaryOperation* NewNaryOperation(Token::Value op, Expression* first, size_t initial_subsequent_size) { - return new (zone_) NaryOperation(zone_, op, first, initial_subsequent_size); + return zone_->New<NaryOperation>(zone_, op, first, initial_subsequent_size); } CountOperation* NewCountOperation(Token::Value op, bool is_prefix, Expression* expr, int pos) { - return new (zone_) CountOperation(op, is_prefix, expr, pos); + return zone_->New<CountOperation>(op, is_prefix, expr, pos); } CompareOperation* NewCompareOperation(Token::Value op, Expression* left, Expression* right, int pos) { - return new (zone_) CompareOperation(op, left, right, pos); + return zone_->New<CompareOperation>(op, left, right, pos); } Spread* NewSpread(Expression* expression, int pos, int expr_pos) { - return new (zone_) Spread(expression, pos, expr_pos); + return zone_->New<Spread>(expression, pos, expr_pos); } Conditional* NewConditional(Expression* condition, Expression* then_expression, Expression* else_expression, int position) { - return new (zone_) - Conditional(condition, then_expression, else_expression, position); + return zone_->New<Conditional>(condition, then_expression, else_expression, + position); } Assignment* NewAssignment(Token::Value op, @@ -3070,10 +3121,10 @@ class AstNodeFactory final { } if (op == Token::ASSIGN || op == Token::INIT) { - return new (zone_) - Assignment(AstNode::kAssignment, op, target, value, pos); + return zone_->New<Assignment>(AstNode::kAssignment, op, target, value, + pos); } else { - return new (zone_) CompoundAssignment( + return zone_->New<CompoundAssignment>( op, target, value, pos, NewBinaryOperation(Token::BinaryOpForAssignment(op), target, value, pos + 1)); @@ -3083,20 +3134,20 @@ class AstNodeFactory final { Suspend* NewYield(Expression* expression, int pos, Suspend::OnAbruptResume on_abrupt_resume) { if (!expression) expression = NewUndefinedLiteral(pos); - return new (zone_) Yield(expression, pos, on_abrupt_resume); + return zone_->New<Yield>(expression, pos, on_abrupt_resume); } YieldStar* NewYieldStar(Expression* expression, int pos) { - return new (zone_) YieldStar(expression, pos); + return zone_->New<YieldStar>(expression, pos); } Await* NewAwait(Expression* expression, int pos) { if (!expression) expression = NewUndefinedLiteral(pos); - return new (zone_) Await(expression, pos); + return zone_->New<Await>(expression, pos); } Throw* NewThrow(Expression* exception, int pos) { - return new (zone_) Throw(exception, pos); + return zone_->New<Throw>(exception, pos); } FunctionLiteral* NewFunctionLiteral( @@ -3108,7 +3159,7 @@ class AstNodeFactory final { FunctionLiteral::EagerCompileHint eager_compile_hint, int position, bool has_braces, int function_literal_id, ProducedPreparseData* produced_preparse_data = nullptr) { - return new (zone_) FunctionLiteral( + return zone_->New<FunctionLiteral>( zone_, name ? ast_value_factory_->NewConsString(name) : nullptr, ast_value_factory_, scope, body, expected_property_count, parameter_count, function_length, function_syntax_kind, @@ -3122,7 +3173,7 @@ class AstNodeFactory final { FunctionLiteral* NewScriptOrEvalFunctionLiteral( DeclarationScope* scope, const ScopedPtrList<Statement>& body, int expected_property_count, int parameter_count) { - return new (zone_) FunctionLiteral( + return zone_->New<FunctionLiteral>( zone_, ast_value_factory_->empty_cons_string(), ast_value_factory_, scope, body, expected_property_count, parameter_count, parameter_count, FunctionSyntaxKind::kAnonymousExpression, @@ -3134,7 +3185,7 @@ class AstNodeFactory final { ClassLiteral::Property* NewClassLiteralProperty( Expression* key, Expression* value, ClassLiteralProperty::Kind kind, bool is_static, bool is_computed_name, bool is_private) { - return new (zone_) ClassLiteral::Property(key, value, kind, is_static, + return zone_->New<ClassLiteral::Property>(key, value, kind, is_static, is_computed_name, is_private); } @@ -3147,7 +3198,7 @@ class AstNodeFactory final { int start_position, int end_position, bool has_name_static_property, bool has_static_computed_names, bool is_anonymous, bool has_private_methods) { - return new (zone_) ClassLiteral( + return zone_->New<ClassLiteral>( scope, extends, constructor, public_members, private_members, static_fields_initializer, instance_members_initializer_function, start_position, end_position, has_name_static_property, @@ -3157,44 +3208,44 @@ class AstNodeFactory final { NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, v8::Extension* extension, int pos) { - return new (zone_) NativeFunctionLiteral(name, extension, pos); + return zone_->New<NativeFunctionLiteral>(name, extension, pos); } SuperPropertyReference* NewSuperPropertyReference(Expression* home_object, int pos) { - return new (zone_) SuperPropertyReference(home_object, pos); + return zone_->New<SuperPropertyReference>(home_object, pos); } SuperCallReference* NewSuperCallReference(VariableProxy* new_target_var, VariableProxy* this_function_var, int pos) { - return new (zone_) - SuperCallReference(new_target_var, this_function_var, pos); + return zone_->New<SuperCallReference>(new_target_var, this_function_var, + pos); } EmptyParentheses* NewEmptyParentheses(int pos) { - return new (zone_) EmptyParentheses(pos); + return zone_->New<EmptyParentheses>(pos); } GetTemplateObject* NewGetTemplateObject( const ZonePtrList<const AstRawString>* cooked_strings, const ZonePtrList<const AstRawString>* raw_strings, int pos) { - return new (zone_) GetTemplateObject(cooked_strings, raw_strings, pos); + return zone_->New<GetTemplateObject>(cooked_strings, raw_strings, pos); } TemplateLiteral* NewTemplateLiteral( const ZonePtrList<const AstRawString>* string_parts, const ZonePtrList<Expression>* substitutions, int pos) { - return new (zone_) TemplateLiteral(string_parts, substitutions, pos); + return zone_->New<TemplateLiteral>(string_parts, substitutions, pos); } ImportCallExpression* NewImportCallExpression(Expression* args, int pos) { - return new (zone_) ImportCallExpression(args, pos); + return zone_->New<ImportCallExpression>(args, pos); } InitializeClassMembersStatement* NewInitializeClassMembersStatement( ZonePtrList<ClassLiteral::Property>* args, int pos) { - return new (zone_) InitializeClassMembersStatement(args, pos); + return zone_->New<InitializeClassMembersStatement>(args, pos); } Zone* zone() const { return zone_; } diff --git a/chromium/v8/src/ast/modules.cc b/chromium/v8/src/ast/modules.cc index 99371306fcf..08fbe761020 100644 --- a/chromium/v8/src/ast/modules.cc +++ b/chromium/v8/src/ast/modules.cc @@ -3,9 +3,10 @@ // found in the LICENSE file. #include "src/ast/modules.h" + #include "src/ast/ast-value-factory.h" #include "src/ast/scopes.h" -#include "src/heap/off-thread-factory-inl.h" +#include "src/heap/local-factory-inl.h" #include "src/objects/module-inl.h" #include "src/objects/objects-inl.h" #include "src/parsing/pending-compilation-error-handler.h" @@ -32,7 +33,7 @@ void SourceTextModuleDescriptor::AddImport( const AstRawString* import_name, const AstRawString* local_name, const AstRawString* module_request, const Scanner::Location loc, const Scanner::Location specifier_loc, Zone* zone) { - Entry* entry = new (zone) Entry(loc); + Entry* entry = zone->New<Entry>(loc); entry->local_name = local_name; entry->import_name = import_name; entry->module_request = AddModuleRequest(module_request, specifier_loc); @@ -43,7 +44,7 @@ void SourceTextModuleDescriptor::AddStarImport( const AstRawString* local_name, const AstRawString* module_request, const Scanner::Location loc, const Scanner::Location specifier_loc, Zone* zone) { - Entry* entry = new (zone) Entry(loc); + Entry* entry = zone->New<Entry>(loc); entry->local_name = local_name; entry->module_request = AddModuleRequest(module_request, specifier_loc); AddNamespaceImport(entry, zone); @@ -57,7 +58,7 @@ void SourceTextModuleDescriptor::AddEmptyImport( void SourceTextModuleDescriptor::AddExport(const AstRawString* local_name, const AstRawString* export_name, Scanner::Location loc, Zone* zone) { - Entry* entry = new (zone) Entry(loc); + Entry* entry = zone->New<Entry>(loc); entry->export_name = export_name; entry->local_name = local_name; AddRegularExport(entry); @@ -69,7 +70,7 @@ void SourceTextModuleDescriptor::AddExport( const Scanner::Location specifier_loc, Zone* zone) { DCHECK_NOT_NULL(import_name); DCHECK_NOT_NULL(export_name); - Entry* entry = new (zone) Entry(loc); + Entry* entry = zone->New<Entry>(loc); entry->export_name = export_name; entry->import_name = import_name; entry->module_request = AddModuleRequest(module_request, specifier_loc); @@ -79,7 +80,7 @@ void SourceTextModuleDescriptor::AddExport( void SourceTextModuleDescriptor::AddStarExport( const AstRawString* module_request, const Scanner::Location loc, const Scanner::Location specifier_loc, Zone* zone) { - Entry* entry = new (zone) Entry(loc); + Entry* entry = zone->New<Entry>(loc); entry->module_request = AddModuleRequest(module_request, specifier_loc); AddSpecialExport(entry, zone); } @@ -106,7 +107,7 @@ Handle<SourceTextModuleInfoEntry> SourceTextModuleDescriptor::Entry::Serialize( template Handle<SourceTextModuleInfoEntry> SourceTextModuleDescriptor::Entry::Serialize(Isolate* isolate) const; template Handle<SourceTextModuleInfoEntry> -SourceTextModuleDescriptor::Entry::Serialize(OffThreadIsolate* isolate) const; +SourceTextModuleDescriptor::Entry::Serialize(LocalIsolate* isolate) const; template <typename LocalIsolate> Handle<FixedArray> SourceTextModuleDescriptor::SerializeRegularExports( @@ -164,7 +165,7 @@ Handle<FixedArray> SourceTextModuleDescriptor::SerializeRegularExports( template Handle<FixedArray> SourceTextModuleDescriptor::SerializeRegularExports( Isolate* isolate, Zone* zone) const; template Handle<FixedArray> SourceTextModuleDescriptor::SerializeRegularExports( - OffThreadIsolate* isolate, Zone* zone) const; + LocalIsolate* isolate, Zone* zone) const; void SourceTextModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) { for (auto it = regular_exports_.begin(); it != regular_exports_.end();) { diff --git a/chromium/v8/src/ast/scopes.cc b/chromium/v8/src/ast/scopes.cc index 3f0a1adbc3a..6e0e238d33e 100644 --- a/chromium/v8/src/ast/scopes.cc +++ b/chromium/v8/src/ast/scopes.cc @@ -11,16 +11,18 @@ #include "src/base/optional.h" #include "src/builtins/accessors.h" #include "src/common/message-template.h" -#include "src/heap/off-thread-factory-inl.h" +#include "src/heap/local-factory-inl.h" #include "src/init/bootstrapper.h" #include "src/logging/counters.h" #include "src/objects/module-inl.h" #include "src/objects/objects-inl.h" #include "src/objects/scope-info.h" +#include "src/objects/string-set-inl.h" #include "src/parsing/parse-info.h" #include "src/parsing/parser.h" #include "src/parsing/preparse-data.h" #include "src/zone/zone-list-inl.h" +#include "src/zone/zone.h" namespace v8 { namespace internal { @@ -34,27 +36,34 @@ namespace internal { // use. Because a Variable holding a handle with the same location exists // this is ensured. +static_assert(sizeof(VariableMap) == (sizeof(void*) + 2 * sizeof(uint32_t) + + sizeof(ZoneAllocationPolicy)), + "Empty base optimization didn't kick in for VariableMap"); + VariableMap::VariableMap(Zone* zone) : ZoneHashMap(8, ZoneAllocationPolicy(zone)) {} +VariableMap::VariableMap(const VariableMap& other, Zone* zone) + : ZoneHashMap(other, ZoneAllocationPolicy(zone)) {} + Variable* VariableMap::Declare(Zone* zone, Scope* scope, const AstRawString* name, VariableMode mode, VariableKind kind, InitializationFlag initialization_flag, MaybeAssignedFlag maybe_assigned_flag, IsStaticFlag is_static_flag, bool* was_added) { + DCHECK_EQ(zone, allocator().zone()); // AstRawStrings are unambiguous, i.e., the same string is always represented // by the same AstRawString*. // FIXME(marja): fix the type of Lookup. - Entry* p = - ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->Hash(), - ZoneAllocationPolicy(zone)); + Entry* p = ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), + name->Hash()); *was_added = p->value == nullptr; if (*was_added) { // The variable has not been declared yet -> insert it. DCHECK_EQ(name, p->key); Variable* variable = - new (zone) Variable(scope, name, mode, kind, initialization_flag, + zone->New<Variable>(scope, name, mode, kind, initialization_flag, maybe_assigned_flag, is_static_flag); p->value = variable; } @@ -66,11 +75,10 @@ void VariableMap::Remove(Variable* var) { ZoneHashMap::Remove(const_cast<AstRawString*>(name), name->Hash()); } -void VariableMap::Add(Zone* zone, Variable* var) { +void VariableMap::Add(Variable* var) { const AstRawString* name = var->raw_name(); - Entry* p = - ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->Hash(), - ZoneAllocationPolicy(zone)); + Entry* p = ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), + name->Hash()); DCHECK_NULL(p->value); DCHECK_EQ(name, p->key); p->value = var; @@ -90,18 +98,12 @@ Variable* VariableMap::Lookup(const AstRawString* name) { // Implementation of Scope Scope::Scope(Zone* zone) - : zone_(zone), - outer_scope_(nullptr), - variables_(zone), - scope_type_(SCRIPT_SCOPE) { + : outer_scope_(nullptr), variables_(zone), scope_type_(SCRIPT_SCOPE) { SetDefaults(); } Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) - : zone_(zone), - outer_scope_(outer_scope), - variables_(zone), - scope_type_(scope_type) { + : outer_scope_(outer_scope), variables_(zone), scope_type_(scope_type) { DCHECK_NE(SCRIPT_SCOPE, scope_type); SetDefaults(); set_language_mode(outer_scope->language_mode()); @@ -138,8 +140,8 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, ModuleScope::ModuleScope(DeclarationScope* script_scope, AstValueFactory* avfactory) : DeclarationScope(avfactory->zone(), script_scope, MODULE_SCOPE, kModule), - module_descriptor_(new (avfactory->zone()) - SourceTextModuleDescriptor(avfactory->zone())) { + module_descriptor_(avfactory->zone()->New<SourceTextModuleDescriptor>( + avfactory->zone())) { set_language_mode(LanguageMode::kStrict); DeclareThis(avfactory); } @@ -192,8 +194,7 @@ ClassScope::ClassScope(Isolate* isolate, Zone* zone, } Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) - : zone_(zone), - outer_scope_(nullptr), + : outer_scope_(nullptr), variables_(zone), scope_info_(scope_info), scope_type_(scope_type) { @@ -226,8 +227,7 @@ DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type, Scope::Scope(Zone* zone, const AstRawString* catch_variable_name, MaybeAssignedFlag maybe_assigned, Handle<ScopeInfo> scope_info) - : zone_(zone), - outer_scope_(nullptr), + : outer_scope_(nullptr), variables_(zone), scope_info_(scope_info), scope_type_(CATCH_SCOPE) { @@ -357,13 +357,13 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, while (!scope_info.is_null()) { if (scope_info.scope_type() == WITH_SCOPE) { if (scope_info.IsDebugEvaluateScope()) { - outer_scope = new (zone) - DeclarationScope(zone, FUNCTION_SCOPE, handle(scope_info, isolate)); + outer_scope = zone->New<DeclarationScope>(zone, FUNCTION_SCOPE, + handle(scope_info, isolate)); outer_scope->set_is_debug_evaluate_scope(); } else { // For scope analysis, debug-evaluate is equivalent to a with scope. outer_scope = - new (zone) Scope(zone, WITH_SCOPE, handle(scope_info, isolate)); + zone->New<Scope>(zone, WITH_SCOPE, handle(scope_info, isolate)); } } else if (scope_info.scope_type() == SCRIPT_SCOPE) { @@ -377,28 +377,28 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, DCHECK(!scope_info.HasOuterScopeInfo()); break; } else if (scope_info.scope_type() == FUNCTION_SCOPE) { - outer_scope = new (zone) - DeclarationScope(zone, FUNCTION_SCOPE, handle(scope_info, isolate)); + outer_scope = zone->New<DeclarationScope>(zone, FUNCTION_SCOPE, + handle(scope_info, isolate)); if (scope_info.IsAsmModule()) { outer_scope->AsDeclarationScope()->set_is_asm_module(); } } else if (scope_info.scope_type() == EVAL_SCOPE) { - outer_scope = new (zone) - DeclarationScope(zone, EVAL_SCOPE, handle(scope_info, isolate)); + outer_scope = zone->New<DeclarationScope>(zone, EVAL_SCOPE, + handle(scope_info, isolate)); } else if (scope_info.scope_type() == CLASS_SCOPE) { - outer_scope = new (zone) ClassScope(isolate, zone, ast_value_factory, + outer_scope = zone->New<ClassScope>(isolate, zone, ast_value_factory, handle(scope_info, isolate)); } else if (scope_info.scope_type() == BLOCK_SCOPE) { if (scope_info.is_declaration_scope()) { - outer_scope = new (zone) - DeclarationScope(zone, BLOCK_SCOPE, handle(scope_info, isolate)); + outer_scope = zone->New<DeclarationScope>(zone, BLOCK_SCOPE, + handle(scope_info, isolate)); } else { outer_scope = - new (zone) Scope(zone, BLOCK_SCOPE, handle(scope_info, isolate)); + zone->New<Scope>(zone, BLOCK_SCOPE, handle(scope_info, isolate)); } } else if (scope_info.scope_type() == MODULE_SCOPE) { - outer_scope = new (zone) - ModuleScope(isolate, handle(scope_info, isolate), ast_value_factory); + outer_scope = zone->New<ModuleScope>(isolate, handle(scope_info, isolate), + ast_value_factory); } else { DCHECK_EQ(scope_info.scope_type(), CATCH_SCOPE); DCHECK_EQ(scope_info.ContextLocalCount(), 1); @@ -407,9 +407,9 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, String name = scope_info.ContextLocalName(0); MaybeAssignedFlag maybe_assigned = scope_info.ContextLocalMaybeAssignedFlag(0); - outer_scope = new (zone) - Scope(zone, ast_value_factory->GetString(handle(name, isolate)), - maybe_assigned, handle(scope_info, isolate)); + outer_scope = zone->New<Scope>( + zone, ast_value_factory->GetString(handle(name, isolate)), + maybe_assigned, handle(scope_info, isolate)); } if (deserialization_mode == DeserializationMode::kScopesOnly) { outer_scope->scope_info_ = Handle<ScopeInfo>::null(); @@ -621,12 +621,12 @@ void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { bool derived_constructor = IsDerivedConstructor(function_kind_); - receiver_ = new (zone()) - Variable(this, ast_value_factory->this_string(), - derived_constructor ? VariableMode::kConst : VariableMode::kVar, - THIS_VARIABLE, - derived_constructor ? kNeedsInitialization : kCreatedInitialized, - kNotAssigned); + receiver_ = zone()->New<Variable>( + this, ast_value_factory->this_string(), + derived_constructor ? VariableMode::kConst : VariableMode::kVar, + THIS_VARIABLE, + derived_constructor ? kNeedsInitialization : kCreatedInitialized, + kNotAssigned); } void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) { @@ -677,12 +677,12 @@ Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name, DCHECK_NULL(cache->variables_.Lookup(name)); VariableKind kind = is_sloppy(language_mode()) ? SLOPPY_FUNCTION_NAME_VARIABLE : NORMAL_VARIABLE; - function_ = new (zone()) - Variable(this, name, VariableMode::kConst, kind, kCreatedInitialized); + function_ = zone()->New<Variable>(this, name, VariableMode::kConst, kind, + kCreatedInitialized); if (sloppy_eval_can_extend_vars()) { cache->NonLocal(name, VariableMode::kDynamic); } else { - cache->variables_.Add(zone(), function_); + cache->variables_.Add(function_); } return function_; } @@ -1131,7 +1131,7 @@ Variable* Scope::NewTemporary(const AstRawString* name) { Variable* Scope::NewTemporary(const AstRawString* name, MaybeAssignedFlag maybe_assigned) { DeclarationScope* scope = GetClosureScope(); - Variable* var = new (zone()) Variable(scope, name, VariableMode::kTemporary, + Variable* var = zone()->New<Variable>(scope, name, VariableMode::kTemporary, NORMAL_VARIABLE, kCreatedInitialized); scope->AddLocal(var); if (maybe_assigned == kMaybeAssigned) var->SetMaybeAssigned(); @@ -1514,7 +1514,7 @@ void DeclarationScope::ResetAfterPreparsing(AstValueFactory* ast_value_factory, DCHECK(is_function_scope()); // Reset all non-trivial members. - params_.Clear(); + params_.DropAndClear(); decls_.Clear(); locals_.Clear(); inner_scope_ = nullptr; @@ -1524,21 +1524,22 @@ void DeclarationScope::ResetAfterPreparsing(AstValueFactory* ast_value_factory, has_rest_ = false; function_ = nullptr; - DCHECK_NE(zone_, ast_value_factory->zone()); - zone_->ReleaseMemory(); + DCHECK_NE(zone(), ast_value_factory->zone()); + // Make sure this scope and zone aren't used for allocation anymore. + { + // Get the zone, while variables_ is still valid + Zone* zone = this->zone(); + variables_.Invalidate(); + zone->ReleaseMemory(); + } if (aborted) { // Prepare scope for use in the outer zone. - zone_ = ast_value_factory->zone(); - variables_.Reset(ZoneAllocationPolicy(zone_)); + variables_ = VariableMap(ast_value_factory->zone()); if (!IsArrowFunction(function_kind_)) { has_simple_parameters_ = true; DeclareDefaultFunctionVariables(ast_value_factory); } - } else { - // Make sure this scope isn't used for allocation anymore. - zone_ = nullptr; - variables_.Invalidate(); } #ifdef DEBUG @@ -2476,8 +2477,8 @@ template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope:: AllocateScopeInfosRecursively<Isolate>(Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope); template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope:: - AllocateScopeInfosRecursively<OffThreadIsolate>( - OffThreadIsolate* isolate, MaybeHandle<ScopeInfo> outer_scope); + AllocateScopeInfosRecursively<LocalIsolate>( + LocalIsolate* isolate, MaybeHandle<ScopeInfo> outer_scope); void DeclarationScope::RecalcPrivateNameContextChain() { // The outermost scope in a class heritage expression is marked to skip the @@ -2556,10 +2557,10 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info, } } -template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos<Isolate>( +template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos( ParseInfo* info, Isolate* isolate); -template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos< - OffThreadIsolate>(ParseInfo* info, OffThreadIsolate* isolate); +template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos( + ParseInfo* info, LocalIsolate* isolate); int Scope::ContextLocalCount() const { if (num_heap_slots() == 0) return 0; diff --git a/chromium/v8/src/ast/scopes.h b/chromium/v8/src/ast/scopes.h index babb90bdd01..a5f4523670a 100644 --- a/chromium/v8/src/ast/scopes.h +++ b/chromium/v8/src/ast/scopes.h @@ -6,6 +6,7 @@ #define V8_AST_SCOPES_H_ #include <numeric> + #include "src/ast/ast.h" #include "src/base/compiler-specific.h" #include "src/base/hashmap.h" @@ -15,6 +16,7 @@ #include "src/objects/objects.h" #include "src/utils/pointer-with-payload.h" #include "src/utils/utils.h" +#include "src/zone/zone-hashmap.h" #include "src/zone/zone.h" namespace v8 { @@ -39,6 +41,15 @@ using UnresolvedList = class VariableMap : public ZoneHashMap { public: explicit VariableMap(Zone* zone); + VariableMap(const VariableMap& other, Zone* zone); + + VariableMap(VariableMap&& other) V8_NOEXCEPT : ZoneHashMap(std::move(other)) { + } + + VariableMap& operator=(VariableMap&& other) V8_NOEXCEPT { + static_cast<ZoneHashMap&>(*this) = std::move(other); + return *this; + } Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, VariableMode mode, VariableKind kind, @@ -48,7 +59,9 @@ class VariableMap : public ZoneHashMap { V8_EXPORT_PRIVATE Variable* Lookup(const AstRawString* name); void Remove(Variable* var); - void Add(Zone* zone, Variable* var); + void Add(Variable* var); + + Zone* zone() const { return allocator().zone(); } }; class Scope; @@ -166,7 +179,7 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) { // Assumes outer_scope_ is non-null. void ReplaceOuterScope(Scope* outer_scope); - Zone* zone() const { return zone_; } + Zone* zone() const { return variables_.zone(); } void SetMustUsePreparseData() { if (must_use_preparsed_scope_data_) { @@ -697,8 +710,7 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) { friend class DeclarationScope; friend class ClassScope; friend class ScopeTestHelper; - - Zone* zone_; + friend Zone; // Scope tree. Scope* outer_scope_; // the immediately enclosing outer scope, or nullptr @@ -896,11 +908,13 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope { } bool is_being_lazily_parsed() const { return is_being_lazily_parsed_; } #endif + void set_zone(Zone* zone) { #ifdef DEBUG needs_migration_ = true; #endif - zone_ = zone; + // Migrate variables_' backing store to new zone. + variables_ = VariableMap(variables_, zone); } // --------------------------------------------------------------------------- @@ -1258,7 +1272,7 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope { V8_INLINE RareData* EnsureRareData() { if (rare_data_ == nullptr) { - rare_data_ = new (zone_) RareData; + rare_data_ = zone()->New<RareData>(); } return rare_data_; } @@ -1439,8 +1453,8 @@ class V8_EXPORT_PRIVATE ClassScope : public Scope { } V8_INLINE RareData* EnsureRareData() { if (GetRareData() == nullptr) { - rare_data_and_is_parsing_heritage_.SetPointer(new (zone_) - RareData(zone_)); + rare_data_and_is_parsing_heritage_.SetPointer( + zone()->New<RareData>(zone())); } return GetRareData(); } diff --git a/chromium/v8/src/ast/source-range-ast-visitor.cc b/chromium/v8/src/ast/source-range-ast-visitor.cc index 52359d54525..ee2c4f58743 100644 --- a/chromium/v8/src/ast/source-range-ast-visitor.cc +++ b/chromium/v8/src/ast/source-range-ast-visitor.cc @@ -99,11 +99,13 @@ void SourceRangeAstVisitor::MaybeRemoveLastContinuationRange( } namespace { -Statement* FindLastNonSyntheticReturn(ZonePtrList<Statement>* statements) { +Statement* FindLastNonSyntheticStatement(ZonePtrList<Statement>* statements) { for (int i = statements->length() - 1; i >= 0; --i) { Statement* stmt = statements->at(i); - if (!stmt->IsReturnStatement()) break; - if (stmt->AsReturnStatement()->is_synthetic_async_return()) continue; + if (stmt->IsReturnStatement() && + stmt->AsReturnStatement()->is_synthetic_async_return()) { + continue; + } return stmt; } return nullptr; @@ -114,11 +116,11 @@ void SourceRangeAstVisitor::MaybeRemoveContinuationRangeOfAsyncReturn( TryCatchStatement* try_catch_stmt) { // Detect try-catch inserted by NewTryCatchStatementForAsyncAwait in the // parser (issued for async functions, including async generators), and - // remove the continuation ranges of return statements corresponding to - // returns at function end in the untransformed source. + // remove the continuation range of the last statement, such that the + // range of the enclosing function body is used. if (try_catch_stmt->is_try_catch_for_async()) { Statement* last_non_synthetic = - FindLastNonSyntheticReturn(try_catch_stmt->try_block()->statements()); + FindLastNonSyntheticStatement(try_catch_stmt->try_block()->statements()); if (last_non_synthetic) { MaybeRemoveContinuationRange(last_non_synthetic); } |