Skip to content

Commit e499846

Browse files
authored
Merge pull request #1236 from NativeScript/darind/codecache-fix
Use the new ScriptCompiler::CreateCodeCache API to produce script caches
2 parents cb6a4b2 + 591cbc3 commit e499846

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

test-app/runtime/src/main/cpp/ModuleInternal.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,12 @@ Local<Script> ModuleInternal::LoadScript(Isolate* isolate, const string& path, c
379379
script = maybeScript.ToLocalChecked();
380380
} else {
381381
tns::instrumentation::Frame frame("Compile, no cache");
382-
if (Constants::V8_CACHE_COMPILED_CODE) {
383-
option = ScriptCompiler::kProduceCodeCache;
384-
}
385382
auto maybeScript = ScriptCompiler::Compile(isolate->GetCurrentContext(), &source, option);
386383
if (maybeScript.IsEmpty() || tc.HasCaught()) {
387384
throw NativeScriptException(tc, "Cannot compile " + path);
388385
}
389386
script = maybeScript.ToLocalChecked();
390-
SaveScriptCache(source, path);
387+
SaveScriptCache(script, path);
391388
}
392389

393390
DEBUG_WRITE("Compiled script (module %s)", path.c_str());
@@ -459,16 +456,19 @@ ScriptCompiler::CachedData* ModuleInternal::TryLoadScriptCache(const std::string
459456
return new ScriptCompiler::CachedData(reinterpret_cast<uint8_t*>(data), length, ScriptCompiler::CachedData::BufferOwned);
460457
}
461458

462-
void ModuleInternal::SaveScriptCache(const ScriptCompiler::Source& source, const std::string& path) {
459+
void ModuleInternal::SaveScriptCache(const Local<Script> script, const std::string& path) {
463460
if (!Constants::V8_CACHE_COMPILED_CODE) {
464461
return;
465462
}
466463

467464
tns::instrumentation::Frame frame("SaveScriptCache");
468465

469-
int length = source.GetCachedData()->length;
466+
Local<UnboundScript> unboundScript = script->GetUnboundScript();
467+
ScriptCompiler::CachedData* cachedData = ScriptCompiler::CreateCodeCache(unboundScript);
468+
469+
int length = cachedData->length;
470470
auto cachePath = path + ".cache";
471-
File::WriteBinary(cachePath, source.GetCachedData()->data, length);
471+
File::WriteBinary(cachePath, cachedData->data, length);
472472
}
473473

474474
ModuleInternal::ModulePathKind ModuleInternal::GetModulePathKind(const std::string& path) {

test-app/runtime/src/main/cpp/ModuleInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ModuleInternal {
6161

6262
v8::ScriptCompiler::CachedData* TryLoadScriptCache(const std::string& path);
6363

64-
void SaveScriptCache(const v8::ScriptCompiler::Source& source, const std::string& path);
64+
void SaveScriptCache(const v8::Local<v8::Script> script, const std::string& path);
6565

6666
ModulePathKind GetModulePathKind(const std::string& path);
6767

0 commit comments

Comments
 (0)