Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 "src/base/platform/platform.h" |
| 9 | #include "src/base/platform/semaphore.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | #include "src/base/smart-pointers.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/compiler.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 12 | #include "src/parsing/parser.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 17 | // Internal representation of v8::ScriptCompiler::StreamedSource. Contains all |
| 18 | // data which needs to be transmitted between threads for background parsing, |
| 19 | // finalizing it on the main thread, and compiling on the main thread. |
| 20 | struct StreamedSource { |
| 21 | StreamedSource(ScriptCompiler::ExternalSourceStream* source_stream, |
| 22 | ScriptCompiler::StreamedSource::Encoding encoding) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 23 | : source_stream(source_stream), encoding(encoding) {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | |
| 25 | // Internal implementation of v8::ScriptCompiler::StreamedSource. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 26 | base::SmartPointer<ScriptCompiler::ExternalSourceStream> source_stream; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | ScriptCompiler::StreamedSource::Encoding encoding; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | base::SmartPointer<ScriptCompiler::CachedData> cached_data; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 29 | |
| 30 | // Data needed for parsing, and data needed to to be passed between thread |
| 31 | // between parsing and compilation. These need to be initialized before the |
| 32 | // compilation starts. |
| 33 | UnicodeCache unicode_cache; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 34 | base::SmartPointer<Zone> zone; |
| 35 | base::SmartPointer<ParseInfo> info; |
| 36 | base::SmartPointer<Parser> parser; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | // Prevent copying. Not implemented. |
| 40 | StreamedSource(const StreamedSource&); |
| 41 | StreamedSource& operator=(const StreamedSource&); |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | class BackgroundParsingTask : public ScriptCompiler::ScriptStreamingTask { |
| 46 | public: |
| 47 | BackgroundParsingTask(StreamedSource* source, |
| 48 | ScriptCompiler::CompileOptions options, int stack_size, |
| 49 | Isolate* isolate); |
| 50 | |
| 51 | virtual void Run(); |
| 52 | |
| 53 | private: |
| 54 | StreamedSource* source_; // Not owned. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 55 | int stack_size_; |
| 56 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 57 | } // namespace internal |
| 58 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | |
| 60 | #endif // V8_BACKGROUND_PARSING_TASK_H_ |