LCOV - code coverage report
Current view: top level - src/parsing - func-name-inferrer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 36 36 100.0 %
Date: 2019-04-18 Functions: 8 8 100.0 %

          Line data    Source code
       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             : 
       5             : #include "src/parsing/func-name-inferrer.h"
       6             : 
       7             : #include "src/ast/ast-value-factory.h"
       8             : #include "src/ast/ast.h"
       9             : #include "src/objects-inl.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : 
      14     2468833 : FuncNameInferrer::FuncNameInferrer(AstValueFactory* ast_value_factory)
      15     4937666 :     : ast_value_factory_(ast_value_factory) {}
      16             : 
      17     1709481 : void FuncNameInferrer::PushEnclosingName(const AstRawString* name) {
      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     1709481 :   if (!name->IsEmpty() && unibrow::Uppercase::Is(name->FirstCharacter())) {
      22      260223 :     names_stack_.push_back(Name(name, kEnclosingConstructorName));
      23             :   }
      24     1709505 : }
      25             : 
      26             : 
      27    10974994 : void FuncNameInferrer::PushLiteralName(const AstRawString* name) {
      28    10974994 :   if (IsOpen() && name != ast_value_factory_->prototype_string()) {
      29    20901308 :     names_stack_.push_back(Name(name, kLiteralName));
      30             :   }
      31    10975000 : }
      32             : 
      33             : 
      34    31001709 : void FuncNameInferrer::PushVariableName(const AstRawString* name) {
      35    31001709 :   if (IsOpen() && name != ast_value_factory_->dot_result_string()) {
      36    62003424 :     names_stack_.push_back(Name(name, kVariableName));
      37             :   }
      38    31001595 : }
      39             : 
      40        6539 : void FuncNameInferrer::RemoveAsyncKeywordFromEnd() {
      41        6539 :   if (IsOpen()) {
      42        6539 :     CHECK_GT(names_stack_.size(), 0);
      43        6539 :     CHECK(names_stack_.back().name()->IsOneByteEqualTo("async"));
      44             :     names_stack_.pop_back();
      45             :   }
      46        6539 : }
      47             : 
      48      463557 : const AstConsString* FuncNameInferrer::MakeNameFromStack() {
      49      463557 :   if (names_stack_.size() == 0) {
      50        9833 :     return ast_value_factory_->empty_cons_string();
      51             :   }
      52      453724 :   AstConsString* result = ast_value_factory_->NewConsString();
      53             :   auto it = names_stack_.begin();
      54     1084579 :   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      959970 :     if (it != names_stack_.end() && current->type() == kVariableName &&
      59             :         it->type() == kVariableName) {
      60             :       continue;
      61             :     }
      62             :     // Add name. Separate names with ".".
      63      626252 :     Zone* zone = ast_value_factory_->zone();
      64      626252 :     if (!result->IsEmpty()) {
      65      172534 :       result->AddString(zone, ast_value_factory_->dot_string());
      66             :     }
      67      626262 :     result->AddString(zone, current->name());
      68             :   }
      69             :   return result;
      70             : }
      71             : 
      72      463558 : void FuncNameInferrer::InferFunctionsNames() {
      73      463558 :   const AstConsString* func_name = MakeNameFromStack();
      74      931673 :   for (FunctionLiteral* func : funcs_to_infer_) {
      75      468096 :     func->set_raw_inferred_name(func_name);
      76             :   }
      77      463577 :   funcs_to_infer_.resize(0);
      78      463559 : }
      79             : 
      80             : 
      81             : }  // namespace internal
      82      122036 : }  // namespace v8

Generated by: LCOV version 1.10