nobody knows about v8

This commit is contained in:
Kulikova Svetlana
2020-10-21 14:08:30 +03:00
parent cbca4decf9
commit 47ab073e49
7 changed files with 31 additions and 139 deletions

View File

@ -136,26 +136,11 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
JSSmart<CJSContextScope> context_scope = m_context->CreateContextScope();
JSSmart<CJSTryCatch> try_catch = m_context->GetExceptions();
CCacheDataScript oCachedScript(sCachePath);
LOGGER_SPEED_LAP("compile");
if (!sCachePath.empty())
{
v8::Local<v8::Script> script = oCachedScript.Compile(m_context->m_internal->m_context, v8::String::NewFromUtf8(m_context->m_internal->m_isolate, sString.c_str()));
if(try_catch->Check())
return false;
else
{
script->Run(m_context->m_internal->m_context);
if(try_catch->Check())
return false;
}
}
else
{
m_context->runScript(sString, try_catch);
if(try_catch->Check())
return false;
}
m_context->runScript(sString, try_catch, sCachePath);
if(try_catch->Check())
return false;
LOGGER_SPEED_LAP("run")

View File

@ -35,10 +35,10 @@
#include "docbuilder.h"
#include "doctrenderer.h"
#include "../xml/include/xmlutils.h"
#include <iostream>
#include <list>
#include "../xml/include/xmlutils.h"
#include "../common/File.h"
#include "../common/Directory.h"

View File

@ -37,6 +37,7 @@
#endif
#include "js_internal/embed/NativeControlEmbed.h"
#include "js_internal/embed/MemoryStreamEmbed.h"
#include "../xml/include/xmlutils.h"
@ -485,12 +486,7 @@ namespace NSDoctRenderer
else
{
std::string sTmp = U_TO_UTF8((pParams->m_sJsonParams));
#ifndef V8_OS_XP
args[0] = js_value(v8::JSON::Parse(context->m_internal->m_context, v8::String::NewFromUtf8(context->m_internal->m_isolate, sTmp.c_str())).FromMaybe(v8::Local<v8::Value>()));
#else
args[0] = js_value(v8::JSON::Parse(v8::String::NewFromUtf8(context->m_internal->m_isolate, sTmp.c_str())));
#endif
args[0] = context->JSON_Parse(sTmp.c_str());
}
JSSmart<CJSValue> js_result2 = js_objectApi->call_func("asc_nativeCalculateFile", 1, args);
@ -522,12 +518,7 @@ namespace NSDoctRenderer
else
{
std::string sTmp = U_TO_UTF8((pParams->m_sJsonParams));
#ifndef V8_OS_XP
args[0] = js_value(v8::JSON::Parse(context->m_internal->m_context, v8::String::NewFromUtf8(context->m_internal->m_isolate, sTmp.c_str())).FromMaybe(v8::Local<v8::Value>()));
#else
args[0] = js_value(v8::JSON::Parse(v8::String::NewFromUtf8(context->m_internal->m_isolate, sTmp.c_str())));
#endif
args[0] = context->JSON_Parse(sTmp.c_str());
}
JSSmart<CJSValue> js_result2 = js_objectApi->call_func("asc_nativeGetPDF", 1, args);
@ -636,37 +627,15 @@ namespace NSDoctRenderer
JSSmart<CJSContextScope> context_scope = context->CreateContextScope();
JSSmart<CJSTryCatch> try_catch = context->GetExceptions();
LOGGER_SPEED_LAP("pre_compile")
CCacheDataScript oCachedScript(sCachePath);
LOGGER_SPEED_LAP("compile")
if (!sCachePath.empty())
context->runScript(strScript, try_catch, sCachePath);
if(try_catch->Check())
{
v8::Local<v8::Script> script = oCachedScript.Compile(context->m_internal->m_context, v8::String::NewFromUtf8(context->m_internal->m_isolate, strScript.c_str()));
if(try_catch->Check())
{
strError = L"code=\"compile\"";
bIsBreak = true;
}
else
{
script->Run(context->m_internal->m_context);
if(try_catch->Check())
{
strError = L"code=\"run\"";
bIsBreak = true;
}
}
}
else
{
context->runScript(strScript, try_catch);
if(try_catch->Check())
{
strError = L"code=\"run\"";
bIsBreak = true;
}
strError = L"code=\"run\"";
bIsBreak = true;
}
LOGGER_SPEED_LAP("run")
//---------------------------------------------------------------
@ -836,11 +805,7 @@ namespace NSDoctRenderer
pBaseData[dwSizeBase] = 0;
JSSmart<CJSValue> args_changes[1];
#ifndef V8_OS_XP
args_changes[0] = js_value(v8::JSON::Parse(context->m_internal->m_context, v8::String::NewFromUtf8(context->m_internal->m_isolate, (char*)(pBaseData + nStart))).FromMaybe(v8::Local<v8::Value>()));
#else
args_changes[0] = js_value(v8::JSON::Parse(v8::String::NewFromUtf8(context->m_internal->m_isolate, (char*)(pBaseData + nStart))));
#endif
args_changes[0] = context->JSON_Parse((char*)(pBaseData + nStart));
js_objectApi->call_func("asc_StartMailMergeByList", 1, args_changes);
if (try_catch->Check())

