From d44ef86319abcc13d28d0119aa2832b418adae3d Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Thu, 11 Jan 2018 11:35:45 +0300 Subject: [PATCH] . --- Common/3dParty/v8/build.bat | 12 ++- Common/3dParty/v8/v8.pri | 2 +- DesktopEditor/doctrenderer/nativecontrol.h | 104 +++++++++++++++++++++ 3 files changed, 112 insertions(+), 6 deletions(-) diff --git a/Common/3dParty/v8/build.bat b/Common/3dParty/v8/build.bat index 014fdd30f6..69ebb465eb 100644 --- a/Common/3dParty/v8/build.bat +++ b/Common/3dParty/v8/build.bat @@ -5,11 +5,13 @@ SET PATH=%SCRIPTPATH%depot_tools;%PATH% SET DEPOT_TOOLS_WIN_TOOLCHAIN=0 SET GYP_MSVS_VERSION=2015 -cd v8 -call gn gen out.gn/win_64 --args="is_debug=false target_cpu=\"x64\" v8_target_cpu=\"x64\" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false" - -cd ../ call powershell -File .\fix-static_crt.ps1 cd v8 -call ninja -C out.gn/win_64 \ No newline at end of file +call gn gen out.gn/win_64/release --args="is_debug=false target_cpu=\"x64\" v8_target_cpu=\"x64\" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false" +call ninja -C out.gn/win_64/release + +call gn gen out.gn/win_64/debug --args="is_debug=true target_cpu=\"x64\" v8_target_cpu=\"x64\" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false" +call ninja -C out.gn/win_64/debug + +rem v8_use_snapshot=true v8_use_external_startup_data=true \ No newline at end of file diff --git a/Common/3dParty/v8/v8.pri b/Common/3dParty/v8/v8.pri index 1bbd5edba7..0ae7fc1589 100644 --- a/Common/3dParty/v8/v8.pri +++ b/Common/3dParty/v8/v8.pri @@ -6,7 +6,7 @@ INCLUDEPATH += \ $$CORE_V8_PATH_INCLUDE/include core_windows { - #CORE_V8_PATH_LIBS = $$CORE_V8_PATH_INCLUDE/out.gn/$$CORE_BUILDS_PLATFORM_PREFIX_$$CORE_BUILDS_CONFIGURATION_PREFIX/obj + CORE_V8_PATH_LIBS = $$CORE_V8_PATH_INCLUDE/out.gn/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX/obj LIBS += -L$$CORE_V8_PATH_LIBS -lv8_base -lv8_libplatform -lv8_libbase -lv8_snapshot -lv8_libsampler LIBS += -L$$CORE_V8_PATH_LIBS/third_party/icu -licui18n -licuuc diff --git a/DesktopEditor/doctrenderer/nativecontrol.h b/DesktopEditor/doctrenderer/nativecontrol.h index 82a1b47c7f..fc97a71ce6 100644 --- a/DesktopEditor/doctrenderer/nativecontrol.h +++ b/DesktopEditor/doctrenderer/nativecontrol.h @@ -1036,6 +1036,110 @@ public: #define LOGGER_SPEED_LAP(__logger_param) #endif +////////////////////////////////////////////////////////////////////////////// +#if 0 +class CSnapshotScript +{ +public: + bool m_bIsExist; + v8::StartupData m_oStartupData; + + CSnapshotScript(const std::wstring& sDir = L"") + { + m_bIsExist = false; + m_oStartupData.data = NULL; + m_oStartupData.raw_size = 0; + + std::wstring sFile = sDir + L"/heap_snapshot.bin"; + if (NSFile::CFileBinary::Exists(sFile)) + { + m_bIsExist = true; + + NSFile::CFileBinary oFile; + oFile.OpenFile(sFile); + m_oStartupData.raw_size = (int)oFile.GetFileSize(); + m_oStartupData.data = new char[m_oStartupData.raw_size]; + + DWORD dwRead = 0; + oFile.ReadFile((BYTE*)m_oStartupData.data, (DWORD)m_oStartupData.raw_size, dwRead); + oFile.CloseFile(); + } + } + + bool Generate(const std::string& sScript) + { + m_oStartupData = {NULL, 0}; + { + v8::SnapshotCreator snapshot_creator; + // Obtain an isolate provided by SnapshotCreator. + v8::Isolate* isolate = snapshot_creator.GetIsolate(); + { + v8::HandleScope scope(isolate); + // Create a new context and optionally run some script. + v8::Local context = v8::Context::New(isolate); + //v8::Context::Scope context_scope(context); + + if (!RunExtraCode(isolate, context, sScript.c_str(), "")) + return false; + + // Add the possibly customized context to the SnapshotCreator. + snapshot_creator.SetDefaultContext(context); + } + // Use the SnapshotCreator to create the snapshot blob. + m_oStartupData = snapshot_creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); + } + return true; + } + + void Save(const std::wstring& sDir) + { + if (m_oStartupData.data == NULL) + return; + + std::wstring sFile = sDir + L"/heap_snapshot.bin"; + NSFile::CFileBinary oFile; + oFile.CreateFile(sFile); + oFile.WriteFile((BYTE*)m_oStartupData.data, (DWORD)m_oStartupData.raw_size); + oFile.CloseFile(); + } + + bool RunExtraCode(v8::Isolate* isolate, v8::Local context, const char* utf8_source, const char* name) + { + // Run custom script if provided. + v8::TryCatch try_catch(isolate); + + v8::Local source_string; + if (!v8::String::NewFromUtf8(isolate, utf8_source, v8::NewStringType::kNormal).ToLocal(&source_string)) + return false; + + v8::Local resource_name = v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kNormal).ToLocalChecked(); + + v8::ScriptOrigin origin(resource_name); + v8::ScriptCompiler::Source source(source_string, origin); + v8::Local script; + + bool bRet = v8::ScriptCompiler::Compile(context, &source).ToLocal(&script); + + if (try_catch.HasCaught()) + { + std::string strCode = to_cstringA(try_catch.Message()->GetSourceLine()); + std::string strException = to_cstringA(try_catch.Message()->Get()); + return false; + } + + script->Run(); + + if (try_catch.HasCaught()) + { + std::string strCode = to_cstringA(try_catch.Message()->GetSourceLine()); + std::string strException = to_cstringA(try_catch.Message()->Get()); + return false; + } + return true; + } +}; +#endif + ////////////////////////////////////////////////////////////////////////////// class CV8Initializer {