[JSC] Refactoring

+ Renamed methods in CGraphicsEmbed and CNativeControlEmbed
+ Generated new embed files
+ Added check for allowed embed creation
This commit is contained in:
Asethone
2023-06-14 15:14:03 +04:00
parent 0c48bd4cc2
commit 03da8bc41a
9 changed files with 39 additions and 38 deletions

View File

@ -1,6 +1,6 @@
#include "GraphicsEmbed.h"
JSSmart<CJSValue> CGraphicsEmbed::init(JSSmart<CJSValue> Native, JSSmart<CJSValue> width_px, JSSmart<CJSValue> height_px, JSSmart<CJSValue> width_mm, JSSmart<CJSValue> height_mm)
JSSmart<CJSValue> CGraphicsEmbed::create(JSSmart<CJSValue> Native, JSSmart<CJSValue> width_px, JSSmart<CJSValue> height_px, JSSmart<CJSValue> width_mm, JSSmart<CJSValue> height_mm)
{
m_pInternal->init((NSNativeControl::CNativeControl*)Native->toObject()->getNative()->getObject(), width_px->toDouble(), height_px->toDouble(), width_mm->toDouble(), height_mm->toDouble());
return NULL;

View File

@ -17,7 +17,7 @@ public:
virtual void* getObject() override { return (void*)m_pInternal; }
public:
JSSmart<CJSValue> init(JSSmart<CJSValue> Native, JSSmart<CJSValue> width_px, JSSmart<CJSValue> height_px, JSSmart<CJSValue> width_mm, JSSmart<CJSValue> height_mm);
JSSmart<CJSValue> create(JSSmart<CJSValue> Native, JSSmart<CJSValue> width_px, JSSmart<CJSValue> height_px, JSSmart<CJSValue> width_mm, JSSmart<CJSValue> height_mm);
JSSmart<CJSValue> Destroy();
JSSmart<CJSValue> EndDraw();
JSSmart<CJSValue> put_GlobalAlpha(JSSmart<CJSValue> enable, JSSmart<CJSValue> globalAlpha);

View File

@ -147,7 +147,7 @@ JSSmart<CJSValue> CNativeControlEmbed::SaveChanges(JSSmart<CJSValue> sParam, JSS
return NULL;
}
JSSmart<CJSValue> CNativeControlEmbed::zipOpenFile(JSSmart<CJSValue> name)
JSSmart<CJSValue> CNativeControlEmbed::ZipOpen(JSSmart<CJSValue> name)
{
bool bIsOpen = m_pInternal->m_oZipWorker.Open(name->toStringW());
if (!bIsOpen)
@ -163,7 +163,7 @@ JSSmart<CJSValue> CNativeControlEmbed::zipOpenFile(JSSmart<CJSValue> name)
return obj->toValue();
}
JSSmart<CJSValue> CNativeControlEmbed::zipOpenFileBase64(JSSmart<CJSValue> name)
JSSmart<CJSValue> CNativeControlEmbed::ZipOpenBase64(JSSmart<CJSValue> name)
{
bool bIsOpen = m_pInternal->m_oZipWorker.OpenBase64(name->toStringA());
if (!bIsOpen)
@ -179,7 +179,7 @@ JSSmart<CJSValue> CNativeControlEmbed::zipOpenFileBase64(JSSmart<CJSValue> name)
return obj->toValue();
}
JSSmart<CJSValue> CNativeControlEmbed::zipGetFileAsString(JSSmart<CJSValue> name)
JSSmart<CJSValue> CNativeControlEmbed::ZipFileAsString(JSSmart<CJSValue> name)
{
BYTE* pData = NULL;
DWORD len = 0;
@ -187,12 +187,12 @@ JSSmart<CJSValue> CNativeControlEmbed::zipGetFileAsString(JSSmart<CJSValue> name
return CJSContext::createString((char*)pData, len);
}
JSSmart<CJSValue> CNativeControlEmbed::zipGetFileAsBinary(JSSmart<CJSValue> name)
JSSmart<CJSValue> CNativeControlEmbed::ZipFileAsBinary(JSSmart<CJSValue> name)
{
return CJSContext::createUint8Array(m_pInternal->m_oZipWorker.m_sTmpFolder + L"/" + name->toStringW());
}
JSSmart<CJSValue> CNativeControlEmbed::zipCloseFile()
JSSmart<CJSValue> CNativeControlEmbed::ZipClose()
{
m_pInternal->m_oZipWorker.Close();
return NULL;

View File

@ -36,11 +36,11 @@ public:
JSSmart<CJSValue> AddImageInChanges(JSSmart<CJSValue> img);
JSSmart<CJSValue> ConsoleLog(JSSmart<CJSValue> message);
/*[noexport]*/JSSmart<CJSValue> SaveChanges(JSSmart<CJSValue> sParam, JSSmart<CJSValue> nDeleteIndex, JSSmart<CJSValue> nCount);
JSSmart<CJSValue> zipOpenFile(JSSmart<CJSValue> name);
JSSmart<CJSValue> zipOpenFileBase64(JSSmart<CJSValue> name);
JSSmart<CJSValue> zipGetFileAsString(JSSmart<CJSValue> name);
JSSmart<CJSValue> zipGetFileAsBinary(JSSmart<CJSValue> name);
JSSmart<CJSValue> zipCloseFile();
JSSmart<CJSValue> ZipOpen(JSSmart<CJSValue> name);
JSSmart<CJSValue> ZipOpenBase64(JSSmart<CJSValue> name);
JSSmart<CJSValue> ZipFileAsString(JSSmart<CJSValue> name);
JSSmart<CJSValue> ZipFileAsBinary(JSSmart<CJSValue> name);
JSSmart<CJSValue> ZipClose();
JSSmart<CJSValue> GetImageUrl(JSSmart<CJSValue> sUrl);
JSSmart<CJSValue> GetImagesPath();
JSSmart<CJSValue> GetImageOriginalSize(JSSmart<CJSValue> sUrl);

View File

@ -5,7 +5,7 @@
#include "../../js_internal/jsc/jsc_base.h"
@protocol IJSCGraphicsEmbed <JSExport>
-(JSValue*) init : (JSValue*)Native : (JSValue*)width_px : (JSValue*)height_px : (JSValue*)width_mm : (JSValue*)height_mm;
-(JSValue*) create : (JSValue*)Native : (JSValue*)width_px : (JSValue*)height_px : (JSValue*)width_mm : (JSValue*)height_mm;
-(JSValue*) Destroy;
-(JSValue*) EndDraw;
-(JSValue*) put_GlobalAlpha : (JSValue*)enable : (JSValue*)globalAlpha;
@ -120,7 +120,7 @@
@implementation CJSCGraphicsEmbed
EMBED_OBJECT_WRAPPER_METHODS(CGraphicsEmbed);
FUNCTION_WRAPPER_JS_5(init, init)
FUNCTION_WRAPPER_JS_5(create, create)
FUNCTION_WRAPPER_JS_0(Destroy, Destroy)
FUNCTION_WRAPPER_JS_0(EndDraw, EndDraw)
FUNCTION_WRAPPER_JS_2(put_GlobalAlpha, put_GlobalAlpha)

View File

@ -20,11 +20,11 @@
-(JSValue*) Save_End : (JSValue*)pos : (JSValue*)len;
-(JSValue*) AddImageInChanges : (JSValue*)img;
-(JSValue*) ConsoleLog : (JSValue*)message;
-(JSValue*) zipOpenFile : (JSValue*)name;
-(JSValue*) zipOpenFileBase64 : (JSValue*)name;
-(JSValue*) zipGetFileAsString : (JSValue*)name;
-(JSValue*) zipGetFileAsBinary : (JSValue*)name;
-(JSValue*) zipCloseFile;
-(JSValue*) ZipOpen : (JSValue*)name;
-(JSValue*) ZipOpenBase64 : (JSValue*)name;
-(JSValue*) ZipFileAsString : (JSValue*)name;
-(JSValue*) ZipFileAsBinary : (JSValue*)name;
-(JSValue*) ZipClose;
-(JSValue*) GetImageUrl : (JSValue*)sUrl;
-(JSValue*) GetImagesPath;
-(JSValue*) GetImageOriginalSize : (JSValue*)sUrl;
@ -55,11 +55,11 @@ FUNCTION_WRAPPER_JS_1(GetChangesFile, GetChangesFile)
FUNCTION_WRAPPER_JS_2(Save_End, Save_End)
FUNCTION_WRAPPER_JS_1(AddImageInChanges, AddImageInChanges)
FUNCTION_WRAPPER_JS_1(ConsoleLog, ConsoleLog)
FUNCTION_WRAPPER_JS_1(zipOpenFile, zipOpenFile)
FUNCTION_WRAPPER_JS_1(zipOpenFileBase64, zipOpenFileBase64)
FUNCTION_WRAPPER_JS_1(zipGetFileAsString, zipGetFileAsString)
FUNCTION_WRAPPER_JS_1(zipGetFileAsBinary, zipGetFileAsBinary)
FUNCTION_WRAPPER_JS_0(zipCloseFile, zipCloseFile)
FUNCTION_WRAPPER_JS_1(ZipOpen, ZipOpen)
FUNCTION_WRAPPER_JS_1(ZipOpenBase64, ZipOpenBase64)
FUNCTION_WRAPPER_JS_1(ZipFileAsString, ZipFileAsString)
FUNCTION_WRAPPER_JS_1(ZipFileAsBinary, ZipFileAsBinary)
FUNCTION_WRAPPER_JS_0(ZipClose, ZipClose)
FUNCTION_WRAPPER_JS_1(GetImageUrl, GetImageUrl)
FUNCTION_WRAPPER_JS_0(GetImagesPath, GetImagesPath)
FUNCTION_WRAPPER_JS_1(GetImageOriginalSize, GetImageOriginalSize)

View File

@ -8,7 +8,7 @@ namespace NSGraphicsEmbed
{
#define CURRENTWRAPPER CGraphicsEmbed
FUNCTION_WRAPPER_V8_5(_init, init)
FUNCTION_WRAPPER_V8_5(_create, create)
FUNCTION_WRAPPER_V8_0(_Destroy, Destroy)
FUNCTION_WRAPPER_V8_0(_EndDraw, EndDraw)
FUNCTION_WRAPPER_V8_2(_put_GlobalAlpha, put_GlobalAlpha)
@ -118,7 +118,7 @@ namespace NSGraphicsEmbed
v8::Local<v8::ObjectTemplate> result = v8::ObjectTemplate::New(isolate);
result->SetInternalFieldCount(1);
NSV8Objects::Template_Set(result, "init", _init);
NSV8Objects::Template_Set(result, "create", _create);
NSV8Objects::Template_Set(result, "Destroy", _Destroy);
NSV8Objects::Template_Set(result, "EndDraw", _EndDraw);
NSV8Objects::Template_Set(result, "put_GlobalAlpha", _put_GlobalAlpha);

View File

@ -23,11 +23,11 @@ namespace NSNativeControlEmbed
FUNCTION_WRAPPER_V8_2(_Save_End, Save_End)
FUNCTION_WRAPPER_V8_1(_AddImageInChanges, AddImageInChanges)
FUNCTION_WRAPPER_V8_1(_ConsoleLog, ConsoleLog)
FUNCTION_WRAPPER_V8_1(_zipOpenFile, zipOpenFile)
FUNCTION_WRAPPER_V8_1(_zipOpenFileBase64, zipOpenFileBase64)
FUNCTION_WRAPPER_V8_1(_zipGetFileAsString, zipGetFileAsString)
FUNCTION_WRAPPER_V8_1(_zipGetFileAsBinary, zipGetFileAsBinary)
FUNCTION_WRAPPER_V8_0(_zipCloseFile, zipCloseFile)
FUNCTION_WRAPPER_V8_1(_ZipOpen, ZipOpen)
FUNCTION_WRAPPER_V8_1(_ZipOpenBase64, ZipOpenBase64)
FUNCTION_WRAPPER_V8_1(_ZipFileAsString, ZipFileAsString)
FUNCTION_WRAPPER_V8_1(_ZipFileAsBinary, ZipFileAsBinary)
FUNCTION_WRAPPER_V8_0(_ZipClose, ZipClose)
FUNCTION_WRAPPER_V8_1(_GetImageUrl, GetImageUrl)
FUNCTION_WRAPPER_V8_0(_GetImagesPath, GetImagesPath)
FUNCTION_WRAPPER_V8_1(_GetImageOriginalSize, GetImageOriginalSize)
@ -53,11 +53,11 @@ namespace NSNativeControlEmbed
NSV8Objects::Template_Set(result, "Save_End", _Save_End);
NSV8Objects::Template_Set(result, "AddImageInChanges", _AddImageInChanges);
NSV8Objects::Template_Set(result, "ConsoleLog", _ConsoleLog);
NSV8Objects::Template_Set(result, "zipOpenFile", _zipOpenFile);
NSV8Objects::Template_Set(result, "zipOpenFileBase64", _zipOpenFileBase64);
NSV8Objects::Template_Set(result, "zipGetFileAsString", _zipGetFileAsString);
NSV8Objects::Template_Set(result, "zipGetFileAsBinary", _zipGetFileAsBinary);
NSV8Objects::Template_Set(result, "zipCloseFile", _zipCloseFile);
NSV8Objects::Template_Set(result, "ZipOpen", _ZipOpen);
NSV8Objects::Template_Set(result, "ZipOpenBase64", _ZipOpenBase64);
NSV8Objects::Template_Set(result, "ZipFileAsString", _ZipFileAsString);
NSV8Objects::Template_Set(result, "ZipFileAsBinary", _ZipFileAsBinary);
NSV8Objects::Template_Set(result, "ZipClose", _ZipClose);
NSV8Objects::Template_Set(result, "GetImageUrl", _GetImageUrl);
NSV8Objects::Template_Set(result, "GetImagesPath", _GetImagesPath);
NSV8Objects::Template_Set(result, "GetImageOriginalSize", _GetImageOriginalSize);

View File

@ -443,8 +443,6 @@ namespace NSJSBase
{
id CreateEmbedNativeObject(NSString* name)
{
JSContext* context = [JSContext currentContext];
std::string sName = [name stdstring];
CEmbedObjectRegistrator& oRegistrator = CEmbedObjectRegistrator::getInstance();
CEmbedObjectRegistrator::store_t::iterator itFound = oRegistrator.m_infos.find(sName);
@ -453,6 +451,9 @@ namespace NSJSBase
const CEmbedObjectRegistrator::CEmdedClassInfo& oInfo = itFound->second;
if (oInfo.m_bIsCreationAllowed == false)
return nil;
CJSEmbedObject* pNativeObj = oInfo.m_creator();
CJSEmbedObjectAdapterJSC* pAdapter = static_cast<CJSEmbedObjectAdapterJSC*>(pNativeObj->getAdapter());
id pEmbedObj = pAdapter->getExportedObject(pNativeObj);