v8_initializer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #ifndef GIN_V8_INITIALIZER_H_
  5. #define GIN_V8_INITIALIZER_H_
  6. #include <stdint.h>
  7. #include "base/files/file.h"
  8. #include "base/files/memory_mapped_file.h"
  9. #include "build/build_config.h"
  10. #include "gin/array_buffer.h"
  11. #include "gin/gin_export.h"
  12. #include "gin/public/isolate_holder.h"
  13. #include "gin/public/v8_platform.h"
  14. #include "v8/include/v8-callbacks.h"
  15. #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
  16. #include "gin/public/v8_snapshot_file_type.h"
  17. #endif
  18. namespace v8 {
  19. class StartupData;
  20. }
  21. namespace gin {
  22. class GIN_EXPORT V8Initializer {
  23. public:
  24. // This should be called by IsolateHolder::Initialize().
  25. static void Initialize(IsolateHolder::ScriptMode mode,
  26. const std::string js_command_line_flags = {},
  27. v8::OOMErrorCallback oom_error_callback = nullptr);
  28. // Get address and size information for currently loaded snapshot.
  29. // If no snapshot is loaded, the return values are null for addresses
  30. // and 0 for sizes.
  31. static void GetV8ExternalSnapshotData(v8::StartupData* snapshot);
  32. static void GetV8ExternalSnapshotData(const char** snapshot_data_out,
  33. int* snapshot_size_out);
  34. #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
  35. // Load V8 snapshot from default resources, if they are available.
  36. static void LoadV8Snapshot(
  37. V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault);
  38. // Load V8 snapshot from user provided file.
  39. // The region argument, if non-zero, specifies the portions
  40. // of the files to be mapped. Since the VM can boot with or without
  41. // the snapshot, this function does not return a status.
  42. static void LoadV8SnapshotFromFile(
  43. base::File snapshot_file,
  44. base::MemoryMappedFile::Region* snapshot_file_region,
  45. V8SnapshotFileType snapshot_file_type);
  46. #if BUILDFLAG(IS_ANDROID)
  47. static base::FilePath GetSnapshotFilePath(
  48. bool abi_32_bit,
  49. V8SnapshotFileType snapshot_file_type);
  50. #endif
  51. #endif // V8_USE_EXTERNAL_STARTUP_DATA
  52. };
  53. } // namespace gin
  54. #endif // GIN_V8_INITIALIZER_H_