v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
func-name-inferrer.cc
Go to the documentation of this file.
1// Copyright 2011 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
8#include "src/ast/ast.h"
10
11namespace v8 {
12namespace internal {
13
15 : ast_value_factory_(ast_value_factory) {}
16
18 // Enclosing name is a name of a constructor function. To check
19 // that it is really a constructor, we check that it is not empty
20 // and starts with a capital letter.
21 if (!name->IsEmpty() && unibrow::Uppercase::Is(name->FirstCharacter())) {
23 }
24}
25
26
28 if (IsOpen() && name != ast_value_factory_->prototype_string()) {
29 names_stack_.push_back(Name(name, kLiteralName));
30 }
31}
32
33
35 if (IsOpen() && name != ast_value_factory_->dot_result_string()) {
36 names_stack_.push_back(Name(name, kVariableName));
37 }
38}
39
41 if (IsOpen()) {
42 CHECK_GT(names_stack_.size(), 0);
43 CHECK(names_stack_.back().name()->IsOneByteEqualTo("async"));
44 names_stack_.pop_back();
45 }
46}
47
49 if (names_stack_.empty()) {
51 }
53 auto it = names_stack_.begin();
54 while (it != names_stack_.end()) {
55 // Advance the iterator to be able to peek the next value.
56 auto current = it++;
57 // Skip consecutive variable declarations.
58 if (it != names_stack_.end() && current->type() == kVariableName &&
59 it->type() == kVariableName) {
60 continue;
61 }
62 // Add name. Separate names with ".".
64 if (!result->IsEmpty()) {
65 result->AddString(zone, ast_value_factory_->dot_string());
66 }
67 result->AddString(zone, current->name());
68 }
69 return result;
70}
71
73 AstConsString* func_name = MakeNameFromStack();
74 for (FunctionLiteral* func : funcs_to_infer_) {
75 func->set_raw_inferred_name(func_name);
76 }
77 funcs_to_infer_.resize(0);
78}
79
80
81} // namespace internal
82} // namespace v8
AstConsString * empty_cons_string() const
V8_EXPORT_PRIVATE AstConsString * NewConsString()
void PushVariableName(const AstRawString *name)
base::SmallVector< Name, 8 > names_stack_
void PushEnclosingName(const AstRawString *name)
void PushLiteralName(const AstRawString *name)
std::vector< FunctionLiteral * > funcs_to_infer_
FuncNameInferrer(AstValueFactory *ast_value_factory)
const char * name() const
Definition zone.h:185
ZoneVector< RpoNumber > & result
#define CHECK(condition)
Definition logging.h:124
#define CHECK_GT(lhs, rhs)
static bool Is(uchar c)
Definition unicode.cc:433