| 307 | } |
| 308 | |
| 309 | std::unique_ptr<v8::ScriptCompiler::CachedData> |
| 310 | V8Runtime::LoadCodeCacheIfNeeded(const std::string &sourceURL) { |
| 311 | // caching is for main runtime only |
| 312 | if (isSharedRuntime_) { |
| 313 | return nullptr; |
| 314 | } |
| 315 | |
| 316 | if (config_->codecacheMode == V8RuntimeConfig::CodecacheMode::kNone) { |
| 317 | return nullptr; |
| 318 | } |
| 319 | |
| 320 | std::filesystem::path codecachePath(config_->codecacheDir); |
| 321 | codecachePath /= std::filesystem::path(sourceURL).filename(); |
| 322 | auto *file = std::fopen(codecachePath.string().c_str(), "rb"); |
| 323 | if (!file) { |
| 324 | LOG(INFO) << "Cannot load codecache file: " << codecachePath.string(); |
| 325 | return nullptr; |
| 326 | } |
| 327 | std::fseek(file, 0, SEEK_END); |
| 328 | size_t size = std::ftell(file); |
| 329 | uint8_t *buffer = new uint8_t[size]; |
| 330 | std::rewind(file); |
| 331 | |
| 332 | std::fread(buffer, size, 1, file); |
| 333 | std::fclose(file); |
| 334 | |
| 335 | return std::make_unique<v8::ScriptCompiler::CachedData>( |
| 336 | buffer, |
| 337 | static_cast<int>(size), |
| 338 | v8::ScriptCompiler::CachedData::BufferPolicy::BufferOwned); |
| 339 | } |
| 340 | |
| 341 | bool V8Runtime::SaveCodeCacheIfNeeded( |
| 342 | const v8::Local<v8::Script> &script, |
nothing calls this directly
no outgoing calls
no test coverage detected