| 663 | } |
| 664 | |
| 665 | void ModuleInternal::SaveScriptCache(const Local<Script> script, const std::string& path) { |
| 666 | if (!Constants::V8_CACHE_COMPILED_CODE) { |
| 667 | return; |
| 668 | } |
| 669 | |
| 670 | tns::instrumentation::Frame frame("SaveScriptCache"); |
| 671 | |
| 672 | Local<UnboundScript> unboundScript = script->GetUnboundScript(); |
| 673 | ScriptCompiler::CachedData* cachedData = ScriptCompiler::CreateCodeCache(unboundScript); |
| 674 | |
| 675 | int length = cachedData->length; |
| 676 | auto cachePath = path + ".cache"; |
| 677 | File::WriteBinary(cachePath, cachedData->data, length); |
| 678 | delete cachedData; |
| 679 | // make sure cache and js file have the same modification date |
| 680 | struct stat result; |
| 681 | struct utimbuf new_times; |
| 682 | new_times.actime = time(nullptr); |
| 683 | new_times.modtime = time(nullptr); |
| 684 | if (stat(path.c_str(), &result) == 0) { |
| 685 | auto jsLastModifiedTime = result.st_mtime; |
| 686 | new_times.modtime = jsLastModifiedTime; |
| 687 | } |
| 688 | utime(cachePath.c_str(), &new_times); |
| 689 | } |
| 690 | |
| 691 | ModuleInternal::ModulePathKind ModuleInternal::GetModulePathKind(const std::string& path) { |
| 692 | ModulePathKind kind; |