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 wmain(int argc,wchar_t * argv[])17int wmain(int argc, wchar_t* argv[]) { 18 #else // UNIX 19 int main(int argc, char* argv[]) { 20 #endif // _WIN32 21 22 v8::V8::SetFlagsFromString("--random_seed=42"); 23 24 if (argc < 2) { 25 std::cerr << "Usage: " << argv[0] << " <path/to/output.cc>\n"; 26 return 1; 27 } 28 29 std::ofstream out; 30 out.open(argv[1], std::ios::out | std::ios::binary); 31 if (!out.is_open()) { 32 std::cerr << "Cannot open " << argv[1] << "\n"; 33 return 1; 34 } 35 36 int node_argc = 1; 37 char argv0[] = "node"; 38 char* node_argv[] = {argv0, nullptr}; 39 40 node::InitializationResult result = 41 node::InitializeOncePerProcess(node_argc, node_argv); 42 CHECK(!result.early_return); 43 CHECK_EQ(result.exit_code, 0); 44 45 { 46 std::string snapshot = 47 node::SnapshotBuilder::Generate(result.args, result.exec_args); 48 out << snapshot; 49 out.close(); 50 } 51 52 node::TearDownOncePerProcess(); 53 return 0; 54 } 55