forked from nodejs/node
/
node_mksnapshot.cc
55 lines (45 loc) · 1.17 KB
/
node_mksnapshot.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <cstdio>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "libplatform/libplatform.h"
#include "node_internals.h"
#include "snapshot_builder.h"
#include "util-inl.h"
#include "v8.h"
#ifdef _WIN32
#include <windows.h>
int wmain(int argc, wchar_t* argv[]) {
#else // UNIX
int main(int argc, char* argv[]) {
argv = uv_setup_args(argc, argv);
#endif // _WIN32
v8::V8::SetFlagsFromString("--random_seed=42");
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <path/to/output.cc>\n";
return 1;
}
std::ofstream out;
out.open(argv[1], std::ios::out | std::ios::binary);
if (!out.is_open()) {
std::cerr << "Cannot open " << argv[1] << "\n";
return 1;
}
int node_argc = 1;
char argv0[] = "node";
char* node_argv[] = {argv0, nullptr};
node::InitializationResult result =
node::InitializeOncePerProcess(node_argc, node_argv);
CHECK(!result.early_return);
CHECK_EQ(result.exit_code, 0);
{
std::string snapshot =
node::SnapshotBuilder::Generate(result.args, result.exec_args);
out << snapshot;
out.close();
}
node::TearDownOncePerProcess();
return 0;
}