summaryrefslogtreecommitdiff
path: root/deps/v8/src/background-parsing-task.h
blob: 1bf9d7412127901c7d8706d9fdecf5213cfef372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_BACKGROUND_PARSING_TASK_H_
#define V8_BACKGROUND_PARSING_TASK_H_

#include <memory>

#include "src/base/platform/platform.h"
#include "src/base/platform/semaphore.h"
#include "src/compiler.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/parser.h"

namespace v8 {
namespace internal {

class ScriptData;

// Internal representation of v8::ScriptCompiler::StreamedSource. Contains all
// data which needs to be transmitted between threads for background parsing,
// finalizing it on the main thread, and compiling on the main thread.
struct StreamedSource {
  StreamedSource(ScriptCompiler::ExternalSourceStream* source_stream,
                 ScriptCompiler::StreamedSource::Encoding encoding)
      : source_stream(source_stream), encoding(encoding) {}

  // Internal implementation of v8::ScriptCompiler::StreamedSource.
  std::unique_ptr<ScriptCompiler::ExternalSourceStream> source_stream;
  ScriptCompiler::StreamedSource::Encoding encoding;
  std::unique_ptr<ScriptCompiler::CachedData> cached_data;

  // Data needed for parsing, and data needed to to be passed between thread
  // between parsing and compilation. These need to be initialized before the
  // compilation starts.
  UnicodeCache unicode_cache;
  std::unique_ptr<Zone> zone;
  std::unique_ptr<ParseInfo> info;
  std::unique_ptr<Parser> parser;

 private:
  // Prevent copying. Not implemented.
  StreamedSource(const StreamedSource&);
  StreamedSource& operator=(const StreamedSource&);
};


class BackgroundParsingTask : public ScriptCompiler::ScriptStreamingTask {
 public:
  BackgroundParsingTask(StreamedSource* source,
                        ScriptCompiler::CompileOptions options, int stack_size,
                        Isolate* isolate);

  virtual void Run();

 private:
  StreamedSource* source_;  // Not owned.
  int stack_size_;
  ScriptData* script_data_;
};
}  // namespace internal
}  // namespace v8

#endif  // V8_BACKGROUND_PARSING_TASK_H_