| Index: gin/shell/gin_prepare_main.cc | 
| diff --git a/gin/shell/gin_prepare_main.cc b/gin/shell/gin_prepare_main.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..8c6c91861a57e762eda15e9a74d2db43b58ceb1e | 
| --- /dev/null | 
| +++ b/gin/shell/gin_prepare_main.cc | 
| @@ -0,0 +1,88 @@ | 
| +// Copyright 2016 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "base/at_exit.h" | 
| +#include "base/bind.h" | 
| +#include "base/command_line.h" | 
| +#include "base/feature_list.h" | 
| +#include "base/files/file_util.h" | 
| +#include "base/location.h" | 
| +#include "base/macros.h" | 
| +#include "base/memory/ptr_util.h" | 
| +#include "base/message_loop/message_loop.h" | 
| +#include "base/run_loop.h" | 
| +#include "base/single_thread_task_runner.h" | 
| +#include "base/task_scheduler/task_scheduler.h" | 
| +#include "base/threading/thread_task_runner_handle.h" | 
| +#include "gin/array_buffer.h" | 
| +#include "gin/modules/console.h" | 
| +#include "gin/modules/module_runner_delegate.h" | 
| +#include "gin/public/isolate_holder.h" | 
| +#include "gin/try_catch.h" | 
| +#include "gin/v8_initializer.h" | 
| +#include "mojo/edk/embedder/embedder.h" | 
| +#include "third_party/WebKit/public/web/SnapshotCreator.h" | 
| +#include "third_party/WebKit/public/web/WebKit.h" | 
| +#include "v8/include/v8.h" | 
| + | 
| +namespace gin { | 
| +namespace { | 
| + | 
| +std::vector<base::FilePath> GetModuleSearchPaths() { | 
| +  std::vector<base::FilePath> module_base(1); | 
| +  CHECK(base::GetCurrentDirectory(&module_base[0])); | 
| +  return module_base; | 
| +} | 
| + | 
| +class GinShellRunnerDelegate final : public ModuleRunnerDelegate { | 
| + public: | 
| +  GinShellRunnerDelegate() : ModuleRunnerDelegate(GetModuleSearchPaths()) { | 
| +    AddBuiltinModule(Console::kModuleName, Console::GetModule); | 
| +  } | 
| + | 
| +  void UnhandledException(ShellRunner* runner, TryCatch& try_catch) override { | 
| +    ModuleRunnerDelegate::UnhandledException(runner, try_catch); | 
| +    LOG(ERROR) << try_catch.GetStackTrace(); | 
| +  } | 
| + | 
| + private: | 
| +  DISALLOW_COPY_AND_ASSIGN(GinShellRunnerDelegate); | 
| +}; | 
| + | 
| +class GinBlinkPlatform final : public blink::Platform {}; | 
| + | 
| +}  // namespace | 
| +}  // namespace gin | 
| + | 
| +int main(int argc, char** argv) { | 
| +  base::AtExitManager at_exit; | 
| +  base::CommandLine::Init(argc, argv); | 
| +#ifdef V8_USE_EXTERNAL_STARTUP_DATA | 
| +  gin::V8Initializer::LoadV8Snapshot(); | 
| +  gin::V8Initializer::LoadV8Natives(); | 
| +#endif | 
| + | 
| +  // This message loop is not directly used here, but it has some side effects | 
| +  // in its constructor, so we need to keep this. | 
| +  base::MessageLoop message_loop; | 
| + | 
| +  // Initialize the base::FeatureList since IsolateHolder can depend on it. | 
| +  base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList)); | 
| + | 
| +  mojo::edk::Init(); | 
| +  gin::GinBlinkPlatform platform; | 
| +  blink::SnapshotCreator::SetTakingSnapshot(true); | 
| +  blink::Initialize(&platform); | 
| +  v8::SnapshotCreator* creator = blink::SnapshotCreator::GetSnapshotCreator(); | 
| +  v8::StartupData blob = blink::SnapshotCreator::SetUpSnapshotCreator(creator); | 
| + | 
| +  base::FilePath file_path = | 
| +      base::CommandLine::ForCurrentProcess()->GetSwitchValuePath("output_file"); | 
| +  CHECK(!file_path.empty()); | 
| +  base::WriteFile(file_path, blob.data, blob.raw_size); | 
| + | 
| +  delete[] blob.data; | 
| + | 
| +  return 0; | 
| +} | 
|  |