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

          Line data    Source code
       1             : // Copyright 2014 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/background-parsing-task.h"
       6             : 
       7             : #include "src/objects-inl.h"
       8             : #include "src/parsing/parser.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : 
      13         126 : void StreamedSource::Release() {
      14             :   parser.reset();
      15             :   info.reset();
      16         126 : }
      17             : 
      18         132 : BackgroundParsingTask::BackgroundParsingTask(
      19             :     StreamedSource* source, ScriptCompiler::CompileOptions options,
      20         132 :     int stack_size, Isolate* isolate)
      21         132 :     : source_(source), stack_size_(stack_size), script_data_(nullptr) {
      22             :   // We don't set the context to the CompilationInfo yet, because the background
      23             :   // thread cannot do anything with it anyway. We set it just before compilation
      24             :   // on the foreground thread.
      25             :   DCHECK(options == ScriptCompiler::kProduceParserCache ||
      26             :          options == ScriptCompiler::kProduceCodeCache ||
      27             :          options == ScriptCompiler::kNoCompileOptions);
      28             : 
      29             :   // Prepare the data for the internalization phase and compilation phase, which
      30             :   // will happen in the main thread after parsing.
      31         132 :   ParseInfo* info = new ParseInfo(isolate->allocator());
      32         132 :   info->InitFromIsolate(isolate);
      33             :   info->set_toplevel();
      34             :   source->info.reset(info);
      35             :   info->set_source_stream(source->source_stream.get());
      36         132 :   info->set_source_stream_encoding(source->encoding);
      37         132 :   info->set_unicode_cache(&source_->unicode_cache);
      38             :   info->set_compile_options(options);
      39             :   info->set_allow_lazy_parsing();
      40             : 
      41         132 :   source_->info->set_cached_data(&script_data_);
      42             :   // Parser needs to stay alive for finalizing the parsing on the main
      43             :   // thread.
      44         264 :   source_->parser.reset(new Parser(source_->info.get()));
      45             :   source_->parser->DeserializeScopeChain(source_->info.get(),
      46         264 :                                          MaybeHandle<ScopeInfo>());
      47         132 : }
      48             : 
      49             : 
      50         132 : void BackgroundParsingTask::Run() {
      51             :   DisallowHeapAllocation no_allocation;
      52             :   DisallowHandleAllocation no_handles;
      53             :   DisallowHandleDereference no_deref;
      54             : 
      55             :   // Reset the stack limit of the parser to reflect correctly that we're on a
      56             :   // background thread.
      57         132 :   uintptr_t stack_limit = GetCurrentStackPosition() - stack_size_ * KB;
      58         132 :   source_->parser->set_stack_limit(stack_limit);
      59             : 
      60         132 :   source_->parser->ParseOnBackground(source_->info.get());
      61             : 
      62         132 :   if (script_data_ != nullptr) {
      63             :     source_->cached_data.reset(new ScriptCompiler::CachedData(
      64             :         script_data_->data(), script_data_->length(),
      65           6 :         ScriptCompiler::CachedData::BufferOwned));
      66           6 :     script_data_->ReleaseDataOwnership();
      67           6 :     delete script_data_;
      68           6 :     script_data_ = nullptr;
      69             :   }
      70         132 : }
      71             : }  // namespace internal
      72             : }  // namespace v8

Generated by: LCOV version 1.10