Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: gin/shell/gin_prepare_main.cc

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Work for most comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium 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 #include "base/at_exit.h"
6 #include "base/bind.h"
7 #include "base/command_line.h"
8 #include "base/files/file_util.h"
9 #include "base/location.h"
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h"
15 #include "base/task_scheduler/task_scheduler.h"
16 #include "base/threading/thread_task_runner_handle.h"
17 #include "gin/array_buffer.h"
18 #include "gin/modules/console.h"
19 #include "gin/modules/module_runner_delegate.h"
20 #include "gin/public/isolate_holder.h"
21 #include "gin/try_catch.h"
22 #include "gin/v8_initializer.h"
23 #include "mojo/edk/embedder/embedder.h"
24 #include "third_party/WebKit/public/web/SnapshotCreator.h"
25 #include "third_party/WebKit/public/web/WebKit.h"
26 #include "v8/include/v8.h"
27
28 namespace gin {
29 namespace {
30
31 std::vector<base::FilePath> GetModuleSearchPaths() {
32 std::vector<base::FilePath> module_base(1);
33 CHECK(base::GetCurrentDirectory(&module_base[0]));
34 return module_base;
35 }
36
37 class GinShellRunnerDelegate final : public ModuleRunnerDelegate {
38 public:
39 GinShellRunnerDelegate() : ModuleRunnerDelegate(GetModuleSearchPaths()) {
40 AddBuiltinModule(Console::kModuleName, Console::GetModule);
41 }
42
43 void UnhandledException(ShellRunner* runner, TryCatch& try_catch) override {
44 ModuleRunnerDelegate::UnhandledException(runner, try_catch);
45 LOG(ERROR) << try_catch.GetStackTrace();
46 }
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(GinShellRunnerDelegate);
50 };
51
52 class GinBlinkPlatform final : public blink::Platform {
53 public:
54 bool TakeV8Snapshot() override { return true; }
55 };
56
57 } // namespace
58 } // namespace gin
59
60 int main(int argc, char** argv) {
Yuki 2017/05/30 14:35:56 Can you put a comment about the usage of this prog
peria 2017/06/01 08:33:32 Done.
61 base::AtExitManager at_exit;
62 base::CommandLine::Init(argc, argv);
63 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
64 gin::V8Initializer::LoadV8Snapshot();
65 gin::V8Initializer::LoadV8Natives();
66 #endif
67
68 // set up environment to make Blink and V8 workable.
Yuki 2017/05/30 14:35:56 nit: s/set/Set/
peria 2017/06/01 08:33:32 Done.
69 base::MessageLoop message_loop;
70 base::TaskScheduler::CreateAndStartWithDefaultParams("TakeSnapshot");
71 mojo::edk::Init();
72
73 // Take snapshot
74 gin::GinBlinkPlatform platform;
75 blink::Initialize(&platform);
76 v8::StartupData blob = blink::SnapshotCreator::TakeSnapshot();
77
78 base::FilePath file_path =
79 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath("output_file");
80 CHECK(!file_path.empty());
81 base::WriteFile(file_path, blob.data, blob.raw_size);
82
83 delete[] blob.data;
84
85 return 0;
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698