1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef GIN_V8_INITIALIZER_H_ 6 #define GIN_V8_INITIALIZER_H_ 7 8 #include <stdint.h> 9 10 #include "base/files/file.h" 11 #include "base/files/memory_mapped_file.h" 12 #include "gin/array_buffer.h" 13 #include "gin/gin_export.h" 14 #include "gin/public/isolate_holder.h" 15 #include "gin/public/v8_platform.h" 16 #include "v8/include/v8.h" 17 18 namespace gin { 19 20 class GIN_EXPORT V8Initializer { 21 public: 22 // This should be called by IsolateHolder::Initialize(). 23 static void Initialize(IsolateHolder::ScriptMode mode); 24 25 // Get address and size information for currently loaded snapshot. 26 // If no snapshot is loaded, the return values are null for addresses 27 // and 0 for sizes. 28 static void GetV8ExternalSnapshotData(v8::StartupData* snapshot); 29 static void GetV8ExternalSnapshotData(const char** snapshot_data_out, 30 int* snapshot_size_out); 31 32 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 33 // Indicates which file to load as a snapshot blob image. 34 enum class V8SnapshotFileType { 35 kDefault, 36 37 // Snapshot augmented with customized contexts, which can be deserialized 38 // using v8::Context::FromSnapshot. 39 kWithAdditionalContext, 40 }; 41 42 // Load V8 snapshot from default resources, if they are available. 43 static void LoadV8Snapshot( 44 V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault); 45 46 // Load V8 snapshot from user provided file. 47 // The region argument, if non-zero, specifies the portions 48 // of the files to be mapped. Since the VM can boot with or without 49 // the snapshot, this function does not return a status. 50 static void LoadV8SnapshotFromFile( 51 base::File snapshot_file, 52 base::MemoryMappedFile::Region* snapshot_file_region, 53 V8SnapshotFileType snapshot_file_type); 54 55 #if defined(OS_ANDROID) 56 static base::FilePath GetSnapshotFilePath( 57 bool abi_32_bit, 58 V8SnapshotFileType snapshot_file_type); 59 #endif 60 61 #endif // V8_USE_EXTERNAL_STARTUP_DATA 62 63 }; 64 65 } // namespace gin 66 67 #endif // GIN_V8_INITIALIZER_H_ 68