Commit 6a1cf1e4 authored by Oleg Korshul's avatar Oleg Korshul Committed by Alexander Trofimov

поддержка новой версии v8

и возможность несколько раз запускать doctrenderer/docbuilder
parent 107e460d
#include "docbuilder.h"
//#include "nativecontrol.h"
#include "../xml/include/xmlutils.h"
#include <iostream>
......@@ -37,30 +36,6 @@ public:
CScopeWrapper(v8::Isolate* isolate) : m_handler(isolate) {}
};
class CV8Initializer
{
private:
v8::Platform* m_platform;
public:
CV8Initializer()
{
m_platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(m_platform);
v8::V8::Initialize();
v8::V8::InitializeICU();
enableTypedArrays();
}
~CV8Initializer()
{
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete m_platform;
}
};
class CV8RealTimeWorker
{
public:
......@@ -74,19 +49,13 @@ public:
int m_nFileType;
public:
static CV8Initializer* m_pInitializer;
public:
CV8RealTimeWorker()
{
if (NULL == m_pInitializer)
NSDoctRenderer::CDocBuilder::Initialize();
m_nFileType = -1;
m_isolate = v8::Isolate::New();
m_isolate = CV8Worker::getInitializer()->CreateNew();
m_isolate_scope = new v8::Isolate::Scope(m_isolate);
m_isolate_locker = new v8::Locker(m_isolate);
......@@ -296,8 +265,6 @@ public:
}
};
CV8Initializer* CV8RealTimeWorker::m_pInitializer = NULL;
#ifdef CreateFile
#undef CreateFile
#endif
......@@ -1189,14 +1156,11 @@ namespace NSDoctRenderer
void CDocBuilder::Initialize()
{
if (NULL == CV8RealTimeWorker::m_pInitializer)
CV8RealTimeWorker::m_pInitializer = new CV8Initializer();
CV8Worker::Initialize();
}
void CDocBuilder::Dispose()
{
if (NULL != CV8RealTimeWorker::m_pInitializer)
delete CV8RealTimeWorker::m_pInitializer;
CV8RealTimeWorker::m_pInitializer = NULL;
CV8Worker::Dispose();
}
}
#include "doctrenderer.h"
#include "docbuilder.h"
#ifdef BOOL
#undef BOOL
......@@ -209,8 +210,6 @@ namespace NSDoctRenderer
std::wstring m_strEditorType;
std::wstring m_strFilePath;
bool m_bIsInitTypedArrays;
std::vector<std::wstring> m_arImagesInChanges;
std::wstring m_sConsoleLogFile;
......@@ -219,8 +218,6 @@ namespace NSDoctRenderer
public:
CDoctRenderer_Private(const std::wstring& sAllFontsPath = L"")
{
m_bIsInitTypedArrays = false;
m_strConfigDir = NSFile::GetProcessDirectory() + L"/";
m_strConfigPath = m_strConfigDir + L"DoctRenderer.config";
......@@ -515,20 +512,8 @@ namespace NSDoctRenderer
bool ExecuteScript(const std::string& strScript, std::wstring& strError, std::wstring& strReturnParams)
{
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
v8::V8::Initialize();
v8::V8::InitializeICU();
if (!m_bIsInitTypedArrays)
{
enableTypedArrays();
m_bIsInitTypedArrays = true;
}
bool bIsBreak = false;
v8::Isolate* isolate = v8::Isolate::New();
v8::Isolate* isolate = CV8Worker::getInitializer()->CreateNew();
if (true)
{
v8::Isolate::Scope isolate_cope(isolate);
......@@ -909,10 +894,8 @@ namespace NSDoctRenderer
}
isolate->Dispose();
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
CV8Worker::Dispose();
return bIsBreak ? false : true;
}
......
......@@ -17,7 +17,7 @@ CONFIG += plugin
CONFIG += c++11
############### destination path ###############
DESTINATION_SDK_PATH = $$PWD/../../SDK/lib
DESTINATION_SDK_PATH = $$PWD/../../build/lib
# WINDOWS
win32:contains(QMAKE_TARGET.arch, x86_64):{
......@@ -66,7 +66,10 @@ linux-g++ | linux-g++-64 | linux-g++-32 {
}
mac {
V8_CHECKOUT_PATH = /Users/Oleg/Desktop/activex/v8
DEFINES += NEW_V8_ENGINE
#V8_CHECKOUT_PATH = /Users/Oleg/Desktop/GIT/v8_mac_work/v8
V8_CHECKOUT_PATH = /Users/Oleg/Desktop/GIT/v8_mac/v8
}
win32 {
......@@ -164,7 +167,8 @@ mac {
MAC \
QT_MAC
LIBS += -L$$V8_CHECKOUT_PATH/out/native -lv8_base -lv8_libbase -lv8_libplatform -lv8_nosnapshot -lv8_snapshot
#LIBS += -L$$V8_CHECKOUT_PATH/out/native -lv8_base -lv8_libbase -lv8_libplatform -lv8_nosnapshot -lv8_snapshot
LIBS += -L$$V8_CHECKOUT_PATH/out/native -lv8_base -lv8_libbase -lv8_libplatform -lv8_nosnapshot -lv8_external_snapshot
LIBS += -L$$V8_CHECKOUT_PATH/out/native -licui18n -licuuc -licudata
message(mac)
......
......@@ -27,7 +27,10 @@ gclient
fetch v8
cd v8
// make native
CFLAGS="-fPIC" CXXFLAGS="-fPIC" make native
CFLAGS="-fPIC" CXXFLAGS="-fPIC" make native
#mac:
CFLAGS="-fPIC" CXXFLAGS="-fPIC -stdlib=libc++" LDFLAGS="-stdlib=libc++" make native
# or ---------------------------------------------------------------------------------------------------
sudo apt-get install git
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
......
......@@ -374,7 +374,25 @@ v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplateBuilder(v8::Isolate* i
}
// --------------------------
void enableTypedArrays()
void CV8Worker::Initialize()
{
v8::V8::SetArrayBufferAllocator(new MallocArrayBufferAllocator());
if (NULL == CV8Worker::m_pInitializer)
CV8Worker::m_pInitializer = new CV8Initializer();
}
void CV8Worker::Dispose()
{
if (NULL != CV8Worker::m_pInitializer)
delete CV8Worker::m_pInitializer;
CV8Worker::m_pInitializer = NULL;
}
CV8Initializer* CV8Worker::getInitializer()
{
if (NULL == CV8Worker::m_pInitializer)
CV8Worker::m_pInitializer = new CV8Initializer();
return CV8Worker::m_pInitializer;
}
CV8Initializer* CV8Worker::m_pInitializer = NULL;
// --------------------------
......@@ -318,8 +318,6 @@ public:
}
};
void enableTypedArrays();
class CChangesWorker
{
private:
......@@ -851,4 +849,63 @@ void CreateNativeObject(const v8::FunctionCallbackInfo<v8::Value>& args);
void CreateNativeObjectBuilder(const v8::FunctionCallbackInfo<v8::Value>& args);
void CreateNativeMemoryStream(const v8::FunctionCallbackInfo<v8::Value>& args);
//////////////////////////////////////////////////////////////////////////////
class CV8Initializer
{
private:
v8::Platform* m_platform;
MallocArrayBufferAllocator m_oAllocator;
public:
CV8Initializer() : m_oAllocator()
{
m_platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(m_platform);
v8::V8::Initialize();
v8::V8::InitializeICU();
#ifndef NEW_V8_ENGINE
v8::V8::SetArrayBufferAllocator(&m_oAllocator);
#endif
}
~CV8Initializer()
{
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete m_platform;
}
v8::ArrayBuffer::Allocator* getAllocator()
{
return &m_oAllocator;
}
v8::Isolate* CreateNew()
{
#ifdef NEW_V8_ENGINE
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &m_oAllocator;
return v8::Isolate::New(create_params);
#else
return v8::Isolate::New();
#endif
}
};
class CV8Worker
{
private:
static CV8Initializer* m_pInitializer;
public:
CV8Worker() {}
~CV8Worker() {}
static void Initialize();
static void Dispose();
static CV8Initializer* getInitializer();
};
#endif // NATIVECONTROL
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment