• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef V8_BACKGROUND_PARSING_TASK_H_
6 #define V8_BACKGROUND_PARSING_TASK_H_
7 
8 #include <memory>
9 
10 #include "include/v8.h"
11 #include "src/base/platform/platform.h"
12 #include "src/base/platform/semaphore.h"
13 #include "src/parsing/parse-info.h"
14 #include "src/unicode-cache.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 class Parser;
20 class ScriptData;
21 
22 // Internal representation of v8::ScriptCompiler::StreamedSource. Contains all
23 // data which needs to be transmitted between threads for background parsing,
24 // finalizing it on the main thread, and compiling on the main thread.
25 struct StreamedSource {
StreamedSourceStreamedSource26   StreamedSource(ScriptCompiler::ExternalSourceStream* source_stream,
27                  ScriptCompiler::StreamedSource::Encoding encoding)
28       : source_stream(source_stream), encoding(encoding) {}
29 
30   void Release();
31 
32   // Internal implementation of v8::ScriptCompiler::StreamedSource.
33   std::unique_ptr<ScriptCompiler::ExternalSourceStream> source_stream;
34   ScriptCompiler::StreamedSource::Encoding encoding;
35   std::unique_ptr<ScriptCompiler::CachedData> cached_data;
36 
37   // Data needed for parsing, and data needed to to be passed between thread
38   // between parsing and compilation. These need to be initialized before the
39   // compilation starts.
40   UnicodeCache unicode_cache;
41   std::unique_ptr<ParseInfo> info;
42   std::unique_ptr<Parser> parser;
43 
44   // Prevent copying.
45   StreamedSource(const StreamedSource&) = delete;
46   StreamedSource& operator=(const StreamedSource&) = delete;
47 };
48 
49 
50 class BackgroundParsingTask : public ScriptCompiler::ScriptStreamingTask {
51  public:
52   BackgroundParsingTask(StreamedSource* source,
53                         ScriptCompiler::CompileOptions options, int stack_size,
54                         Isolate* isolate);
55 
56   virtual void Run();
57 
58  private:
59   StreamedSource* source_;  // Not owned.
60   int stack_size_;
61   ScriptData* script_data_;
62 };
63 }  // namespace internal
64 }  // namespace v8
65 
66 #endif  // V8_BACKGROUND_PARSING_TASK_H_
67