LCOV - code coverage report
Current view: top level - src/parsing - parsing.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 30 30 100.0 %
Date: 2017-10-20 Functions: 3 3 100.0 %

          Line data    Source code
       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             : 
       5             : #include "src/parsing/parsing.h"
       6             : 
       7             : #include <memory>
       8             : 
       9             : #include "src/ast/ast.h"
      10             : #include "src/objects-inl.h"
      11             : #include "src/parsing/parse-info.h"
      12             : #include "src/parsing/parser.h"
      13             : #include "src/parsing/scanner-character-streams.h"
      14             : #include "src/vm-state-inl.h"
      15             : 
      16             : namespace v8 {
      17             : namespace internal {
      18             : namespace parsing {
      19             : 
      20     3040701 : bool ParseProgram(ParseInfo* info, Isolate* isolate) {
      21             :   DCHECK(info->is_toplevel());
      22             :   DCHECK_NULL(info->literal());
      23             : 
      24             :   VMState<PARSER> state(isolate);
      25             : 
      26             :   // Create a character stream for the parser.
      27             :   Handle<String> source(String::cast(info->script()->source()));
      28     1678345 :   source = String::Flatten(source);
      29     1678346 :   isolate->counters()->total_parse_size()->Increment(source->length());
      30     1678346 :   std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(source));
      31     3356692 :   info->set_character_stream(std::move(stream));
      32             : 
      33     3356692 :   Parser parser(info);
      34             : 
      35     1362357 :   FunctionLiteral* result = nullptr;
      36             :   // Ok to use Isolate here; this function is only called in the main thread.
      37             :   DCHECK(parser.parsing_on_main_thread_);
      38             : 
      39     1678346 :   parser.SetCachedData(info);
      40     1678346 :   result = parser.ParseProgram(isolate, info);
      41             :   info->set_literal(result);
      42     1678346 :   if (result == nullptr) {
      43      315989 :     parser.ReportErrors(isolate, info->script());
      44             :   } else {
      45     1362357 :     result->scope()->AttachOuterScopeInfo(info, isolate);
      46     1362356 :     info->set_language_mode(info->literal()->language_mode());
      47             :   }
      48     1678345 :   parser.UpdateStatistics(isolate, info->script());
      49     3356692 :   return (result != nullptr);
      50             : }
      51             : 
      52      669523 : bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
      53             :                    Isolate* isolate) {
      54             :   DCHECK(!info->is_toplevel());
      55             :   DCHECK(!shared_info.is_null());
      56             :   DCHECK_NULL(info->literal());
      57             : 
      58             :   // Create a character stream for the parser.
      59             :   Handle<String> source(String::cast(info->script()->source()));
      60      669524 :   source = String::Flatten(source);
      61      669524 :   isolate->counters()->total_parse_size()->Increment(source->length());
      62             :   std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(
      63      669524 :       source, shared_info->start_position(), shared_info->end_position()));
      64     1339048 :   info->set_character_stream(std::move(stream));
      65             : 
      66             :   VMState<PARSER> state(isolate);
      67             : 
      68     1339048 :   Parser parser(info);
      69             : 
      70      668141 :   FunctionLiteral* result = nullptr;
      71             :   // Ok to use Isolate here; this function is only called in the main thread.
      72             :   DCHECK(parser.parsing_on_main_thread_);
      73             : 
      74      669524 :   result = parser.ParseFunction(isolate, info, shared_info);
      75             :   info->set_literal(result);
      76      669524 :   if (result == nullptr) {
      77        1383 :     parser.ReportErrors(isolate, info->script());
      78             :   } else {
      79      668141 :     result->scope()->AttachOuterScopeInfo(info, isolate);
      80             :   }
      81      669524 :   parser.UpdateStatistics(isolate, info->script());
      82     1339048 :   return (result != nullptr);
      83             : }
      84             : 
      85      138899 : bool ParseAny(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
      86             :               Isolate* isolate) {
      87             :   DCHECK(!shared_info.is_null());
      88             :   return info->is_toplevel() ? ParseProgram(info, isolate)
      89      138899 :                              : ParseFunction(info, shared_info, isolate);
      90             : }
      91             : 
      92             : }  // namespace parsing
      93             : }  // namespace internal
      94             : }  // namespace v8

Generated by: LCOV version 1.10