| Index: src/d8.cc | 
| diff --git a/src/d8.cc b/src/d8.cc | 
| index 1ecfc270d43973bacd6c3c5ab7db6e063733d3e7..4ed4f76c34fbf6004d37361f016e5e2ed8453203 100644 | 
| --- a/src/d8.cc | 
| +++ b/src/d8.cc | 
| @@ -1320,6 +1320,15 @@ bool Shell::SetOptions(int argc, char* argv[]) { | 
| 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 | 
| } | 
|  | 
| v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 
| @@ -1477,9 +1486,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; | 
|  |