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<Zone> zone;
42   std::unique_ptr<ParseInfo> info;
43   std::unique_ptr<Parser> parser;
44 
45   // Prevent copying.
46   StreamedSource(const StreamedSource&) = delete;
47   StreamedSource& operator=(const StreamedSource&) = delete;
48 };
49 
50 
51 class BackgroundParsingTask : public ScriptCompiler::ScriptStreamingTask {
52  public:
53   BackgroundParsingTask(StreamedSource* source,
54                         ScriptCompiler::CompileOptions options, int stack_size,
55                         Isolate* isolate);
56 
57   virtual void Run();
58 
59  private:
60   StreamedSource* source_;  // Not owned.
61   int stack_size_;
62   ScriptData* script_data_;
63 };
64 }  // namespace internal
65 }  // namespace v8
66 
67 #endif  // V8_BACKGROUND_PARSING_TASK_H_
68