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

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

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: . Created 3 years, 7 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/feature_list.h"
9 #include "base/files/file_util.h"
10 #include "base/location.h"
11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h"
16 #include "base/task_scheduler/task_scheduler.h"
17 #include "base/threading/thread_task_runner_handle.h"
18 #include "gin/array_buffer.h"
19 #include "gin/modules/console.h"
20 #include "gin/modules/module_runner_delegate.h"
21 #include "gin/public/isolate_holder.h"
22 #include "gin/try_catch.h"
23 #include "gin/v8_initializer.h"
24 #include "mojo/edk/embedder/embedder.h"
25 #include "third_party/WebKit/public/web/SnapshotCreator.h"
26 #include "third_party/WebKit/public/web/WebKit.h"
27 #include "v8/include/v8.h"
28
29 namespace gin {
30 namespace {
31
32 std::vector<base::FilePath> GetModuleSearchPaths() {
33 std::vector<base::FilePath> module_base(1);
34 CHECK(base::GetCurrentDirectory(&module_base[0]));
35 return module_base;
36 }
37
38 class GinShellRunnerDelegate final : public ModuleRunnerDelegate {
39 public:
40 GinShellRunnerDelegate() : ModuleRunnerDelegate(GetModuleSearchPaths()) {
41 AddBuiltinModule(Console::kModuleName, Console::GetModule);
42 }
43
44 void UnhandledException(ShellRunner* runner, TryCatch& try_catch) override {
45 ModuleRunnerDelegate::UnhandledException(runner, try_catch);
46 LOG(ERROR) << try_catch.GetStackTrace();
47 }
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(GinShellRunnerDelegate);
51 };
52
53 class GinBlinkPlatform final : public blink::Platform {};
54
55 } // namespace
56 } // namespace gin
57
58 int main(int argc, char** argv) {
59 base::AtExitManager at_exit;
60 base::CommandLine::Init(argc, argv);
61 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
62 gin::V8Initializer::LoadV8Snapshot();
63 gin::V8Initializer::LoadV8Natives();
64 #endif
65
66 // This message loop is not directly used here, but it has some side effects
67 // in its constructor, so we need to keep this.
68 base::MessageLoop message_loop;
69
70 // Initialize the base::FeatureList since IsolateHolder can depend on it.
71 base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList));
72
73 mojo::edk::Init();
74 gin::GinBlinkPlatform platform;
75 blink::SnapshotCreator::SetTakingSnapshot(true);
Yuki 2017/04/28 13:48:27 s/SetTakingSnapshot/SetTakeSnapshot/
peria 2017/06/01 08:33:31 Acknowledged.
76 blink::Initialize(&platform);
77 v8::SnapshotCreator* creator = blink::SnapshotCreator::GetSnapshotCreator();
78 v8::StartupData blob = blink::SnapshotCreator::SetUpSnapshotCreator(creator);
Yuki 2017/04/28 13:48:27 I've not yet read the implementation of SetUpSnaps
peria 2017/05/30 08:25:41 Done.
79
80 base::FilePath file_path =
81 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath("output_file");
82 CHECK(!file_path.empty());
83 base::WriteFile(file_path, blob.data, blob.raw_size);
84
85 delete[] blob.data;
86
87 return 0;
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698