diff options
author | Michaël Zasso <targos@protonmail.com> | 2019-08-01 08:38:30 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2019-08-01 12:53:56 +0200 |
commit | 2dcc3665abf57c3607cebffdeeca062f5894885d (patch) | |
tree | 4f560748132edcfb4c22d6f967a7e80d23d7ea2c /deps/v8/src/ast | |
parent | 1ee47d550c6de132f06110aa13eceb7551d643b3 (diff) | |
download | android-node-v8-2dcc3665abf57c3607cebffdeeca062f5894885d.tar.gz android-node-v8-2dcc3665abf57c3607cebffdeeca062f5894885d.tar.bz2 android-node-v8-2dcc3665abf57c3607cebffdeeca062f5894885d.zip |
deps: update V8 to 7.6.303.28
PR-URL: https://github.com/nodejs/node/pull/28016
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann (רפאל פלחי) <refack@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Diffstat (limited to 'deps/v8/src/ast')
-rw-r--r-- | deps/v8/src/ast/ast-function-literal-id-reindexer.cc | 72 | ||||
-rw-r--r-- | deps/v8/src/ast/ast-function-literal-id-reindexer.h | 16 | ||||
-rw-r--r-- | deps/v8/src/ast/ast-source-ranges.h | 25 | ||||
-rw-r--r-- | deps/v8/src/ast/ast-value-factory.cc | 55 | ||||
-rw-r--r-- | deps/v8/src/ast/ast-value-factory.h | 14 | ||||
-rw-r--r-- | deps/v8/src/ast/ast.cc | 27 | ||||
-rw-r--r-- | deps/v8/src/ast/ast.h | 38 | ||||
-rw-r--r-- | deps/v8/src/ast/modules.cc | 4 | ||||
-rw-r--r-- | deps/v8/src/ast/modules.h | 12 | ||||
-rw-r--r-- | deps/v8/src/ast/prettyprinter.cc | 47 | ||||
-rw-r--r-- | deps/v8/src/ast/prettyprinter.h | 4 | ||||
-rw-r--r-- | deps/v8/src/ast/scopes.cc | 81 | ||||
-rw-r--r-- | deps/v8/src/ast/scopes.h | 21 | ||||
-rw-r--r-- | deps/v8/src/ast/variables.cc | 4 | ||||
-rw-r--r-- | deps/v8/src/ast/variables.h | 4 |
15 files changed, 288 insertions, 136 deletions
diff --git a/deps/v8/src/ast/ast-function-literal-id-reindexer.cc b/deps/v8/src/ast/ast-function-literal-id-reindexer.cc index 7e3a25890b..95bd94d8d4 100644 --- a/deps/v8/src/ast/ast-function-literal-id-reindexer.cc +++ b/deps/v8/src/ast/ast-function-literal-id-reindexer.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "src/ast/ast-function-literal-id-reindexer.h" -#include "src/objects-inl.h" +#include "src/objects/objects-inl.h" #include "src/ast/ast.h" @@ -17,13 +17,83 @@ AstFunctionLiteralIdReindexer::AstFunctionLiteralIdReindexer(size_t stack_limit, AstFunctionLiteralIdReindexer::~AstFunctionLiteralIdReindexer() = default; void AstFunctionLiteralIdReindexer::Reindex(Expression* pattern) { +#ifdef DEBUG + visited_.clear(); +#endif Visit(pattern); + CheckVisited(pattern); } void AstFunctionLiteralIdReindexer::VisitFunctionLiteral(FunctionLiteral* lit) { + // Make sure we're not already in the visited set. + DCHECK(visited_.insert(lit).second); + AstTraversalVisitor::VisitFunctionLiteral(lit); lit->set_function_literal_id(lit->function_literal_id() + delta_); } +void AstFunctionLiteralIdReindexer::VisitClassLiteral(ClassLiteral* expr) { + // Manually visit the class literal so that we can change the property walk. + // This should be kept in-sync with AstTraversalVisitor::VisitClassLiteral. + + if (expr->extends() != nullptr) { + Visit(expr->extends()); + } + Visit(expr->constructor()); + if (expr->static_fields_initializer() != nullptr) { + Visit(expr->static_fields_initializer()); + } + if (expr->instance_members_initializer_function() != nullptr) { + Visit(expr->instance_members_initializer_function()); + } + ZonePtrList<ClassLiteral::Property>* props = expr->properties(); + for (int i = 0; i < props->length(); ++i) { + ClassLiteralProperty* prop = props->at(i); + + // Private fields and public fields with computed names have both their key + // and value present in instance_members_initializer_function, so they will + // already have been visited. + if ((prop->is_computed_name() || prop->is_private()) && + !prop->value()->IsFunctionLiteral()) { + if (!prop->key()->IsLiteral()) { + CheckVisited(prop->key()); + } + CheckVisited(prop->value()); + } else { + if (!prop->key()->IsLiteral()) { + Visit(prop->key()); + } + Visit(prop->value()); + } + } +} + +#ifdef DEBUG +namespace { + +class AstFunctionLiteralIdReindexChecker final + : public AstTraversalVisitor<AstFunctionLiteralIdReindexChecker> { + public: + AstFunctionLiteralIdReindexChecker(size_t stack_limit, + const std::set<FunctionLiteral*>* visited) + : AstTraversalVisitor(stack_limit), visited_(visited) {} + + void VisitFunctionLiteral(FunctionLiteral* lit) { + // TODO(leszeks): It would be nice to print the unvisited function literal + // here, but that requires more advanced DCHECK support with formatting. + DCHECK(visited_->find(lit) != visited_->end()); + } + + private: + const std::set<FunctionLiteral*>* visited_; +}; + +} // namespace + +void AstFunctionLiteralIdReindexer::CheckVisited(Expression* expr) { + AstFunctionLiteralIdReindexChecker(stack_limit(), &visited_).Visit(expr); +} +#endif + } // namespace internal } // namespace v8 diff --git a/deps/v8/src/ast/ast-function-literal-id-reindexer.h b/deps/v8/src/ast/ast-function-literal-id-reindexer.h index 400196da68..f4dac7b01e 100644 --- a/deps/v8/src/ast/ast-function-literal-id-reindexer.h +++ b/deps/v8/src/ast/ast-function-literal-id-reindexer.h @@ -8,6 +8,10 @@ #include "src/ast/ast-traversal-visitor.h" #include "src/base/macros.h" +#ifdef DEBUG +#include <set> +#endif + namespace v8 { namespace internal { @@ -23,10 +27,22 @@ class AstFunctionLiteralIdReindexer final // AstTraversalVisitor implementation. void VisitFunctionLiteral(FunctionLiteral* lit); + void VisitClassLiteral(ClassLiteral* lit); private: int delta_; +#ifdef DEBUG + // Visited set, only used in DCHECKs for verification. + std::set<FunctionLiteral*> visited_; + + // Visit all function literals, checking if they have already been visited + // (are in the visited set). + void CheckVisited(Expression* expr); +#else + void CheckVisited(Expression* expr) {} +#endif + DISALLOW_COPY_AND_ASSIGN(AstFunctionLiteralIdReindexer); }; diff --git a/deps/v8/src/ast/ast-source-ranges.h b/deps/v8/src/ast/ast-source-ranges.h index a04e68fa2f..1b42a055dd 100644 --- a/deps/v8/src/ast/ast-source-ranges.h +++ b/deps/v8/src/ast/ast-source-ranges.h @@ -25,6 +25,18 @@ struct SourceRange { int end = kNoSourcePosition) { return that.IsEmpty() ? Empty() : SourceRange(that.end, end); } + + static constexpr int kFunctionLiteralSourcePosition = -2; + STATIC_ASSERT(kFunctionLiteralSourcePosition == kNoSourcePosition - 1); + + // Source ranges associated with a function literal do not contain real + // source positions; instead, they are created with special marker values. + // These are later recognized and rewritten during processing in + // Coverage::Collect(). + static SourceRange FunctionLiteralMarkerRange() { + return {kFunctionLiteralSourcePosition, kFunctionLiteralSourcePosition}; + } + int32_t start, end; }; @@ -35,6 +47,7 @@ struct SourceRange { V(Block) \ V(CaseClause) \ V(Conditional) \ + V(FunctionLiteral) \ V(IfStatement) \ V(IterationStatement) \ V(JumpStatement) \ @@ -155,6 +168,18 @@ class ConditionalSourceRanges final : public AstNodeSourceRanges { SourceRange else_range_; }; +class FunctionLiteralSourceRanges final : public AstNodeSourceRanges { + public: + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); + return SourceRange::FunctionLiteralMarkerRange(); + } + + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kBody; + } +}; + class IfStatementSourceRanges final : public AstNodeSourceRanges { public: explicit IfStatementSourceRanges(const SourceRange& then_range, diff --git a/deps/v8/src/ast/ast-value-factory.cc b/deps/v8/src/ast/ast-value-factory.cc index d6f12cb34a..55415f0bdd 100644 --- a/deps/v8/src/ast/ast-value-factory.cc +++ b/deps/v8/src/ast/ast-value-factory.cc @@ -27,11 +27,11 @@ #include "src/ast/ast-value-factory.h" -#include "src/char-predicates-inl.h" -#include "src/objects-inl.h" -#include "src/objects.h" -#include "src/string-hasher.h" -#include "src/utils-inl.h" +#include "src/objects/objects-inl.h" +#include "src/objects/objects.h" +#include "src/strings/char-predicates-inl.h" +#include "src/strings/string-hasher.h" +#include "src/utils/utils-inl.h" namespace v8 { namespace internal { @@ -54,37 +54,16 @@ class OneByteStringStream { } // namespace -class AstRawStringInternalizationKey : public StringTableKey { - public: - explicit AstRawStringInternalizationKey(const AstRawString* string) - : StringTableKey(string->hash_field()), string_(string) {} - - bool IsMatch(Object other) override { - if (string_->is_one_byte()) - return String::cast(other)->IsOneByteEqualTo(string_->literal_bytes_); - return String::cast(other)->IsTwoByteEqualTo( - Vector<const uint16_t>::cast(string_->literal_bytes_)); - } - - Handle<String> AsHandle(Isolate* isolate) override { - if (string_->is_one_byte()) - return isolate->factory()->NewOneByteInternalizedString( - string_->literal_bytes_, string_->hash_field()); - return isolate->factory()->NewTwoByteInternalizedString( - Vector<const uint16_t>::cast(string_->literal_bytes_), - string_->hash_field()); - } - - private: - const AstRawString* string_; -}; - void AstRawString::Internalize(Isolate* isolate) { DCHECK(!has_string_); if (literal_bytes_.length() == 0) { set_string(isolate->factory()->empty_string()); + } else if (is_one_byte()) { + OneByteStringKey key(hash_field_, literal_bytes_); + set_string(StringTable::LookupKey(isolate, &key)); } else { - AstRawStringInternalizationKey key(this); + TwoByteStringKey key(hash_field_, + Vector<const uint16_t>::cast(literal_bytes_)); set_string(StringTable::LookupKey(isolate, &key)); } } @@ -108,13 +87,13 @@ bool AstRawString::IsOneByteEqualTo(const char* data) const { size_t length = static_cast<size_t>(literal_bytes_.length()); if (length != strlen(data)) return false; - return 0 == strncmp(reinterpret_cast<const char*>(literal_bytes_.start()), + return 0 == strncmp(reinterpret_cast<const char*>(literal_bytes_.begin()), data, length); } uint16_t AstRawString::FirstCharacter() const { if (is_one_byte()) return literal_bytes_[0]; - const uint16_t* c = reinterpret_cast<const uint16_t*>(literal_bytes_.start()); + const uint16_t* c = reinterpret_cast<const uint16_t*>(literal_bytes_.begin()); return *c; } @@ -193,7 +172,7 @@ AstStringConstants::AstStringConstants(Isolate* isolate, uint64_t hash_seed) 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.start(), literal.length(), hash_seed_); \ + 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. */ \ @@ -213,20 +192,20 @@ AstRawString* AstValueFactory::GetOneByteStringInternal( int key = literal[0]; if (V8_UNLIKELY(one_character_strings_[key] == nullptr)) { uint32_t hash_field = StringHasher::HashSequentialString<uint8_t>( - literal.start(), literal.length(), hash_seed_); + literal.begin(), literal.length(), hash_seed_); one_character_strings_[key] = GetString(hash_field, true, literal); } return one_character_strings_[key]; } uint32_t hash_field = StringHasher::HashSequentialString<uint8_t>( - literal.start(), literal.length(), hash_seed_); + literal.begin(), literal.length(), hash_seed_); return GetString(hash_field, true, literal); } AstRawString* AstValueFactory::GetTwoByteStringInternal( Vector<const uint16_t> literal) { uint32_t hash_field = StringHasher::HashSequentialString<uint16_t>( - literal.start(), literal.length(), hash_seed_); + literal.begin(), literal.length(), hash_seed_); return GetString(hash_field, false, Vector<const byte>::cast(literal)); } @@ -298,7 +277,7 @@ AstRawString* AstValueFactory::GetString(uint32_t hash_field, bool is_one_byte, // Copy literal contents for later comparison. int length = literal_bytes.length(); byte* new_literal_bytes = zone_->NewArray<byte>(length); - memcpy(new_literal_bytes, literal_bytes.start(), length); + memcpy(new_literal_bytes, literal_bytes.begin(), length); AstRawString* new_string = new (zone_) AstRawString( is_one_byte, Vector<const byte>(new_literal_bytes, length), hash_field); CHECK_NOT_NULL(new_string); diff --git a/deps/v8/src/ast/ast-value-factory.h b/deps/v8/src/ast/ast-value-factory.h index f063c6942a..bc732ce994 100644 --- a/deps/v8/src/ast/ast-value-factory.h +++ b/deps/v8/src/ast/ast-value-factory.h @@ -31,10 +31,10 @@ #include <forward_list> #include "src/base/hashmap.h" -#include "src/conversions.h" -#include "src/globals.h" +#include "src/common/globals.h" +#include "src/execution/isolate.h" #include "src/heap/factory.h" -#include "src/isolate.h" +#include "src/numbers/conversions.h" // Ast(Raw|Cons)String and AstValueFactory are for storing strings and // values independent of the V8 heap and internalizing them later. During @@ -60,9 +60,7 @@ class AstRawString final : public ZoneObject { // Access the physical representation: bool is_one_byte() const { return is_one_byte_; } int byte_length() const { return literal_bytes_.length(); } - const unsigned char* raw_data() const { - return literal_bytes_.start(); - } + const unsigned char* raw_data() const { return literal_bytes_.begin(); } // For storing AstRawStrings in a hash map. uint32_t hash_field() const { return hash_field_; } @@ -203,6 +201,7 @@ class AstBigInt { F(bigint, "bigint") \ F(boolean, "boolean") \ F(computed, "<computed>") \ + F(dot_brand, ".brand") \ F(constructor, "constructor") \ F(default, "default") \ F(done, "done") \ @@ -298,8 +297,7 @@ class AstValueFactory { return GetOneByteStringInternal(literal); } const AstRawString* GetOneByteString(const char* string) { - return GetOneByteString(Vector<const uint8_t>( - reinterpret_cast<const uint8_t*>(string), StrLength(string))); + return GetOneByteString(OneByteVector(string)); } const AstRawString* GetTwoByteString(Vector<const uint16_t> literal) { return GetTwoByteStringInternal(literal); diff --git a/deps/v8/src/ast/ast.cc b/deps/v8/src/ast/ast.cc index 7d2227e2c8..a930a374b8 100644 --- a/deps/v8/src/ast/ast.cc +++ b/deps/v8/src/ast/ast.cc @@ -12,17 +12,17 @@ #include "src/base/hashmap.h" #include "src/builtins/builtins-constructor.h" #include "src/builtins/builtins.h" -#include "src/contexts.h" -#include "src/conversions-inl.h" -#include "src/double.h" -#include "src/elements.h" -#include "src/objects-inl.h" +#include "src/numbers/conversions-inl.h" +#include "src/numbers/double.h" +#include "src/objects/contexts.h" +#include "src/objects/elements.h" #include "src/objects/literal-objects-inl.h" #include "src/objects/literal-objects.h" #include "src/objects/map.h" -#include "src/property-details.h" -#include "src/property.h" -#include "src/string-stream.h" +#include "src/objects/objects-inl.h" +#include "src/objects/property-details.h" +#include "src/objects/property.h" +#include "src/strings/string-stream.h" #include "src/zone/zone-list-inl.h" namespace v8 { @@ -282,6 +282,17 @@ std::unique_ptr<char[]> FunctionLiteral::GetDebugName() const { return result; } +bool FunctionLiteral::requires_brand_initialization() const { + Scope* outer = scope_->outer_scope(); + + // If there are no variables declared in the outer scope other than + // the class name variable, the outer class scope may be elided when + // the function is deserialized after preparsing. + if (!outer->is_class_scope()) return false; + + return outer->AsClassScope()->brand() != nullptr; +} + ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, bool is_computed_name) : LiteralProperty(key, value, is_computed_name), diff --git a/deps/v8/src/ast/ast.h b/deps/v8/src/ast/ast.h index eb72b4f243..27d298c88e 100644 --- a/deps/v8/src/ast/ast.h +++ b/deps/v8/src/ast/ast.h @@ -10,12 +10,12 @@ #include "src/ast/ast-value-factory.h" #include "src/ast/modules.h" #include "src/ast/variables.h" -#include "src/bailout-reason.h" #include "src/base/threaded-list.h" -#include "src/globals.h" +#include "src/codegen/bailout-reason.h" +#include "src/codegen/label.h" +#include "src/common/globals.h" +#include "src/execution/isolate.h" #include "src/heap/factory.h" -#include "src/isolate.h" -#include "src/label.h" #include "src/objects/literal-objects.h" #include "src/objects/smi.h" #include "src/parsing/token.h" @@ -422,7 +422,7 @@ class DoExpression final : public Expression { class Declaration : public AstNode { public: - typedef base::ThreadedList<Declaration> List; + using List = base::ThreadedList<Declaration>; Variable* var() const { return var_; } void set_var(Variable* var) { var_ = var; } @@ -1300,7 +1300,7 @@ class ObjectLiteralProperty final : public LiteralProperty { // for minimizing the work when constructing it at runtime. class ObjectLiteral final : public AggregateLiteral { public: - typedef ObjectLiteralProperty Property; + using Property = ObjectLiteralProperty; Handle<ObjectBoilerplateDescription> boilerplate_description() const { DCHECK(!boilerplate_description_.is_null()); @@ -2342,6 +2342,8 @@ class FunctionLiteral final : public Expression { return RequiresInstanceMembersInitializer::decode(bit_field_); } + bool requires_brand_initialization() const; + ProducedPreparseData* produced_preparse_data() const { return produced_preparse_data_; } @@ -2435,12 +2437,10 @@ class ClassLiteralProperty final : public LiteralProperty { } void set_private_name_var(Variable* var) { - DCHECK_EQ(FIELD, kind()); DCHECK(is_private()); private_or_computed_name_var_ = var; } Variable* private_name_var() const { - DCHECK_EQ(FIELD, kind()); DCHECK(is_private()); return private_or_computed_name_var_; } @@ -2459,7 +2459,7 @@ class ClassLiteralProperty final : public LiteralProperty { class InitializeClassMembersStatement final : public Statement { public: - typedef ClassLiteralProperty Property; + using Property = ClassLiteralProperty; ZonePtrList<Property>* fields() const { return fields_; } @@ -2474,9 +2474,9 @@ class InitializeClassMembersStatement final : public Statement { class ClassLiteral final : public Expression { public: - typedef ClassLiteralProperty Property; + using Property = ClassLiteralProperty; - Scope* scope() const { return scope_; } + ClassScope* scope() const { return scope_; } Variable* class_variable() const { return class_variable_; } Expression* extends() const { return extends_; } FunctionLiteral* constructor() const { return constructor_; } @@ -2508,7 +2508,7 @@ class ClassLiteral final : public Expression { private: friend class AstNodeFactory; - ClassLiteral(Scope* scope, Variable* class_variable, Expression* extends, + ClassLiteral(ClassScope* scope, Variable* class_variable, Expression* extends, FunctionLiteral* constructor, ZonePtrList<Property>* properties, FunctionLiteral* static_fields_initializer, FunctionLiteral* instance_members_initializer_function, @@ -2531,7 +2531,7 @@ class ClassLiteral final : public Expression { } int end_position_; - Scope* scope_; + ClassScope* scope_; Variable* class_variable_; Expression* extends_; FunctionLiteral* constructor_; @@ -2753,6 +2753,9 @@ class AstVisitor { return false; \ } \ \ + protected: \ + uintptr_t stack_limit() const { return stack_limit_; } \ + \ private: \ void InitializeAstVisitor(Isolate* isolate) { \ stack_limit_ = isolate->stack_guard()->real_climit(); \ @@ -2938,6 +2941,13 @@ class AstNodeFactory final { } class ThisExpression* ThisExpression() { + // Clear any previously set "parenthesized" flag on this_expression_ so this + // particular token does not inherit the it. The flag is used to check + // during arrow function head parsing whether we came from parenthesized + // exprssion parsing, since additional arrow function verification was done + // there. It does not matter whether a flag is unset after arrow head + // verification, so clearing at this point is fine. + this_expression_->clear_parenthesized(); return this_expression_; } @@ -3226,7 +3236,7 @@ class AstNodeFactory final { } ClassLiteral* NewClassLiteral( - Scope* scope, Variable* variable, Expression* extends, + ClassScope* scope, Variable* variable, Expression* extends, FunctionLiteral* constructor, ZonePtrList<ClassLiteral::Property>* properties, FunctionLiteral* static_fields_initializer, diff --git a/deps/v8/src/ast/modules.cc b/deps/v8/src/ast/modules.cc index d1be965a4a..5e9bbc6332 100644 --- a/deps/v8/src/ast/modules.cc +++ b/deps/v8/src/ast/modules.cc @@ -5,9 +5,9 @@ #include "src/ast/modules.h" #include "src/ast/ast-value-factory.h" #include "src/ast/scopes.h" -#include "src/objects-inl.h" #include "src/objects/module-inl.h" -#include "src/pending-compilation-error-handler.h" +#include "src/objects/objects-inl.h" +#include "src/parsing/pending-compilation-error-handler.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/ast/modules.h b/deps/v8/src/ast/modules.h index 2c778ff349..c3aa2bd0ad 100644 --- a/deps/v8/src/ast/modules.h +++ b/deps/v8/src/ast/modules.h @@ -125,12 +125,12 @@ class ModuleDescriptor : public ZoneObject { bool operator()(const AstRawString* lhs, const AstRawString* rhs) const; }; - typedef ZoneMap<const AstRawString*, ModuleRequest, AstRawStringComparer> - ModuleRequestMap; - typedef ZoneMultimap<const AstRawString*, Entry*, AstRawStringComparer> - RegularExportMap; - typedef ZoneMap<const AstRawString*, Entry*, AstRawStringComparer> - RegularImportMap; + using ModuleRequestMap = + ZoneMap<const AstRawString*, ModuleRequest, AstRawStringComparer>; + using RegularExportMap = + ZoneMultimap<const AstRawString*, Entry*, AstRawStringComparer>; + using RegularImportMap = + ZoneMap<const AstRawString*, Entry*, AstRawStringComparer>; // Module requests. const ModuleRequestMap& module_requests() const { return module_requests_; } diff --git a/deps/v8/src/ast/prettyprinter.cc b/deps/v8/src/ast/prettyprinter.cc index c7f6e3d9f0..eca091d61f 100644 --- a/deps/v8/src/ast/prettyprinter.cc +++ b/deps/v8/src/ast/prettyprinter.cc @@ -9,10 +9,10 @@ #include "src/ast/ast-value-factory.h" #include "src/ast/scopes.h" #include "src/base/platform/platform.h" -#include "src/globals.h" -#include "src/objects-inl.h" -#include "src/string-builder-inl.h" -#include "src/vector.h" +#include "src/common/globals.h" +#include "src/objects/objects-inl.h" +#include "src/strings/string-builder-inl.h" +#include "src/utils/vector.h" namespace v8 { namespace internal { @@ -756,7 +756,7 @@ void AstPrinter::PrintLiteralWithModeIndented(const char* info, Variable* var, reinterpret_cast<void*>(var), VariableMode2String(var->mode()), var->maybe_assigned() == kMaybeAssigned ? "true" : "false"); SNPrintF(buf + pos, ")"); - PrintLiteralIndented(buf.start(), value, true); + PrintLiteralIndented(buf.begin(), value, true); } } @@ -1054,12 +1054,19 @@ void AstPrinter::VisitClassLiteral(ClassLiteral* node) { if (node->extends() != nullptr) { PrintIndentedVisit("EXTENDS", node->extends()); } + Scope* outer = node->constructor()->scope()->outer_scope(); + if (outer->is_class_scope()) { + Variable* brand = outer->AsClassScope()->brand(); + if (brand != nullptr) { + PrintLiteralWithModeIndented("BRAND", brand, brand->raw_name()); + } + } if (node->static_fields_initializer() != nullptr) { PrintIndentedVisit("STATIC FIELDS INITIALIZER", node->static_fields_initializer()); } if (node->instance_members_initializer_function() != nullptr) { - PrintIndentedVisit("INSTANCE ELEMENTS INITIALIZER", + PrintIndentedVisit("INSTANCE MEMBERS INITIALIZER", node->instance_members_initializer_function()); } PrintClassProperties(node->properties()); @@ -1067,7 +1074,7 @@ void AstPrinter::VisitClassLiteral(ClassLiteral* node) { void AstPrinter::VisitInitializeClassMembersStatement( InitializeClassMembersStatement* node) { - IndentedScope indent(this, "INITIALIZE CLASS ELEMENTS", node->position()); + IndentedScope indent(this, "INITIALIZE CLASS MEMBERS", node->position()); PrintClassProperties(node->fields()); } @@ -1093,7 +1100,7 @@ void AstPrinter::PrintClassProperties( EmbeddedVector<char, 128> buf; SNPrintF(buf, "PROPERTY%s%s - %s", property->is_static() ? " - STATIC" : "", property->is_private() ? " - PRIVATE" : " - PUBLIC", prop_kind); - IndentedScope prop(this, buf.start()); + IndentedScope prop(this, buf.begin()); PrintIndentedVisit("KEY", properties->at(i)->key()); PrintIndentedVisit("VALUE", properties->at(i)->value()); } @@ -1137,7 +1144,7 @@ void AstPrinter::VisitRegExpLiteral(RegExpLiteral* node) { if (node->flags() & RegExp::kSticky) buf[i++] = 'y'; buf[i] = '\0'; PrintIndented("FLAGS "); - Print("%s", buf.start()); + Print("%s", buf.begin()); Print("\n"); } @@ -1177,7 +1184,7 @@ void AstPrinter::PrintObjectProperties( } EmbeddedVector<char, 128> buf; SNPrintF(buf, "PROPERTY - %s", prop_kind); - IndentedScope prop(this, buf.start()); + IndentedScope prop(this, buf.begin()); PrintIndentedVisit("KEY", properties->at(i)->key()); PrintIndentedVisit("VALUE", properties->at(i)->value()); } @@ -1201,7 +1208,7 @@ void AstPrinter::VisitVariableProxy(VariableProxy* node) { if (!node->is_resolved()) { SNPrintF(buf + pos, " unresolved"); - PrintLiteralWithModeIndented(buf.start(), nullptr, node->raw_name()); + PrintLiteralWithModeIndented(buf.begin(), nullptr, node->raw_name()); } else { Variable* var = node->var(); switch (var->location()) { @@ -1224,7 +1231,7 @@ void AstPrinter::VisitVariableProxy(VariableProxy* node) { SNPrintF(buf + pos, " module"); break; } - PrintLiteralWithModeIndented(buf.start(), var, node->raw_name()); + PrintLiteralWithModeIndented(buf.begin(), var, node->raw_name()); } } @@ -1242,21 +1249,21 @@ void AstPrinter::VisitCompoundAssignment(CompoundAssignment* node) { void AstPrinter::VisitYield(Yield* node) { EmbeddedVector<char, 128> buf; SNPrintF(buf, "YIELD"); - IndentedScope indent(this, buf.start(), node->position()); + IndentedScope indent(this, buf.begin(), node->position()); Visit(node->expression()); } void AstPrinter::VisitYieldStar(YieldStar* node) { EmbeddedVector<char, 128> buf; SNPrintF(buf, "YIELD_STAR"); - IndentedScope indent(this, buf.start(), node->position()); + IndentedScope indent(this, buf.begin(), node->position()); Visit(node->expression()); } void AstPrinter::VisitAwait(Await* node) { EmbeddedVector<char, 128> buf; SNPrintF(buf, "AWAIT"); - IndentedScope indent(this, buf.start(), node->position()); + IndentedScope indent(this, buf.begin(), node->position()); Visit(node->expression()); } @@ -1268,7 +1275,7 @@ void AstPrinter::VisitThrow(Throw* node) { void AstPrinter::VisitProperty(Property* node) { EmbeddedVector<char, 128> buf; SNPrintF(buf, "PROPERTY"); - IndentedScope indent(this, buf.start(), node->position()); + IndentedScope indent(this, buf.begin(), node->position()); Visit(node->obj()); AssignType property_kind = Property::GetAssignType(node); @@ -1285,7 +1292,7 @@ void AstPrinter::VisitProperty(Property* node) { void AstPrinter::VisitResolvedProperty(ResolvedProperty* node) { EmbeddedVector<char, 128> buf; SNPrintF(buf, "RESOLVED-PROPERTY"); - IndentedScope indent(this, buf.start(), node->position()); + IndentedScope indent(this, buf.begin(), node->position()); PrintIndentedVisit("RECEIVER", node->object()); PrintIndentedVisit("PROPERTY", node->property()); @@ -1294,7 +1301,7 @@ void AstPrinter::VisitResolvedProperty(ResolvedProperty* node) { void AstPrinter::VisitCall(Call* node) { EmbeddedVector<char, 128> buf; SNPrintF(buf, "CALL"); - IndentedScope indent(this, buf.start()); + IndentedScope indent(this, buf.begin()); Visit(node->expression()); PrintArguments(node->arguments()); @@ -1312,7 +1319,7 @@ void AstPrinter::VisitCallRuntime(CallRuntime* node) { EmbeddedVector<char, 128> buf; SNPrintF(buf, "CALL RUNTIME %s%s", node->debug_name(), node->is_jsruntime() ? " (JS function)" : ""); - IndentedScope indent(this, buf.start(), node->position()); + IndentedScope indent(this, buf.begin(), node->position()); PrintArguments(node->arguments()); } @@ -1327,7 +1334,7 @@ void AstPrinter::VisitCountOperation(CountOperation* node) { EmbeddedVector<char, 128> buf; SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), Token::Name(node->op())); - IndentedScope indent(this, buf.start(), node->position()); + IndentedScope indent(this, buf.begin(), node->position()); Visit(node->expression()); } diff --git a/deps/v8/src/ast/prettyprinter.h b/deps/v8/src/ast/prettyprinter.h index e1efdbfb88..cceb5fc269 100644 --- a/deps/v8/src/ast/prettyprinter.h +++ b/deps/v8/src/ast/prettyprinter.h @@ -5,10 +5,10 @@ #ifndef V8_AST_PRETTYPRINTER_H_ #define V8_AST_PRETTYPRINTER_H_ -#include "src/allocation.h" #include "src/ast/ast.h" #include "src/base/compiler-specific.h" -#include "src/function-kind.h" +#include "src/utils/allocation.h" +#include "src/objects/function-kind.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/ast/scopes.cc b/deps/v8/src/ast/scopes.cc index c3950af7ab..e45303c64b 100644 --- a/deps/v8/src/ast/scopes.cc +++ b/deps/v8/src/ast/scopes.cc @@ -6,14 +6,14 @@ #include <set> -#include "src/accessors.h" #include "src/ast/ast.h" #include "src/base/optional.h" -#include "src/bootstrapper.h" -#include "src/counters.h" -#include "src/message-template.h" -#include "src/objects-inl.h" +#include "src/builtins/accessors.h" +#include "src/execution/message-template.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/parsing/parse-info.h" #include "src/parsing/parser.h" @@ -145,9 +145,16 @@ ClassScope::ClassScope(Zone* zone, Scope* outer_scope) set_language_mode(LanguageMode::kStrict); } -ClassScope::ClassScope(Zone* zone, Handle<ScopeInfo> scope_info) +ClassScope::ClassScope(Zone* zone, AstValueFactory* ast_value_factory, + Handle<ScopeInfo> scope_info) : Scope(zone, CLASS_SCOPE, scope_info) { set_language_mode(LanguageMode::kStrict); + if (scope_info->HasClassBrand()) { + Variable* brand = + LookupInScopeInfo(ast_value_factory->dot_brand_string(), this); + DCHECK_NOT_NULL(brand); + EnsureRareData()->brand = brand; + } } Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) @@ -303,8 +310,8 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, Scope* innermost_scope = nullptr; Scope* outer_scope = nullptr; while (!scope_info.is_null()) { - if (scope_info->scope_type() == WITH_SCOPE) { - if (scope_info->IsDebugEvaluateScope()) { + 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->set_is_debug_evaluate_scope(); @@ -314,45 +321,46 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, new (zone) Scope(zone, WITH_SCOPE, handle(scope_info, isolate)); } - } else if (scope_info->scope_type() == SCRIPT_SCOPE) { + } else if (scope_info.scope_type() == SCRIPT_SCOPE) { // If we reach a script scope, it's the outermost scope. Install the // scope info of this script context onto the existing script scope to // avoid nesting script scopes. if (deserialization_mode == DeserializationMode::kIncludingVariables) { script_scope->SetScriptScopeInfo(handle(scope_info, isolate)); } - DCHECK(!scope_info->HasOuterScopeInfo()); + DCHECK(!scope_info.HasOuterScopeInfo()); break; - } else if (scope_info->scope_type() == FUNCTION_SCOPE) { + } else if (scope_info.scope_type() == FUNCTION_SCOPE) { outer_scope = new (zone) DeclarationScope(zone, FUNCTION_SCOPE, handle(scope_info, isolate)); - if (scope_info->IsAsmModule()) { + if (scope_info.IsAsmModule()) { outer_scope->AsDeclarationScope()->set_is_asm_module(); } - } else if (scope_info->scope_type() == EVAL_SCOPE) { + } else if (scope_info.scope_type() == EVAL_SCOPE) { outer_scope = new (zone) DeclarationScope(zone, EVAL_SCOPE, handle(scope_info, isolate)); - } else if (scope_info->scope_type() == CLASS_SCOPE) { - outer_scope = new (zone) ClassScope(zone, handle(scope_info, isolate)); - } else if (scope_info->scope_type() == BLOCK_SCOPE) { - if (scope_info->is_declaration_scope()) { + } else if (scope_info.scope_type() == CLASS_SCOPE) { + outer_scope = new (zone) + ClassScope(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)); } else { outer_scope = new (zone) Scope(zone, BLOCK_SCOPE, handle(scope_info, isolate)); } - } else if (scope_info->scope_type() == MODULE_SCOPE) { + } else if (scope_info.scope_type() == MODULE_SCOPE) { outer_scope = new (zone) ModuleScope(isolate, handle(scope_info, isolate), ast_value_factory); } else { - DCHECK_EQ(scope_info->scope_type(), CATCH_SCOPE); - DCHECK_EQ(scope_info->ContextLocalCount(), 1); - DCHECK_EQ(scope_info->ContextLocalMode(0), VariableMode::kVar); - DCHECK_EQ(scope_info->ContextLocalInitFlag(0), kCreatedInitialized); - String name = scope_info->ContextLocalName(0); + DCHECK_EQ(scope_info.scope_type(), CATCH_SCOPE); + DCHECK_EQ(scope_info.ContextLocalCount(), 1); + DCHECK_EQ(scope_info.ContextLocalMode(0), VariableMode::kVar); + DCHECK_EQ(scope_info.ContextLocalInitFlag(0), kCreatedInitialized); + String name = scope_info.ContextLocalName(0); MaybeAssignedFlag maybe_assigned = - scope_info->ContextLocalMaybeAssignedFlag(0); + scope_info.ContextLocalMaybeAssignedFlag(0); outer_scope = new (zone) Scope(zone, ast_value_factory->GetString(handle(name, isolate)), maybe_assigned, handle(scope_info, isolate)); @@ -365,8 +373,8 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, } current_scope = outer_scope; if (innermost_scope == nullptr) innermost_scope = current_scope; - scope_info = scope_info->HasOuterScopeInfo() ? scope_info->OuterScopeInfo() - : ScopeInfo(); + scope_info = scope_info.HasOuterScopeInfo() ? scope_info.OuterScopeInfo() + : ScopeInfo(); } if (deserialization_mode == DeserializationMode::kIncludingVariables && @@ -1710,6 +1718,11 @@ void Scope::Print(int n) { if (class_scope->rare_data_ != nullptr) { PrintMap(n1, "// private name vars:\n", &(class_scope->rare_data_->private_name_map), true, function); + Variable* brand = class_scope->brand(); + if (brand != nullptr) { + Indent(n1, "// brand var:\n"); + PrintVar(n1, brand); + } } } @@ -2512,5 +2525,21 @@ VariableProxy* ClassScope::ResolvePrivateNamesPartially() { return nullptr; } +Variable* ClassScope::DeclareBrandVariable(AstValueFactory* ast_value_factory, + int class_token_pos) { + DCHECK_IMPLIES(rare_data_ != nullptr, rare_data_->brand == nullptr); + bool was_added; + Variable* brand = Declare(zone(), ast_value_factory->dot_brand_string(), + VariableMode::kConst, NORMAL_VARIABLE, + InitializationFlag::kNeedsInitialization, + MaybeAssignedFlag::kMaybeAssigned, &was_added); + DCHECK(was_added); + brand->ForceContextAllocation(); + brand->set_is_used(); + EnsureRareData()->brand = brand; + brand->set_initializer_position(class_token_pos); + return brand; +} + } // namespace internal } // namespace v8 diff --git a/deps/v8/src/ast/scopes.h b/deps/v8/src/ast/scopes.h index 8d64fbf2ee..1feaad2a90 100644 --- a/deps/v8/src/ast/scopes.h +++ b/deps/v8/src/ast/scopes.h @@ -9,10 +9,10 @@ #include "src/base/compiler-specific.h" #include "src/base/hashmap.h" #include "src/base/threaded-list.h" -#include "src/function-kind.h" -#include "src/globals.h" -#include "src/objects.h" -#include "src/pointer-with-payload.h" +#include "src/common/globals.h" +#include "src/objects/function-kind.h" +#include "src/objects/objects.h" +#include "src/utils/pointer-with-payload.h" #include "src/zone/zone.h" namespace v8 { @@ -30,8 +30,8 @@ class Statement; class StringSet; class VariableProxy; -typedef base::ThreadedList<VariableProxy, VariableProxy::UnresolvedNext> - UnresolvedList; +using UnresolvedList = + base::ThreadedList<VariableProxy, VariableProxy::UnresolvedNext>; // A hash map to support fast variable declaration and lookup. class VariableMap : public ZoneHashMap { @@ -1169,7 +1169,8 @@ class V8_EXPORT_PRIVATE ClassScope : public Scope { public: ClassScope(Zone* zone, Scope* outer_scope); // Deserialization. - ClassScope(Zone* zone, Handle<ScopeInfo> scope_info); + ClassScope(Zone* zone, AstValueFactory* ast_value_factory, + Handle<ScopeInfo> scope_info); // Declare a private name in the private name map and add it to the // local variables of this scope. @@ -1205,6 +1206,11 @@ class V8_EXPORT_PRIVATE ClassScope : public Scope { // and the current tail. void MigrateUnresolvedPrivateNameTail(AstNodeFactory* ast_node_factory, UnresolvedList::Iterator tail); + Variable* DeclareBrandVariable(AstValueFactory* ast_value_factory, + int class_token_pos); + Variable* brand() { + return rare_data_ == nullptr ? nullptr : rare_data_->brand; + } private: friend class Scope; @@ -1222,6 +1228,7 @@ class V8_EXPORT_PRIVATE ClassScope : public Scope { explicit RareData(Zone* zone) : private_name_map(zone) {} UnresolvedList unresolved_private_names; VariableMap private_name_map; + Variable* brand = nullptr; }; V8_INLINE RareData* EnsureRareData() { diff --git a/deps/v8/src/ast/variables.cc b/deps/v8/src/ast/variables.cc index addcf8db2b..26f037ea68 100644 --- a/deps/v8/src/ast/variables.cc +++ b/deps/v8/src/ast/variables.cc @@ -5,8 +5,8 @@ #include "src/ast/variables.h" #include "src/ast/scopes.h" -#include "src/globals.h" -#include "src/objects-inl.h" +#include "src/common/globals.h" +#include "src/objects/objects-inl.h" namespace v8 { namespace internal { diff --git a/deps/v8/src/ast/variables.h b/deps/v8/src/ast/variables.h index 6dbb9dbac4..df40fee754 100644 --- a/deps/v8/src/ast/variables.h +++ b/deps/v8/src/ast/variables.h @@ -7,7 +7,7 @@ #include "src/ast/ast-value-factory.h" #include "src/base/threaded-list.h" -#include "src/globals.h" +#include "src/common/globals.h" #include "src/zone/zone.h" namespace v8 { @@ -193,7 +193,7 @@ class Variable final : public ZoneObject { : kNeedsInitialization; } - typedef base::ThreadedList<Variable> List; + using List = base::ThreadedList<Variable>; private: Scope* scope_; |