@@ -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
474474ModuleInternal::ModulePathKind ModuleInternal::GetModulePathKind (const std::string& path) {
0 commit comments