Index: src/d8.cc |
diff --git a/src/d8.cc b/src/d8.cc |
index 82fe6f76f335aeaac764cfe02b44ad81c6aa97de..1718fbd228707c861d5b7cedd61634cc80395343 100644 |
--- a/src/d8.cc |
+++ b/src/d8.cc |
@@ -1327,6 +1327,14 @@ bool Shell::SetOptions(int argc, char* argv[]) { |
printf("Javascript debugger not included\n"); |
return false; |
#endif // V8_SHARED |
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA |
+ } else if (strncmp(argv[i], "--natives_blob=", 15) == 0) { |
+ options.natives_blob = argv[i] + 15; |
+ argv[i] = NULL; |
+ } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) { |
+ options.snapshot_blob = argv[i] + 16; |
+ argv[i] = NULL; |
+#endif // V8_USE_EXTERNAL_STARTUP_DATA |
} |
} |
@@ -1485,9 +1493,65 @@ class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
}; |
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA |
+class StartupDataHandler { |
+ public: |
+ StartupDataHandler(const char* natives_blob, |
+ const char* snapshot_blob) { |
+ Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob); |
+ Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob); |
+ } |
+ |
+ ~StartupDataHandler() { |
+ delete[] natives_.data; |
+ delete[] snapshot_.data; |
+ } |
+ |
+ private: |
+ void Load(const char* blob_file, |
+ v8::StartupData* startup_data, |
+ void (*setter_fn)(v8::StartupData*)) { |
+ startup_data->data = NULL; |
+ startup_data->compressed_size = 0; |
+ startup_data->raw_size = 0; |
+ |
+ if (!blob_file) |
+ return; |
+ |
+ FILE* file = fopen(blob_file, "rb"); |
+ if (!file) |
+ return; |
+ |
+ fseek(file, 0, SEEK_END); |
+ startup_data->raw_size = ftell(file); |
+ rewind(file); |
+ |
+ startup_data->data = new char[startup_data->raw_size]; |
+ startup_data->compressed_size = fread( |
+ const_cast<char*>(startup_data->data), 1, startup_data->raw_size, |
+ file); |
+ fclose(file); |
+ |
+ if (startup_data->raw_size == startup_data->compressed_size) |
+ (*setter_fn)(startup_data); |
+ } |
+ |
+ v8::StartupData natives_; |
+ v8::StartupData snapshot_; |
+ |
+ // Disallow copy & assign. |
+ StartupDataHandler(const StartupDataHandler& other); |
+ void operator=(const StartupDataHandler& other); |
+}; |
+#endif // V8_USE_EXTERNAL_STARTUP_DATA |
+ |
+ |
int Shell::Main(int argc, char* argv[]) { |
if (!SetOptions(argc, argv)) return 1; |
v8::V8::InitializeICU(options.icu_data_file); |
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA |
+ StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob); |
+#endif |
SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); |
SetFlagsFromString("--redirect-code-traces-to=code.asm"); |
ShellArrayBufferAllocator array_buffer_allocator; |