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