MCPcopy Create free account
hub / github.com/Kudo/react-native-v8 / LoadCodeCacheIfNeeded

Method LoadCodeCacheIfNeeded

src/v8runtime/V8Runtime.cpp:309–339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307}
308
309std::unique_ptr<v8::ScriptCompiler::CachedData>
310V8Runtime::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
341bool V8Runtime::SaveCodeCacheIfNeeded(
342 const v8::Local<v8::Script> &script,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected