OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" | 5 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
6 | 6 |
7 #include "src/global-handles.h" | 7 #include "src/global-handles.h" |
8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
10 #include "src/parsing/parser.h" | 10 #include "src/parsing/parser.h" |
| 11 #include "src/parsing/scanner-character-streams.h" |
11 #include "src/unicode-cache.h" | 12 #include "src/unicode-cache.h" |
12 #include "src/zone.h" | 13 #include "src/zone.h" |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 | 17 |
17 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, | 18 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, |
18 Handle<JSFunction> function) | 19 Handle<JSFunction> function) |
19 : isolate_(isolate), | 20 : isolate_(isolate), |
20 function_(Handle<JSFunction>::cast( | 21 function_(Handle<JSFunction>::cast( |
21 isolate_->global_handles()->Create(*function))) {} | 22 isolate_->global_handles()->Create(*function))), |
| 23 can_parse_on_background_thread_(false) {} |
22 | 24 |
23 CompilerDispatcherJob::~CompilerDispatcherJob() { | 25 CompilerDispatcherJob::~CompilerDispatcherJob() { |
24 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 26 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
25 i::GlobalHandles::Destroy(Handle<Object>::cast(function_).location()); | 27 i::GlobalHandles::Destroy(Handle<Object>::cast(function_).location()); |
26 } | 28 } |
27 | 29 |
28 void CompilerDispatcherJob::PrepareToParseOnMainThread() { | 30 void CompilerDispatcherJob::PrepareToParseOnMainThread() { |
29 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 31 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
30 DCHECK(status_ == CompileJobStatus::kInitial); | 32 DCHECK(status_ == CompileJobStatus::kInitial); |
| 33 HandleScope scope(isolate_); |
31 unicode_cache_.reset(new UnicodeCache()); | 34 unicode_cache_.reset(new UnicodeCache()); |
32 zone_.reset(new Zone(isolate_->allocator())); | 35 zone_.reset(new Zone(isolate_->allocator())); |
| 36 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); |
| 37 Handle<Script> script(Script::cast(shared->script()), isolate_); |
| 38 Handle<String> source(String::cast(script->source()), isolate_); |
| 39 if (source->IsExternalTwoByteString()) { |
| 40 can_parse_on_background_thread_ = true; |
| 41 character_stream_.reset(new ExternalTwoByteStringUtf16CharacterStream( |
| 42 Handle<ExternalTwoByteString>::cast(source), shared->start_position(), |
| 43 shared->end_position())); |
| 44 } else if (source->IsExternalOneByteString()) { |
| 45 can_parse_on_background_thread_ = true; |
| 46 character_stream_.reset(new ExternalOneByteStringUtf16CharacterStream( |
| 47 Handle<ExternalOneByteString>::cast(source), shared->start_position(), |
| 48 shared->end_position())); |
| 49 } else { |
| 50 can_parse_on_background_thread_ = false; |
| 51 character_stream_.reset(new GenericStringUtf16CharacterStream( |
| 52 source, shared->start_position(), shared->end_position())); |
| 53 } |
33 parse_info_.reset(new ParseInfo(zone_.get())); | 54 parse_info_.reset(new ParseInfo(zone_.get())); |
34 parse_info_->set_isolate(isolate_); | 55 parse_info_->set_isolate(isolate_); |
35 // TODO(jochen): We need to hook up a fake source stream here. | 56 parse_info_->set_character_stream(character_stream_.get()); |
36 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); | 57 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); |
37 parse_info_->set_unicode_cache(unicode_cache_.get()); | 58 parse_info_->set_unicode_cache(unicode_cache_.get()); |
38 status_ = CompileJobStatus::kReadyToParse; | 59 status_ = CompileJobStatus::kReadyToParse; |
39 } | 60 } |
40 | 61 |
41 } // namespace internal | 62 } // namespace internal |
42 } // namespace v8 | 63 } // namespace v8 |
OLD | NEW |