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