OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/sys_info.h" |
| 18 #include "base/task_scheduler/task_scheduler.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
18 #include "gin/array_buffer.h" | 20 #include "gin/array_buffer.h" |
19 #include "gin/modules/console.h" | 21 #include "gin/modules/console.h" |
20 #include "gin/modules/module_runner_delegate.h" | 22 #include "gin/modules/module_runner_delegate.h" |
21 #include "gin/public/isolate_holder.h" | 23 #include "gin/public/isolate_holder.h" |
22 #include "gin/try_catch.h" | 24 #include "gin/try_catch.h" |
23 #include "gin/v8_initializer.h" | 25 #include "gin/v8_initializer.h" |
24 | 26 |
25 namespace gin { | 27 namespace gin { |
26 namespace { | 28 namespace { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 int main(int argc, char** argv) { | 68 int main(int argc, char** argv) { |
67 base::AtExitManager at_exit; | 69 base::AtExitManager at_exit; |
68 base::CommandLine::Init(argc, argv); | 70 base::CommandLine::Init(argc, argv); |
69 base::i18n::InitializeICU(); | 71 base::i18n::InitializeICU(); |
70 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 72 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
71 gin::V8Initializer::LoadV8Snapshot(); | 73 gin::V8Initializer::LoadV8Snapshot(); |
72 gin::V8Initializer::LoadV8Natives(); | 74 gin::V8Initializer::LoadV8Natives(); |
73 #endif | 75 #endif |
74 | 76 |
75 base::MessageLoop message_loop; | 77 base::MessageLoop message_loop; |
| 78 base::TaskScheduler::CreateAndSetSimpleTaskScheduler( |
| 79 base::SysInfo::NumberOfProcessors()); |
76 | 80 |
77 // Initialize the base::FeatureList since IsolateHolder can depend on it. | 81 // Initialize the base::FeatureList since IsolateHolder can depend on it. |
78 base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList)); | 82 base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList)); |
79 | 83 |
80 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, | 84 { |
81 gin::IsolateHolder::kStableV8Extras, | 85 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, |
82 gin::ArrayBufferAllocator::SharedInstance()); | 86 gin::IsolateHolder::kStableV8Extras, |
83 gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get()); | 87 gin::ArrayBufferAllocator::SharedInstance()); |
| 88 gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get()); |
84 | 89 |
85 gin::GinShellRunnerDelegate delegate; | 90 gin::GinShellRunnerDelegate delegate; |
86 gin::ShellRunner runner(&delegate, instance.isolate()); | 91 gin::ShellRunner runner(&delegate, instance.isolate()); |
87 | 92 |
88 { | 93 { |
89 gin::Runner::Scope scope(&runner); | 94 gin::Runner::Scope scope(&runner); |
90 runner.GetContextHolder() | 95 runner.GetContextHolder() |
91 ->isolate() | 96 ->isolate() |
92 ->SetCaptureStackTraceForUncaughtExceptions(true); | 97 ->SetCaptureStackTraceForUncaughtExceptions(true); |
| 98 } |
| 99 |
| 100 base::CommandLine::StringVector args = |
| 101 base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 102 for (base::CommandLine::StringVector::const_iterator it = args.begin(); |
| 103 it != args.end(); ++it) { |
| 104 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 105 FROM_HERE, |
| 106 base::Bind(gin::Run, runner.GetWeakPtr(), base::FilePath(*it))); |
| 107 } |
| 108 |
| 109 base::RunLoop().RunUntilIdle(); |
93 } | 110 } |
94 | 111 |
95 base::CommandLine::StringVector args = | 112 // gin::IsolateHolder waits for tasks running in TaskScheduler in its |
96 base::CommandLine::ForCurrentProcess()->GetArgs(); | 113 // destructor and thus must be destroyed before TaskScheduler starts skipping |
97 for (base::CommandLine::StringVector::const_iterator it = args.begin(); | 114 // CONTINUE_ON_SHUTDOWN tasks. |
98 it != args.end(); ++it) { | 115 base::TaskScheduler::GetInstance()->Shutdown(); |
99 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
100 FROM_HERE, | |
101 base::Bind(gin::Run, runner.GetWeakPtr(), base::FilePath(*it))); | |
102 } | |
103 | 116 |
104 base::RunLoop().RunUntilIdle(); | |
105 return 0; | 117 return 0; |
106 } | 118 } |
OLD | NEW |