本文整理汇总了C++中Persistent::MarkIndependent方法的典型用法代码示例。如果您正苦于以下问题:C++ Persistent::MarkIndependent方法的具体用法?C++ Persistent::MarkIndependent怎么用?C++ Persistent::MarkIndependent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Persistent
的用法示例。
在下文中一共展示了Persistent::MarkIndependent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jsObjectToJavaFunction
jobject TypeConverter::jsObjectToJavaFunction(JNIEnv *env, v8::Handle<v8::Object> jsObject)
{
Persistent<Function> jsFunction = Persistent<Function>::New(Handle<Function>::Cast(jsObject));
jsFunction.MarkIndependent();
jlong ptr = (jlong) *jsFunction;
return env->NewObject(JNIUtil::v8FunctionClass, JNIUtil::v8FunctionInitMethod, ptr);
}
示例2: New
void Shape::New(const v8::FunctionCallbackInfo<Value>& args)
{
HandleScope scope;
Handle<Object> self = args.Holder();
Shape *shape;
if (args[0]->IsExternal())
{
Local<External> ext = Local<External>::Cast(args[0]);
void *ptr = ext->Value();
shape = static_cast<Shape*>(ptr);
shape->Wrap(args.Holder());
}
else
{
shapeObj *s = (shapeObj *)msSmallMalloc(sizeof(shapeObj));
msInitShape(s);
if(args.Length() >= 1) {
s->type = args[0]->Int32Value();
}
else {
s->type = MS_SHAPE_NULL;
}
shape = new Shape(s);
shape->Wrap(self);
}
/* create the attribute template. should use ObjectWrap in future */
Handle<ObjectTemplate> attributes_templ = ObjectTemplate::New();
attributes_templ->SetInternalFieldCount(2);
attributes_templ->SetNamedPropertyHandler(attributeGetValue,
attributeSetValue);
Handle<Object> attributes = attributes_templ->NewInstance();
map<string, int> *attributes_map = new map<string, int>();
attributes->SetInternalField(0, External::New(attributes_map));
attributes->SetInternalField(1, External::New(shape->get()->values));
attributes->SetHiddenValue(String::New("__parent__"), self);
if (shape->layer) {
for (int i=0; i<shape->layer->numitems; ++i) {
(*attributes_map)[string(shape->layer->items[i])] = i;
}
}
Persistent<Object> pattributes;
pattributes.Reset(Isolate::GetCurrent(), attributes);
pattributes.MakeWeak(attributes_map, attributeWeakCallback);
pattributes.MarkIndependent();
self->Set(String::New("attributes"), attributes);
}
示例3: readJsFile
Handle<Value> TiRootObject::_require(void* userContext, TiObject* caller, const Arguments& args)
{
HandleScope scope;
Local<Object> globalObject = TitaniumRuntime::getContenxt()->Global();
Handle<Value> nativeModule = TiModuleRegistry::GetModule(QString(*String::Utf8Value(args[0]->ToString())));
if(!nativeModule->IsUndefined())
{
return scope.Close(nativeModule);
}
QString fileName = Ti::TiHelper::QStringFromValue(args[0]).append(".js");
QString filePath = Ti::TiHelper::getAssetPath(fileName).prepend("app/native/");
Local<Value> existingModule = globalObject->GetHiddenValue(Ti::TiHelper::ValueFromQString(fileName)->ToString());
if(!existingModule.IsEmpty() && !existingModule->IsUndefined())
{
return scope.Close(existingModule);
}
QString js = readJsFile(filePath);
if(js.isEmpty()) {
ThrowException(String::New(
QString("Module not found ").append(fileName).toLocal8Bit().constData()
));
return scope.Close(Undefined());
}
js.prepend("(function(){"
"var __vars = {};"
"__vars.exports = {};"
"__vars.module = {exports:__vars.exports};"
"var module = __vars.module;"
"var exports = __vars.exports;");
js.append("\nreturn __vars.module.exports;"
"})();");
Handle<Script> script = Script::Compile(Ti::TiHelper::ValueFromQString(js)->ToString() , Ti::TiHelper::ValueFromQString(fileName));
TryCatch tryCatch;
if (script.IsEmpty())
{
Ti::TiErrorScreen::ShowWithTryCatch(tryCatch);
return scope.Close(Undefined());
}
Persistent<Value> result = Persistent<Value>::New(script->Run());
result.MarkIndependent();
if (result.IsEmpty())
{
Ti::TiErrorScreen::ShowWithTryCatch(tryCatch);
return scope.Close(Undefined());
}
globalObject->SetHiddenValue(Ti::TiHelper::ValueFromQString(fileName)->ToString(), result);
return scope.Close(result);
}