本文整理汇总了C++中CFXJS_ObjDefinition::GetInstanceTemplate方法的典型用法代码示例。如果您正苦于以下问题:C++ CFXJS_ObjDefinition::GetInstanceTemplate方法的具体用法?C++ CFXJS_ObjDefinition::GetInstanceTemplate怎么用?C++ CFXJS_ObjDefinition::GetInstanceTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFXJS_ObjDefinition
的用法示例。
在下文中一共展示了CFXJS_ObjDefinition::GetInstanceTemplate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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: DefineObjConst
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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例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) {
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);
}
示例8:
v8::Local<v8::Object> CFXJS_Engine::NewFxDynamicObj(int nObjDefnID,
bool bStatic) {
v8::Isolate::Scope isolate_scope(m_isolate);
v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
if (nObjDefnID == -1) {
v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(m_isolate);
v8::Local<v8::Object> obj;
if (!objTempl->NewInstance(context).ToLocal(&obj))
return v8::Local<v8::Object>();
return obj;
}
FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_isolate);
if (!pData)
return v8::Local<v8::Object>();
if (nObjDefnID < 0 || nObjDefnID >= CFXJS_ObjDefinition::MaxID(m_isolate))
return v8::Local<v8::Object>();
CFXJS_ObjDefinition* pObjDef =
CFXJS_ObjDefinition::ForID(m_isolate, nObjDefnID);
v8::Local<v8::Object> obj;
if (!pObjDef->GetInstanceTemplate()->NewInstance(context).ToLocal(&obj))
return v8::Local<v8::Object>();
CFXJS_PerObjectData* pPerObjData = new CFXJS_PerObjectData(nObjDefnID);
obj->SetAlignedPointerInInternalField(0, pPerObjData);
if (pObjDef->m_pConstructor)
pObjDef->m_pConstructor(this, obj);
if (!bStatic && FXJS_PerIsolateData::Get(m_isolate)->m_pDynamicObjsMap) {
FXJS_PerIsolateData::Get(m_isolate)->m_pDynamicObjsMap->set(pPerObjData,
obj);
}
return obj;
}