v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
ast-function-literal-id-reindexer.cc
Go to the documentation of this file.
1// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include "src/ast/ast.h"
8
9namespace v8 {
10namespace internal {
11
13 int delta)
14 : AstTraversalVisitor(stack_limit), delta_(delta) {}
15
17
19#ifdef DEBUG
20 visited_.clear();
21#endif
24}
25
27 // Make sure we're not already in the visited set.
28 DCHECK(visited_.insert(lit).second);
29
30 AstTraversalVisitor::VisitFunctionLiteral(lit);
32}
33
35 AstTraversalVisitor::VisitCall(expr);
36 if (expr->is_possibly_eval()) {
38 }
39}
40
42 // Manually visit the class literal so that we can change the property walk.
43 // This should be kept in-sync with AstTraversalVisitor::VisitClassLiteral.
44
45 if (expr->extends() != nullptr) {
46 Visit(expr->extends());
47 }
48 Visit(expr->constructor());
49 if (expr->static_initializer() != nullptr) {
51 }
52 if (expr->instance_members_initializer_function() != nullptr) {
54 }
56 expr->private_members();
57 for (int i = 0; i < private_members->length(); ++i) {
58 ClassLiteralProperty* prop = private_members->at(i);
59
60 // Private fields have their key and value present in
61 // instance_members_initializer_function, so they will
62 // already have been visited.
64 CheckVisited(prop->value());
65 } else {
66 Visit(prop->value());
67 }
68 }
70 for (int i = 0; i < props->length(); ++i) {
71 ClassLiteralProperty* prop = props->at(i);
72
73 // Public fields with computed names have their key
74 // and value present in instance_members_initializer_function, so they will
75 // already have been visited.
76 if (prop->is_computed_name() &&
78 if (!prop->key()->IsLiteral()) {
79 CheckVisited(prop->key());
80 }
81 CheckVisited(prop->value());
82 } else {
83 if (!prop->key()->IsLiteral()) {
84 Visit(prop->key());
85 }
86 Visit(prop->value());
87 }
88 }
89}
90
91#ifdef DEBUG
92namespace {
93
94class AstFunctionLiteralIdReindexChecker final
95 : public AstTraversalVisitor<AstFunctionLiteralIdReindexChecker> {
96 public:
97 AstFunctionLiteralIdReindexChecker(size_t stack_limit,
98 const std::set<FunctionLiteral*>* visited)
99 : AstTraversalVisitor(stack_limit), visited_(visited) {}
100
101 void VisitFunctionLiteral(FunctionLiteral* lit) {
102 // TODO(leszeks): It would be nice to print the unvisited function literal
103 // here, but that requires more advanced DCHECK support with formatting.
104 DCHECK(visited_->find(lit) != visited_->end());
105 }
106
107 private:
108 const std::set<FunctionLiteral*>* visited_;
109};
110
111} // namespace
112
113void AstFunctionLiteralIdReindexer::CheckVisited(Expression* expr) {
114 AstFunctionLiteralIdReindexChecker(stack_limit(), &visited_).Visit(expr);
115}
116#endif
117
118} // namespace internal
119} // namespace v8
bool is_possibly_eval() const
Definition ast.h:1771
void adjust_eval_scope_info_index(int delta)
Definition ast.h:1787
ZonePtrList< Property > * public_members() const
Definition ast.h:2709
FunctionLiteral * instance_members_initializer_function() const
Definition ast.h:2726
ZonePtrList< Property > * private_members() const
Definition ast.h:2710
Expression * extends() const
Definition ast.h:2707
FunctionLiteral * static_initializer() const
Definition ast.h:2724
FunctionLiteral * constructor() const
Definition ast.h:2708
int function_literal_id() const
Definition ast.h:2408
void set_function_literal_id(int function_literal_id)
Definition ast.h:2409
Expression * key() const
Definition ast.h:1247
Expression * value() const
Definition ast.h:1248
bool is_computed_name() const
Definition ast.h:1250
V8_INLINE int length() const
Definition zone-list.h:101
T & at(int i) const
Definition zone-list.h:88
std::string pattern
HeapObjectSet *const visited_
#define DCHECK(condition)
Definition logging.h:482