View File

@ -59,7 +59,6 @@ HEADERS += \
docbuilder_p.h \
memorystream.h \
nativecontrol.h \
graphics.h
HEADERS += \

View File

@ -187,6 +187,7 @@ namespace NSJSBase
CJSLocalScope* CreateLocalScope();
JSSmart<CJSValue> runScript(const std::string& script, JSSmart<CJSTryCatch> exception = NULL, const std::wstring& scriptPath = std::wstring(L""));
CJSValue* JSON_Parse(const char* sTmp);
public:
static CJSValue* createUndefined();

View File

@ -259,7 +259,7 @@ namespace NSJSBase
v8::Local<v8::String> _source = v8::String::NewFromUtf8(CV8Worker::GetCurrent(), script.c_str());
v8::Local<v8::Script> _script;
if(scriptPath.length() > 0)
if(!scriptPath.empty())
{
std::wstring sCachePath = scriptPath.substr(0, scriptPath.find(L".")) + L".cache";
CCacheDataScript oCachedScript(sCachePath);
@ -300,4 +300,15 @@ namespace NSJSBase
// global???
return ret;
}
CJSValue* CJSContext::JSON_Parse(const char *sTmp)
{
CJSValueV8* _value = new CJSValueV8();
#ifndef V8_OS_XP
_value->value = v8::JSON::Parse(m_internal->m_context, v8::String::NewFromUtf8(CV8Worker::GetCurrent(), sTmp)).FromMaybe(v8::Local<v8::Value>());
#else
_value->value = v8::JSON::Parse(v8::String::NewFromUtf8(CV8Worker::GetCurrent(), sTmp));
#endif
return _value;
}
}

View File

@ -41,8 +41,7 @@
#include "../common/Array.h"
#include "../../OfficeUtils/src/OfficeUtils.h"
#include "js_internal/embed/MemoryStreamEmbed.h"
#include "js_internal/v8/v8_base.h"
#include "js_internal/js_base.h"
#include "../fontengine/application_generate_fonts_common.h"
#if defined(CreateDirectory)
@ -191,6 +190,7 @@ public:
std::wstring GetImage(const std::wstring& sUrl);
};
using namespace NSJSBase;
namespace NSNativeControl
{
class CNativeControl
@ -232,8 +232,6 @@ public:
// для добавления картинок -------------------------------------
CImagesWorker* m_pWorker;
CMemoryStreamEmbed* m_pStream;
public:
CNativeControl() :
m_pChanges(NULL),
@ -244,12 +242,10 @@ public:
m_nSaveBinaryLen(0),
m_sConsoleLogFile(L""),
m_nCurrentChangesBuilderIndex(0),
m_pWorker(NULL),
m_pStream(NULL)
m_pWorker(NULL)
{}
~CNativeControl()
{
RELEASEOBJECT(m_pStream);
m_pChanges = NULL;
RELEASEARRAYOBJECTS(m_pSaveBinary);
@ -1122,69 +1118,4 @@ bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFi
JSSmart<CJSValue>* args,
std::wstring& strError);
class CCacheDataScript
{
private:
BYTE* Data;
int Length;
v8::ScriptCompiler::Source* Source;
v8::ScriptCompiler::CachedData* CachedData;
std::wstring Path;
public:
CCacheDataScript(const std::wstring& sPath)
{
Data = NULL;
Length = 0;
if (!sPath.empty())
{
BYTE* _data = NULL;
DWORD _data_length = 0;
if (NSFile::CFileBinary::ReadAllBytes(sPath, &_data, _data_length))
{
Data = _data;
Length = (int)_data_length;
}
}
Source = NULL;
CachedData = NULL;
Path = sPath;
}
~CCacheDataScript()
{
//RELEASEOBJECT(Source);
//RELEASEOBJECT(CachedData);
RELEASEARRAYOBJECTS(Data);
}
v8::Local<v8::Script> Compile(const v8::Local<v8::Context>& _context, const v8::Local<v8::String>& source)
{
v8::Local<v8::Script> script;
if (NULL == Data)
{
Source = new v8::ScriptCompiler::Source(source);
script = v8::ScriptCompiler::Compile(_context, Source, v8::ScriptCompiler::kProduceCodeCache).ToLocalChecked();
const v8::ScriptCompiler::CachedData* _cachedData = Source->GetCachedData();
NSFile::CFileBinary oFileTest;
if (oFileTest.CreateFileW(Path))
{
oFileTest.WriteFile(_cachedData->data, (DWORD)_cachedData->length);
oFileTest.CloseFile();
}
}
else
{
CachedData = new v8::ScriptCompiler::CachedData(Data, Length);
Source = new v8::ScriptCompiler::Source(source, CachedData);
script = v8::ScriptCompiler::Compile(_context, Source, v8::ScriptCompiler::kConsumeCodeCache).ToLocalChecked();
}
return script;
}
};
#endif // NATIVECONTROL