Added #ifdef and [noexport] support for code generation. Replaced most of internal classes.

Removed unnecessary V8 code.
This commit is contained in:
Asethone
2023-06-11 23:30:40 +04:00
parent 6590643894
commit 39cbad3ebf
26 changed files with 1009 additions and 979 deletions

View File

@ -670,6 +670,10 @@ namespace NSJSBase
* 7. In C++ code call `CJSContext::Embed<YourClassName>()`.
*
* You can then call `CreateEmbedOjbect('YourClassName')` in JS code for getting an instance of the embedded class and use its methods.
*
* NOTE: If you don't want to export certain functions from your embedded class for some reason,
* then add the inline comment "[noexport]" at the start of a function declaration.
* Also you can use `#ifdef ... #endif` blocks (see doctrenderer/test/internal/Embed.h for an example).
*/
#endif // _CORE_EXT_JS_BASE_H_

View File

@ -219,18 +219,6 @@ namespace NSJSBase
#endif
m_internal->m_contextPersistent.Reset();
unsigned int nEmbedDataCount = m_internal->m_isolate->GetNumberOfDataSlots();
if (nEmbedDataCount > 0)
{
void* pSingletonData = m_internal->m_isolate->GetData(0);
if (NULL != pSingletonData)
{
CIsolateAdditionalData* pData = (CIsolateAdditionalData*)pSingletonData;
delete pData;
}
}
m_internal->m_isolate->Dispose();
m_internal->m_isolate = NULL;
}

View File

@ -77,40 +77,6 @@ public:
};
#endif
// TODO: remove this class
class CIsolateAdditionalData
{
public:
NSJSBase::IsolateAdditionalDataType m_eType;
public:
CIsolateAdditionalData(const NSJSBase::IsolateAdditionalDataType& type = NSJSBase::iadtUndefined) { m_eType = type; }
virtual ~CIsolateAdditionalData() {}
static bool CheckSingletonType(v8::Isolate* isolate, const NSJSBase::IsolateAdditionalDataType& type, const bool& isAdd = true)
{
unsigned int nCount = isolate->GetNumberOfDataSlots();
if (nCount == 0)
return false;
void* pSingletonData = isolate->GetData(0);
if (NULL != pSingletonData)
{
CIsolateAdditionalData* pData = (CIsolateAdditionalData*)pSingletonData;
if (pData->m_eType == type)
return true;
return false;
}
if (isAdd)
{
isolate->SetData(0, (void*)(new CIsolateAdditionalData(type)));
}
return false;
}
};
class CV8Initializer
{
private:
@ -1046,40 +1012,4 @@ inline void js_return(const v8::PropertyCallbackInfo<v8::Value>& info, JSSmart<N
js_return(args, ret); \
}
// TODO: remove this function
static void InsertToGlobal(const std::string& name, JSSmart<NSJSBase::CJSContext>& context, v8::FunctionCallback creator)
{
v8::Isolate* current = CV8Worker::GetCurrent();
v8::Local<v8::Context> localContext = context->m_internal->m_context;
v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(current, creator);
v8::MaybeLocal<v8::Function> oFuncMaybeLocal = templ->GetFunction(localContext);
v8::Maybe<bool> oResultMayBe = localContext->Global()->Set(localContext, CreateV8String(current, name.c_str()), oFuncMaybeLocal.ToLocalChecked());
}
// TODO: remove this function
using FunctionCreateTemplate = v8::Handle<v8::ObjectTemplate> (*)(v8::Isolate* isolate);
static void CreateNativeInternalField(void* native, FunctionCreateTemplate creator, const v8::FunctionCallbackInfo<v8::Value>& args,
const NSJSBase::IsolateAdditionalDataType& type = NSJSBase::iadtUndefined)
{
v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
if (NSJSBase::iadtUndefined != type)
{
if (CIsolateAdditionalData::CheckSingletonType(isolate, type))
{
args.GetReturnValue().Set(v8::Undefined(isolate));
return;
}
}
v8::Handle<v8::ObjectTemplate> oCurTemplate = creator(isolate);
v8::MaybeLocal<v8::Object> oTemplateMayBe = oCurTemplate->NewInstance(isolate->GetCurrentContext());
v8::Local<v8::Object> obj = oTemplateMayBe.ToLocalChecked();
obj->SetInternalField(0, v8::External::New(CV8Worker::GetCurrent(), native));
NSJSBase::CJSEmbedObjectPrivate::CreateWeaker(obj);
args.GetReturnValue().Set(obj);
}
#endif // _BUILD_NATIVE_CONTROL_V8_BASE_H_