mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Remove static functions from editors.h
This commit is contained in:
@ -27,6 +27,7 @@ HEADERS += \
|
|||||||
docbuilder.h
|
docbuilder.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
editors.cpp \
|
||||||
nativecontrol.cpp \
|
nativecontrol.cpp \
|
||||||
doctrenderer.cpp \
|
doctrenderer.cpp \
|
||||||
docbuilder.cpp \
|
docbuilder.cpp \
|
||||||
|
|||||||
249
DesktopEditor/doctrenderer/editors.cpp
Normal file
249
DesktopEditor/doctrenderer/editors.cpp
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
#include "./editors.h"
|
||||||
|
|
||||||
|
#include "../common/StringBuilder.h"
|
||||||
|
|
||||||
|
namespace NSDoctRenderer
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void AppendScript(NSStringUtils::CStringBuilderA* builder, const std::wstring& path)
|
||||||
|
{
|
||||||
|
NSFile::CFileBinary oFile;
|
||||||
|
|
||||||
|
if (!oFile.OpenFile(path))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int size = (int)oFile.GetFileSize();
|
||||||
|
if (size < 3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BYTE* pData = new BYTE[size];
|
||||||
|
DWORD dwReadSize = 0;
|
||||||
|
oFile.ReadFile(pData, (DWORD)size, dwReadSize);
|
||||||
|
oFile.CloseFile();
|
||||||
|
|
||||||
|
int nOffset = 0;
|
||||||
|
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
|
||||||
|
nOffset = 3;
|
||||||
|
|
||||||
|
builder->WriteString((char*)(pData + nOffset), size - nOffset);
|
||||||
|
builder->WriteString("\n\n");
|
||||||
|
RELEASEARRAYOBJECTS(pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RunScript(JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, const std::wstring& path)
|
||||||
|
{
|
||||||
|
NSFile::CFileBinary oFile;
|
||||||
|
|
||||||
|
if (!oFile.OpenFile(path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int size = (int)oFile.GetFileSize();
|
||||||
|
if (size < 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
BYTE* pData = new BYTE[size];
|
||||||
|
DWORD dwReadSize = 0;
|
||||||
|
oFile.ReadFile(pData, (DWORD)size, dwReadSize);
|
||||||
|
oFile.CloseFile();
|
||||||
|
|
||||||
|
int nOffset = 0;
|
||||||
|
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
|
||||||
|
nOffset = 3;
|
||||||
|
|
||||||
|
context->runScript(std::string((char*)(pData + nOffset), size - nOffset), try_catch);
|
||||||
|
RELEASEARRAYOBJECTS(pData);
|
||||||
|
|
||||||
|
return !try_catch->Check();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring GetAllScript(NSStringUtils::CStringBuilderA* builder, const DoctRendererEditorType& type, CDoctRendererConfig* config, const bool& isSnapshot = false)
|
||||||
|
{
|
||||||
|
for (std::vector<std::wstring>::const_iterator i = config->m_arrFiles.cbegin(); i != config->m_arrFiles.cend(); i++)
|
||||||
|
AppendScript(builder, *i);
|
||||||
|
|
||||||
|
std::wstring sFontsPath = config->m_strSdkPath + L"/common/libfont/engine";
|
||||||
|
#ifdef SUPPORT_HARFBUZZ_SHAPER
|
||||||
|
sFontsPath += L"/fonts_native.js";
|
||||||
|
#else
|
||||||
|
sFontsPath += L"/fonts_ie.js";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::wstring sCachePath = L"";
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case DoctRendererEditorType::WORD:
|
||||||
|
{
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all-min.js");
|
||||||
|
AppendScript(builder, sFontsPath);
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all.js");
|
||||||
|
sCachePath = config->m_strSdkPath + L"/word/sdk-all";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DoctRendererEditorType::SLIDE:
|
||||||
|
{
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/slide/sdk-all-min.js");
|
||||||
|
AppendScript(builder, sFontsPath);
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/slide/sdk-all.js");
|
||||||
|
sCachePath = config->m_strSdkPath + L"/slide/sdk-all";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DoctRendererEditorType::CELL:
|
||||||
|
{
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/cell/sdk-all-min.js");
|
||||||
|
AppendScript(builder, sFontsPath);
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/cell/sdk-all.js");
|
||||||
|
builder->WriteString("\n$.ready();", 11);
|
||||||
|
sCachePath = config->m_strSdkPath + L"/cell/sdk-all";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DoctRendererEditorType::VISIO:
|
||||||
|
{
|
||||||
|
if (!NSFile::CFileBinary::Exists(config->m_strSdkPath + L"/draw/sdk-all-min.js"))
|
||||||
|
return L"";
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/draw/sdk-all-min.js");
|
||||||
|
AppendScript(builder, sFontsPath);
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/draw/sdk-all.js");
|
||||||
|
sCachePath = config->m_strSdkPath + L"/draw/sdk-all";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DoctRendererEditorType::PDF:
|
||||||
|
{
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all-min.js");
|
||||||
|
AppendScript(builder, sFontsPath);
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all.js");
|
||||||
|
AppendScript(builder, config->m_strSdkPath + L"/pdf/src/engine/drawingfile_native.js");
|
||||||
|
sCachePath = config->m_strSdkPath + L"/pdf/sdk-all";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sCachePath.empty())
|
||||||
|
sCachePath += (isSnapshot ? L".bin" : L".cache");
|
||||||
|
|
||||||
|
return sCachePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring GetSnapshotPath(const DoctRendererEditorType& type, CDoctRendererConfig* config)
|
||||||
|
{
|
||||||
|
std::wstring sCachePath = L"";
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case DoctRendererEditorType::WORD:
|
||||||
|
{
|
||||||
|
return config->m_strSdkPath + L"/word/sdk-all.bin";
|
||||||
|
}
|
||||||
|
case DoctRendererEditorType::SLIDE:
|
||||||
|
{
|
||||||
|
return config->m_strSdkPath + L"/slide/sdk-all.bin";
|
||||||
|
}
|
||||||
|
case DoctRendererEditorType::CELL:
|
||||||
|
{
|
||||||
|
return config->m_strSdkPath + L"/cell/sdk-all.bin";
|
||||||
|
}
|
||||||
|
case DoctRendererEditorType::VISIO:
|
||||||
|
{
|
||||||
|
return config->m_strSdkPath + L"/draw/sdk-all.bin";
|
||||||
|
}
|
||||||
|
case DoctRendererEditorType::PDF:
|
||||||
|
{
|
||||||
|
return config->m_strSdkPath + L"/pdf/sdk-all.bin";
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return L"";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RunEditorFooter(JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, CDoctRendererConfig* config)
|
||||||
|
{
|
||||||
|
if (!RunScript(context, try_catch, config->m_strAllFonts))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::string sFooter = "window.InitNativeEditors();";
|
||||||
|
|
||||||
|
if (context->isSnapshotUsed())
|
||||||
|
{
|
||||||
|
sFooter += "\
|
||||||
|
if (undefined === String.prototype.replaceAll)\
|
||||||
|
{\
|
||||||
|
String.prototype.replaceAll = function(str, newStr)\
|
||||||
|
{\
|
||||||
|
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]')\
|
||||||
|
return this.replace(str, newStr);\
|
||||||
|
return this.split(str).join(newStr);\
|
||||||
|
};\
|
||||||
|
}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
context->runScript(sFooter, try_catch);
|
||||||
|
return !try_catch->Check();
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
bool RunEditor(const DoctRendererEditorType& type, JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, CDoctRendererConfig* config)
|
||||||
|
{
|
||||||
|
if (context->isSnapshotUsed())
|
||||||
|
return RunEditorFooter(context, try_catch, config);
|
||||||
|
|
||||||
|
NSStringUtils::CStringBuilderA builder;
|
||||||
|
builder.AddSize(10 * 1024 * 1024);
|
||||||
|
std::wstring sCachePath = GetAllScript(&builder, type, config);
|
||||||
|
|
||||||
|
if (!sCachePath.empty())
|
||||||
|
{
|
||||||
|
context->runScript(builder.GetData(), try_catch, config->m_bIsUseCache ? sCachePath : L"");
|
||||||
|
RunEditorFooter(context, try_catch, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !try_catch->Check();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GenerateEditorSnapshot(const DoctRendererEditorType& type, CDoctRendererConfig* config)
|
||||||
|
{
|
||||||
|
NSStringUtils::CStringBuilderA builder;
|
||||||
|
builder.AddSize(10 * 1024 * 1024);
|
||||||
|
std::wstring sCachePath = GetAllScript(&builder, type, config, true);
|
||||||
|
|
||||||
|
builder.WriteString("delete String.prototype.replaceAll;");
|
||||||
|
|
||||||
|
if (sCachePath.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return NSJSBase::CJSContext::generateSnapshot(builder.GetData(), sCachePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
JSSmart<NSJSBase::CJSContext> RunEditorWithSnapshot(const DoctRendererEditorType& type, CDoctRendererConfig* config)
|
||||||
|
{
|
||||||
|
#ifndef V8_SUPPORT_SNAPSHOTS
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::wstring sCachePath = GetSnapshotPath(type, config);
|
||||||
|
if (!NSFile::CFileBinary::Exists(sCachePath))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (sCachePath.empty())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
JSSmart<NSJSBase::CJSContext> context = new NSJSBase::CJSContext(false);
|
||||||
|
context->Initialize(sCachePath);
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
JSSmart<NSJSBase::CJSContext> CreateEditorContext(const DoctRendererEditorType& type, CDoctRendererConfig* config)
|
||||||
|
{
|
||||||
|
JSSmart<NSJSBase::CJSContext> context = RunEditorWithSnapshot(type, config);
|
||||||
|
if (context.is_init())
|
||||||
|
return context;
|
||||||
|
return new NSJSBase::CJSContext();
|
||||||
|
}
|
||||||
|
} // namespace NSDoctRenderer
|
||||||
@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
#include "./config.h"
|
#include "./config.h"
|
||||||
#include "../js_internal/js_base.h"
|
#include "../js_internal/js_base.h"
|
||||||
#include "../common/StringBuilder.h"
|
|
||||||
|
|
||||||
#ifdef CreateFile
|
#ifdef CreateFile
|
||||||
#undef CreateFile
|
#undef CreateFile
|
||||||
@ -53,242 +52,11 @@ namespace NSDoctRenderer
|
|||||||
INVALID = 255
|
INVALID = 255
|
||||||
};
|
};
|
||||||
|
|
||||||
static void AppendScript(NSStringUtils::CStringBuilderA* builder, const std::wstring& path)
|
bool RunEditor(const DoctRendererEditorType& type, JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, CDoctRendererConfig* config);
|
||||||
{
|
|
||||||
NSFile::CFileBinary oFile;
|
|
||||||
|
|
||||||
if (!oFile.OpenFile(path))
|
bool GenerateEditorSnapshot(const DoctRendererEditorType& type, CDoctRendererConfig* config);
|
||||||
return;
|
|
||||||
|
|
||||||
int size = (int)oFile.GetFileSize();
|
JSSmart<NSJSBase::CJSContext> CreateEditorContext(const DoctRendererEditorType& type, CDoctRendererConfig* config);
|
||||||
if (size < 3)
|
|
||||||
return;
|
|
||||||
|
|
||||||
BYTE* pData = new BYTE[size];
|
|
||||||
DWORD dwReadSize = 0;
|
|
||||||
oFile.ReadFile(pData, (DWORD)size, dwReadSize);
|
|
||||||
oFile.CloseFile();
|
|
||||||
|
|
||||||
int nOffset = 0;
|
|
||||||
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
|
|
||||||
nOffset = 3;
|
|
||||||
|
|
||||||
builder->WriteString((char*)(pData + nOffset), size - nOffset);
|
|
||||||
builder->WriteString("\n\n");
|
|
||||||
RELEASEARRAYOBJECTS(pData);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool RunScript(JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, const std::wstring& path)
|
|
||||||
{
|
|
||||||
NSFile::CFileBinary oFile;
|
|
||||||
|
|
||||||
if (!oFile.OpenFile(path))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
int size = (int)oFile.GetFileSize();
|
|
||||||
if (size < 3)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BYTE* pData = new BYTE[size];
|
|
||||||
DWORD dwReadSize = 0;
|
|
||||||
oFile.ReadFile(pData, (DWORD)size, dwReadSize);
|
|
||||||
oFile.CloseFile();
|
|
||||||
|
|
||||||
int nOffset = 0;
|
|
||||||
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
|
|
||||||
nOffset = 3;
|
|
||||||
|
|
||||||
context->runScript(std::string((char*)(pData + nOffset), size - nOffset), try_catch);
|
|
||||||
RELEASEARRAYOBJECTS(pData);
|
|
||||||
|
|
||||||
return !try_catch->Check();
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::wstring GetAllScript(NSStringUtils::CStringBuilderA* builder, const DoctRendererEditorType& type, CDoctRendererConfig* config, const bool& isSnapshot = false)
|
|
||||||
{
|
|
||||||
for (std::vector<std::wstring>::const_iterator i = config->m_arrFiles.cbegin(); i != config->m_arrFiles.cend(); i++)
|
|
||||||
AppendScript(builder, *i);
|
|
||||||
|
|
||||||
std::wstring sFontsPath = config->m_strSdkPath + L"/common/libfont/engine";
|
|
||||||
#ifdef SUPPORT_HARFBUZZ_SHAPER
|
|
||||||
sFontsPath += L"/fonts_native.js";
|
|
||||||
#else
|
|
||||||
sFontsPath += L"/fonts_ie.js";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::wstring sCachePath = L"";
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case DoctRendererEditorType::WORD:
|
|
||||||
{
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all-min.js");
|
|
||||||
AppendScript(builder, sFontsPath);
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all.js");
|
|
||||||
sCachePath = config->m_strSdkPath + L"/word/sdk-all";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DoctRendererEditorType::SLIDE:
|
|
||||||
{
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/slide/sdk-all-min.js");
|
|
||||||
AppendScript(builder, sFontsPath);
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/slide/sdk-all.js");
|
|
||||||
sCachePath = config->m_strSdkPath + L"/slide/sdk-all";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DoctRendererEditorType::CELL:
|
|
||||||
{
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/cell/sdk-all-min.js");
|
|
||||||
AppendScript(builder, sFontsPath);
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/cell/sdk-all.js");
|
|
||||||
builder->WriteString("\n$.ready();", 11);
|
|
||||||
sCachePath = config->m_strSdkPath + L"/cell/sdk-all";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DoctRendererEditorType::VISIO:
|
|
||||||
{
|
|
||||||
if (!NSFile::CFileBinary::Exists(config->m_strSdkPath + L"/draw/sdk-all-min.js"))
|
|
||||||
return L"";
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/draw/sdk-all-min.js");
|
|
||||||
AppendScript(builder, sFontsPath);
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/draw/sdk-all.js");
|
|
||||||
sCachePath = config->m_strSdkPath + L"/draw/sdk-all";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DoctRendererEditorType::PDF:
|
|
||||||
{
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all-min.js");
|
|
||||||
AppendScript(builder, sFontsPath);
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all.js");
|
|
||||||
AppendScript(builder, config->m_strSdkPath + L"/pdf/src/engine/drawingfile_native.js");
|
|
||||||
sCachePath = config->m_strSdkPath + L"/pdf/sdk-all";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sCachePath.empty())
|
|
||||||
sCachePath += (isSnapshot ? L".bin" : L".cache");
|
|
||||||
|
|
||||||
return sCachePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::wstring GetSnapshotPath(const DoctRendererEditorType& type, CDoctRendererConfig* config)
|
|
||||||
{
|
|
||||||
std::wstring sCachePath = L"";
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case DoctRendererEditorType::WORD:
|
|
||||||
{
|
|
||||||
return config->m_strSdkPath + L"/word/sdk-all.bin";
|
|
||||||
}
|
|
||||||
case DoctRendererEditorType::SLIDE:
|
|
||||||
{
|
|
||||||
return config->m_strSdkPath + L"/slide/sdk-all.bin";
|
|
||||||
}
|
|
||||||
case DoctRendererEditorType::CELL:
|
|
||||||
{
|
|
||||||
return config->m_strSdkPath + L"/cell/sdk-all.bin";
|
|
||||||
}
|
|
||||||
case DoctRendererEditorType::VISIO:
|
|
||||||
{
|
|
||||||
return config->m_strSdkPath + L"/draw/sdk-all.bin";
|
|
||||||
}
|
|
||||||
case DoctRendererEditorType::PDF:
|
|
||||||
{
|
|
||||||
return config->m_strSdkPath + L"/pdf/sdk-all.bin";
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return L"";
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool RunEditorFooter(JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, CDoctRendererConfig* config)
|
|
||||||
{
|
|
||||||
if (!RunScript(context, try_catch, config->m_strAllFonts))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::string sFooter = "window.InitNativeEditors();";
|
|
||||||
|
|
||||||
if (context->isSnapshotUsed())
|
|
||||||
{
|
|
||||||
sFooter += "\
|
|
||||||
if (undefined === String.prototype.replaceAll)\
|
|
||||||
{\
|
|
||||||
String.prototype.replaceAll = function(str, newStr)\
|
|
||||||
{\
|
|
||||||
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]')\
|
|
||||||
return this.replace(str, newStr);\
|
|
||||||
return this.split(str).join(newStr);\
|
|
||||||
};\
|
|
||||||
}\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
context->runScript(sFooter, try_catch);
|
|
||||||
return !try_catch->Check();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool RunEditor(const DoctRendererEditorType& type, JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, CDoctRendererConfig* config)
|
|
||||||
{
|
|
||||||
if (context->isSnapshotUsed())
|
|
||||||
return RunEditorFooter(context, try_catch, config);
|
|
||||||
|
|
||||||
NSStringUtils::CStringBuilderA builder;
|
|
||||||
builder.AddSize(10 * 1024 * 1024);
|
|
||||||
std::wstring sCachePath = GetAllScript(&builder, type, config);
|
|
||||||
|
|
||||||
if (!sCachePath.empty())
|
|
||||||
{
|
|
||||||
context->runScript(builder.GetData(), try_catch, config->m_bIsUseCache ? sCachePath : L"");
|
|
||||||
RunEditorFooter(context, try_catch, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
return !try_catch->Check();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool GenerateEditorSnapshot(const DoctRendererEditorType& type, CDoctRendererConfig* config)
|
|
||||||
{
|
|
||||||
NSStringUtils::CStringBuilderA builder;
|
|
||||||
builder.AddSize(10 * 1024 * 1024);
|
|
||||||
std::wstring sCachePath = GetAllScript(&builder, type, config, true);
|
|
||||||
|
|
||||||
builder.WriteString("delete String.prototype.replaceAll;");
|
|
||||||
|
|
||||||
if (sCachePath.empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return NSJSBase::CJSContext::generateSnapshot(builder.GetData(), sCachePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSSmart<NSJSBase::CJSContext> RunEditorWithSnapshot(const DoctRendererEditorType& type, CDoctRendererConfig* config)
|
|
||||||
{
|
|
||||||
#ifndef V8_SUPPORT_SNAPSHOTS
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::wstring sCachePath = GetSnapshotPath(type, config);
|
|
||||||
if (!NSFile::CFileBinary::Exists(sCachePath))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (sCachePath.empty())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
JSSmart<NSJSBase::CJSContext> context = new NSJSBase::CJSContext(false);
|
|
||||||
context->Initialize(sCachePath);
|
|
||||||
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSSmart<NSJSBase::CJSContext> CreateEditorContext(const DoctRendererEditorType& type, CDoctRendererConfig* config)
|
|
||||||
{
|
|
||||||
JSSmart<NSJSBase::CJSContext> context = RunEditorWithSnapshot(type, config);
|
|
||||||
if (context.is_init())
|
|
||||||
return context;
|
|
||||||
return new NSJSBase::CJSContext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // DOC_BUILDER_EDITORS_CONFIG
|
#endif // DOC_BUILDER_EDITORS_CONFIG
|
||||||
|
|||||||
Reference in New Issue
Block a user