本文整理汇总了C++中CFXJS_ObjDefinition类的典型用法代码示例。如果您正苦于以下问题:C++ CFXJS_ObjDefinition类的具体用法?C++ CFXJS_ObjDefinition怎么用?C++ CFXJS_ObjDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CFXJS_ObjDefinition类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FXJS_NewFxDynamicObj
v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate,
IJS_Runtime* pIRuntime,
int nObjDefnID) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
if (nObjDefnID == -1) {
v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(pIsolate);
v8::Local<v8::Object> obj;
if (!objTempl->NewInstance(context).ToLocal(&obj))
return v8::Local<v8::Object>();
return obj;
}
FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
if (!pData)
return v8::Local<v8::Object>();
if (nObjDefnID < 0 || nObjDefnID >= CFXJS_ObjDefinition::MaxID(pIsolate))
return v8::Local<v8::Object>();
CFXJS_ObjDefinition* pObjDef =
CFXJS_ObjDefinition::ForID(pIsolate, nObjDefnID);
v8::Local<v8::Object> obj;
if (!pObjDef->GetInstanceTemplate()->NewInstance(context).ToLocal(&obj))
return v8::Local<v8::Object>();
obj->SetAlignedPointerInInternalField(0, new CFXJS_PerObjectData(nObjDefnID));
if (pObjDef->m_pConstructor)
pObjDef->m_pConstructor(pIRuntime, obj);
return obj;
}
示例2: FXJS_ReleaseRuntime
void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
v8::Global<v8::Context>& v8PersistentContext) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(pIsolate, v8PersistentContext);
v8::Context::Scope context_scope(context);
FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
if (!pData)
return;
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
if (!pObjDef->m_StaticObj.IsEmpty()) {
v8::Local<v8::Object> pObj =
v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj);
if (pObjDef->m_pDestructor)
pObjDef->m_pDestructor(pObj);
FXJS_FreePrivate(pObj);
}
delete pObjDef;
}
pIsolate->SetData(g_embedderDataSlot, nullptr);
delete pData;
}
示例3: isolate_scope
void CFXJS_Engine::DefineObjConst(int nObjDefnID,
const wchar_t* sConstName,
v8::Local<v8::Value> pDefault) {
v8::Isolate::Scope isolate_scope(m_isolate);
v8::HandleScope handle_scope(m_isolate);
CFX_ByteString bsConstName = CFX_WideString(sConstName).UTF8Encode();
CFXJS_ObjDefinition* pObjDef =
CFXJS_ObjDefinition::ForID(m_isolate, nObjDefnID);
pObjDef->GetInstanceTemplate()->Set(m_isolate, bsConstName.c_str(), pDefault);
}
示例4: FXJS_InitializeRuntime
void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
IFXJS_Runtime* pFXRuntime,
IFXJS_Context* context,
v8::Global<v8::Context>& v8PersistentContext) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
v8::Global<v8::ObjectTemplate>& globalObjTemp =
_getGlobalObjectTemplate(pIsolate);
v8::Local<v8::Context> v8Context = v8::Context::New(
pIsolate, NULL,
v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp));
v8::Context::Scope context_scope(v8Context);
FXJS_PerIsolateData::SetUp(pIsolate);
v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pFXRuntime);
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
CFX_WideString ws = CFX_WideString(pObjDef->objName);
CFX_ByteString bs = ws.UTF8Encode();
v8::Local<v8::String> objName =
v8::String::NewFromUtf8(pIsolate, bs.c_str(),
v8::NewStringType::kNormal,
bs.GetLength()).ToLocalChecked();
if (pObjDef->objType == FXJS_DYNAMIC) {
// Document is set as global object, need to construct it first.
if (ws.Equal(L"Document")) {
v8Context->Global()
->GetPrototype()
->ToObject(v8Context)
.ToLocalChecked()
->SetAlignedPointerInInternalField(0, new CFXJS_PrivateData(i));
if (pObjDef->m_pConstructor)
pObjDef->m_pConstructor(context, v8Context->Global()
->GetPrototype()
->ToObject(v8Context)
.ToLocalChecked(),
v8Context->Global()
->GetPrototype()
->ToObject(v8Context)
.ToLocalChecked());
}
} else {
v8::Local<v8::Object> obj = FXJS_NewFxDynamicObj(pIsolate, context, i);
v8Context->Global()->Set(v8Context, objName, obj).FromJust();
pObjDef->m_StaticObj.Reset(pIsolate, obj);
}
}
v8PersistentContext.Reset(pIsolate, v8Context);
}
示例5: FXJS_DefineObj
int FXJS_DefineObj(v8::Isolate* pIsolate,
const wchar_t* sObjName,
FXJSOBJTYPE eObjType,
FXJS_CONSTRUCTOR pConstructor,
FXJS_DESTRUCTOR pDestructor) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
FXJS_PerIsolateData::SetUp(pIsolate);
CFXJS_ObjDefinition* pObjDef = new CFXJS_ObjDefinition(
pIsolate, sObjName, eObjType, pConstructor, pDestructor);
return pObjDef->AssignID();
}
示例6: FXJS_DefineObjAllProperties
void FXJS_DefineObjAllProperties(v8::Isolate* pIsolate,
int nObjDefnID,
v8::NamedPropertyQueryCallback pPropQurey,
v8::NamedPropertyGetterCallback pPropGet,
v8::NamedPropertySetterCallback pPropPut,
v8::NamedPropertyDeleterCallback pPropDel) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
CFXJS_ObjDefinition* pObjDef =
CFXJS_ObjDefinition::ForID(pIsolate, nObjDefnID);
pObjDef->GetInstanceTemplate()->SetNamedPropertyHandler(pPropGet, pPropPut,
pPropQurey, pPropDel);
}
示例7: GetGlobalObjectTemplate
static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate(
v8::Isolate* pIsolate) {
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL)
return pObjDef->GetInstanceTemplate();
}
if (!g_DefaultGlobalObjectTemplate) {
g_DefaultGlobalObjectTemplate = new v8::Global<v8::ObjectTemplate>;
g_DefaultGlobalObjectTemplate->Reset(pIsolate,
v8::ObjectTemplate::New(pIsolate));
}
return g_DefaultGlobalObjectTemplate->Get(pIsolate);
}
示例8: FXJS_DefineObjProperty
void FXJS_DefineObjProperty(v8::Isolate* pIsolate,
int nObjDefnID,
const wchar_t* sPropName,
v8::AccessorGetterCallback pPropGet,
v8::AccessorSetterCallback pPropPut) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
CFX_ByteString bsPropertyName = CFX_WideString(sPropName).UTF8Encode();
CFXJS_ObjDefinition* pObjDef =
CFXJS_ObjDefinition::ForID(pIsolate, nObjDefnID);
pObjDef->GetInstanceTemplate()->SetAccessor(
v8::String::NewFromUtf8(pIsolate, bsPropertyName.c_str(),
v8::NewStringType::kNormal).ToLocalChecked(),
pPropGet, pPropPut);
}
示例9: FXJS_DefineObjMethod
void FXJS_DefineObjMethod(v8::Isolate* pIsolate,
int nObjDefnID,
const wchar_t* sMethodName,
v8::FunctionCallback pMethodCall) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
CFX_ByteString bsMethodName = CFX_WideString(sMethodName).UTF8Encode();
CFXJS_ObjDefinition* pObjDef =
CFXJS_ObjDefinition::ForID(pIsolate, nObjDefnID);
pObjDef->GetInstanceTemplate()->Set(
v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(),
v8::NewStringType::kNormal).ToLocalChecked(),
v8::FunctionTemplate::New(pIsolate, pMethodCall, v8::Local<v8::Value>(),
pObjDef->GetSignature()),
v8::ReadOnly);
}
示例10: FXJS_InitializeRuntime
void FXJS_InitializeRuntime(
v8::Isolate* pIsolate,
IJS_Runtime* pIRuntime,
v8::Global<v8::Context>* pV8PersistentContext,
std::vector<v8::Global<v8::Object>*>* pStaticObjects) {
if (pIsolate == g_isolate)
++g_isolate_ref_count;
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
v8::Local<v8::Context> v8Context =
v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate));
v8::Context::Scope context_scope(v8Context);
FXJS_PerIsolateData::SetUp(pIsolate);
v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
pStaticObjects->resize(maxID + 1);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
v8Context->Global()
->GetPrototype()
->ToObject(v8Context)
.ToLocalChecked()
->SetAlignedPointerInInternalField(0, new CFXJS_PerObjectData(i));
if (pObjDef->m_pConstructor)
pObjDef->m_pConstructor(pIRuntime, v8Context->Global()
->GetPrototype()
->ToObject(v8Context)
.ToLocalChecked());
} else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) {
CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode();
v8::Local<v8::String> m_ObjName =
v8::String::NewFromUtf8(pIsolate, bs.c_str(),
v8::NewStringType::kNormal,
bs.GetLength()).ToLocalChecked();
v8::Local<v8::Object> obj = FXJS_NewFxDynamicObj(pIsolate, pIRuntime, i);
v8Context->Global()->Set(v8Context, m_ObjName, obj).FromJust();
pStaticObjects->at(i) = new v8::Global<v8::Object>(pIsolate, obj);
}
}
pV8PersistentContext->Reset(pIsolate, v8Context);
}
示例11:
void V8TemplateMapTraits::Dispose(v8::Isolate* isolate,
v8::Global<v8::Object> value,
void* key) {
v8::Local<v8::Object> obj = value.Get(isolate);
if (obj.IsEmpty())
return;
CFXJS_Engine* pEngine = CFXJS_Engine::CurrentEngineFromIsolate(isolate);
int id = pEngine->GetObjDefnID(obj);
if (id == -1)
return;
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(isolate, id);
if (!pObjDef)
return;
if (pObjDef->m_pDestructor)
pObjDef->m_pDestructor(pEngine, obj);
CFXJS_Engine::FreeObjectPrivate(obj);
}
示例12: FXJS_ReleaseRuntime
void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
v8::Global<v8::Context>* pV8PersistentContext,
std::vector<v8::Global<v8::Object>*>* pStaticObjects) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext);
v8::Context::Scope context_scope(context);
FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
if (!pData)
return;
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
v8::Local<v8::Object> pObj;
if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
pObj =
context->Global()->GetPrototype()->ToObject(context).ToLocalChecked();
} else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) {
pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i));
delete pStaticObjects->at(i);
pStaticObjects->at(i) = nullptr;
}
if (!pObj.IsEmpty()) {
if (pObjDef->m_pDestructor)
pObjDef->m_pDestructor(pObj);
FXJS_FreePrivate(pObj);
}
}
if (pIsolate == g_isolate && --g_isolate_ref_count > 0)
return;
for (int i = 0; i < maxID; ++i)
delete CFXJS_ObjDefinition::ForID(pIsolate, i);
pIsolate->SetData(g_embedderDataSlot, nullptr);
delete pData;
}
示例13: GetGlobalObjectTemplate
static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate(
v8::Isolate* pIsolate) {
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL)
return pObjDef->GetInstanceTemplate();
}
if (!g_DefaultGlobalObjectTemplate) {
v8::Local<v8::ObjectTemplate> hGlobalTemplate =
v8::ObjectTemplate::New(pIsolate);
hGlobalTemplate->Set(
v8::Symbol::GetToStringTag(pIsolate),
v8::String::NewFromUtf8(pIsolate, "global", v8::NewStringType::kNormal)
.ToLocalChecked());
g_DefaultGlobalObjectTemplate =
new v8::Global<v8::ObjectTemplate>(pIsolate, hGlobalTemplate);
}
return g_DefaultGlobalObjectTemplate->Get(pIsolate);
}
示例14: FXJS_NewFxDynamicObj
v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate,
IFXJS_Context* pJSContext,
int nObjDefnID) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
if (nObjDefnID == -1) {
v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(pIsolate);
v8::Local<v8::Object> obj;
if (objTempl->NewInstance(context).ToLocal(&obj))
return obj;
return v8::Local<v8::Object>();
}
FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
if (!pData)
return v8::Local<v8::Object>();
if (nObjDefnID < 0 || nObjDefnID >= CFXJS_ObjDefinition::MaxID(pIsolate))
return v8::Local<v8::Object>();
CFXJS_ObjDefinition* pObjDef =
CFXJS_ObjDefinition::ForID(pIsolate, nObjDefnID);
v8::Local<v8::ObjectTemplate> objTemp =
v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
v8::Local<v8::Object> obj;
if (!objTemp->NewInstance(context).ToLocal(&obj))
return v8::Local<v8::Object>();
obj->SetAlignedPointerInInternalField(0, new CFXJS_PrivateData(nObjDefnID));
if (pObjDef->m_pConstructor)
pObjDef->m_pConstructor(
pJSContext, obj,
context->Global()->GetPrototype()->ToObject(context).ToLocalChecked());
return obj;
}