本文整理汇总了C++中Persistent类的典型用法代码示例。如果您正苦于以下问题:C++ Persistent类的具体用法?C++ Persistent怎么用?C++ Persistent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Persistent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: customScriptInit
/*
* This is meant to run one time when the match creator is initialized.
*/
void customScriptInit()
{
Context::Scope context_scope(_script->getContext());
HandleScope handleScope;
Persistent<Object> plugin = getPlugin();
Handle<String> initStr = String::New("init");
if (plugin->Has(initStr) == false)
{
throw HootException("Error finding 'init' function.");
}
Handle<v8::Value> value = plugin->Get(initStr);
if (value->IsFunction() == false)
{
throw HootException("init is not a function.");
}
Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value);
Handle<Value> jsArgs[1];
int argc = 0;
HandleScope scope;
assert(_map.get());
OsmMapPtr copiedMap(new OsmMap(_map));
jsArgs[argc++] = OsmMapJs::create(copiedMap);
func->Call(plugin, argc, jsArgs);
//this is meant to have been set externally in a js rules file
_searchRadius = getNumber(plugin, "searchRadius", -1.0, 15.0);
}
示例2: script
MatchCreator::Description ScriptMatchCreator::_getScriptDescription(QString path) const
{
MatchCreator::Description result;
result.experimental = true;
shared_ptr<PluginContext> script(new PluginContext());
HandleScope handleScope;
Context::Scope context_scope(script->getContext());
script->loadScript(path, "plugin");
Persistent<Object> plugin = ScriptMatchVisitor::getPlugin(script);
Handle<String> descriptionStr = String::New("description");
if (plugin->Has(descriptionStr))
{
Handle<v8::Value> value = plugin->Get(descriptionStr);
result.description = toCpp<QString>(value);
}
Handle<String> experimentalStr = String::New("experimental");
if (plugin->Has(experimentalStr))
{
Handle<v8::Value> value = plugin->Get(experimentalStr);
result.experimental = toCpp<bool>(value);
}
QFileInfo fi(path);
result.className = (QString::fromStdString(className()) + "," + fi.fileName()).toStdString();
return result;
}
示例3: ENTER_V8
/*
* Class: org_appcelerator_kroll_runtime_v8_V8Runtime
* Method: nativeRunModule
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeRunModule
(JNIEnv *env, jobject self, jstring source, jstring filename, jobject activityProxy)
{
ENTER_V8(V8Runtime::globalContext);
titanium::JNIScope jniScope(env);
if (moduleObject.IsEmpty()) {
moduleObject = Persistent<Object>::New(
V8Runtime::krollGlobalObject->Get(String::New("Module"))->ToObject());
runModuleFunction = Persistent<Function>::New(
Handle<Function>::Cast(moduleObject->Get(String::New("runModule"))));
}
Handle<Value> jsSource = TypeConverter::javaStringToJsString(source);
Handle<Value> jsFilename = TypeConverter::javaStringToJsString(filename);
Handle<Value> jsActivity = TypeConverter::javaObjectToJsValue(activityProxy);
Handle<Value> args[] = { jsSource, jsFilename, jsActivity };
TryCatch tryCatch;
runModuleFunction->Call(moduleObject, 3, args);
if (tryCatch.HasCaught()) {
V8Util::openJSErrorDialog(tryCatch);
V8Util::reportException(tryCatch, true);
}
}
示例4: TEST
TEST(ImageResourceTest, SuccessfulRevalidationSvg) {
KURL url(ParsedURLString, "http://127.0.0.1:8000/foo");
ImageResource* imageResource = ImageResource::create(ResourceRequest(url));
Persistent<MockImageResourceClient> client =
new MockImageResourceClient(imageResource);
receiveResponse(imageResource, url, "image/svg+xml", svgImage());
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->hasImage());
EXPECT_FALSE(imageResource->getImage()->isNull());
EXPECT_EQ(1, client->imageChangedCount());
EXPECT_TRUE(client->notifyFinishedCalled());
EXPECT_FALSE(imageResource->getImage()->isBitmapImage());
EXPECT_EQ(200, imageResource->getImage()->width());
EXPECT_EQ(200, imageResource->getImage()->height());
imageResource->setRevalidatingRequest(ResourceRequest(url));
ResourceResponse response;
response.setURL(url);
response.setHTTPStatusCode(304);
imageResource->responseReceived(response, nullptr);
EXPECT_FALSE(imageResource->errorOccurred());
ASSERT_TRUE(imageResource->hasImage());
EXPECT_FALSE(imageResource->getImage()->isNull());
EXPECT_EQ(1, client->imageChangedCount());
EXPECT_TRUE(client->notifyFinishedCalled());
EXPECT_FALSE(imageResource->getImage()->isBitmapImage());
EXPECT_EQ(200, imageResource->getImage()->width());
EXPECT_EQ(200, imageResource->getImage()->height());
}
示例5: TEST
TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
{
ImageResource* cachedImage = ImageResource::create(ResourceRequest());
cachedImage->setStatus(Resource::Pending);
Persistent<MockImageResourceClient> client = new MockImageResourceClient(cachedImage);
// Send the image response.
cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-replace", 0, nullAtom, String()), nullptr);
Vector<unsigned char> jpeg = jpegImage();
cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAtom, String()), nullptr);
cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.size());
cachedImage->finish();
ASSERT_FALSE(cachedImage->errorOccurred());
ASSERT_TRUE(cachedImage->hasImage());
ASSERT_FALSE(cachedImage->getImage()->isNull());
ASSERT_TRUE(client->notifyFinishedCalled());
// The prune comes when the ImageResource still has clients. The image should not be deleted.
cachedImage->prune();
ASSERT_TRUE(cachedImage->hasClientsOrObservers());
ASSERT_TRUE(cachedImage->hasImage());
ASSERT_FALSE(cachedImage->getImage()->isNull());
// The ImageResource no longer has clients. The image should be deleted by prune.
client->removeAsClient();
cachedImage->prune();
ASSERT_FALSE(cachedImage->hasClientsOrObservers());
ASSERT_FALSE(cachedImage->hasImage());
ASSERT_TRUE(cachedImage->getImage()->isNull());
}
示例6: test_obj_setprop
void
test_obj_setprop()
{
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
Handle<Object> obj = Object::New();
Handle<String> k = String::New("someprop");
Handle<String> v = String::New("somevalue");
obj->Set(k, v);
Handle<Value> v2 = obj->Get(k);
String::AsciiValue vs(v);
String::AsciiValue vs2(v2);
do_check_eq(vs.length(), vs2.length());
do_check_eq(0, strcmp(*vs,*vs2));
context.Dispose();
}
示例7: Init
void Init (Handle<Object> target) {
initQueues();
freeThreadsQueue= nuQueue(-3); //闲置线程队列的 id为 -3
freeJobsQueue= nuQueue(-4); //闲置任务队列的id 为-4
HandleScope scope;
//static bool IsActive ()
//将返回当前V8的运行实例是否加锁
useLocker= v8::Locker::IsActive();
target->Set(String::NewSymbol("create"), FunctionTemplate::New(Create)->GetFunction());
target->Set(String::NewSymbol("createPool"), Script::Compile(String::New(kCreatePool_js))->Run()->ToObject());
//target->Set(String::NewSymbol("JASON"), Script::Compile(String::New(kJASON_js))->Run()->ToObject());
//设置js访问线程id的属性名为‘id’
id_symbol= Persistent<String>::New(String::NewSymbol("id"));
//定义 threadTemplate 的一些属性
threadTemplate= Persistent<ObjectTemplate>::New(ObjectTemplate::New());
threadTemplate->SetInternalFieldCount(1);
threadTemplate->Set(id_symbol, Integer::New(0));
threadTemplate->Set(String::NewSymbol("eval"), FunctionTemplate::New(Eval));
//threadTemplate->Set(String::NewSymbol("load"), FunctionTemplate::New(Load));
threadTemplate->Set(String::NewSymbol("emit"), FunctionTemplate::New(processEmit));
threadTemplate->Set(String::NewSymbol("destroy"), FunctionTemplate::New(Destroy));
}
示例8: NODE_PSYMBOL
// initialize a JS wrapper around this object
void NodeFSEvents::Initialize(Handle<Object> target)
{
HandleScope scope;
emit_sym = NODE_PSYMBOL("emit");
change_sym = NODE_PSYMBOL("fsevent");
Local<FunctionTemplate> t = FunctionTemplate::New(NodeFSEvents::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("FSEvents"));
Local<Function> constructor = constructor_template->GetFunction();
constructor->Set(String::New("kFSEventStreamEventFlagNone"), Integer::New(0x00000000));
constructor->Set(String::New("kFSEventStreamEventFlagMustScanSubDirs"), Integer::New(0x00000001));
constructor->Set(String::New("kFSEventStreamEventFlagUserDropped"), Integer::New(0x00000002));
constructor->Set(String::New("kFSEventStreamEventFlagKernelDropped"), Integer::New(0x00000004));
constructor->Set(String::New("kFSEventStreamEventFlagEventIdsWrapped"), Integer::New(0x00000008));
constructor->Set(String::New("kFSEventStreamEventFlagHistoryDone"), Integer::New(0x00000010));
constructor->Set(String::New("kFSEventStreamEventFlagRootChanged"), Integer::New(0x00000020));
constructor->Set(String::New("kFSEventStreamEventFlagMount"), Integer::New(0x00000040));
constructor->Set(String::New("kFSEventStreamEventFlagUnmount"), Integer::New(0x00000080));
constructor->Set(String::New("kFSEventStreamEventFlagItemCreated"), Integer::New(0x00000100));
constructor->Set(String::New("kFSEventStreamEventFlagItemRemoved"), Integer::New(0x00000200));
constructor->Set(String::New("kFSEventStreamEventFlagItemInodeMetaMod"), Integer::New(0x00000400));
constructor->Set(String::New("kFSEventStreamEventFlagItemRenamed"), Integer::New(0x00000800));
constructor->Set(String::New("kFSEventStreamEventFlagItemModified"), Integer::New(0x00001000));
constructor->Set(String::New("kFSEventStreamEventFlagItemFinderInfoMod"), Integer::New(0x00002000));
constructor->Set(String::New("kFSEventStreamEventFlagItemChangeOwner"), Integer::New(0x00004000));
constructor->Set(String::New("kFSEventStreamEventFlagItemXattrMod"), Integer::New(0x00008000));
constructor->Set(String::New("kFSEventStreamEventFlagItemIsFile"), Integer::New(0x00010000));
constructor->Set(String::New("kFSEventStreamEventFlagItemIsDir"), Integer::New(0x00020000));
constructor->Set(String::New("kFSEventStreamEventFlagItemIsSymlink"), Integer::New(0x00040000));
target->Set(String::NewSymbol("FSEvents"), constructor);
}
示例9: keyStr
Handle<Value> HashTable::Put(const Arguments& args) {
HandleScope scope;
HashTable *obj = ObjectWrap::Unwrap<HashTable>(args.This());
Local<Value> key = Local<Value>(args[0]);
Local<Value> value = Local<Value>(args[1]);
String::AsciiValue keyStr(key);
MapType::const_iterator itr = obj->map.find(std::string(*keyStr));
//overwriting an existing value
if(itr != obj->map.end()) {
Persistent<Value> oldValue = itr->second;
oldValue.Dispose(); //release the handle to the GC
}
Persistent<Value> persistent = Persistent<Value>::New(value);
obj->map.insert(std::pair<std::string, Persistent<Value> >(std::string(*keyStr), persistent));
//Return undefined
return scope.Close(Local<Value>());
}
示例10: WrappedContext
Handle<Value> WrappedScript::CreateContext(const Arguments& args)
{
HandleScope scope;
Persistent<Context> context = Context::New(NULL, WrappedContext::global_template);
WrappedContext *wrappedContext = new WrappedContext(context);
Local<Object> global = context->Global();
// Allow current context access to newly created context's objects.
context->SetSecurityToken(Context::GetCurrent()->GetSecurityToken());
// If a sandbox is provided initial the new context's global with it.
if (args.Length() > 0) {
Local<Object> sandbox = args[0]->ToObject();
Local<Array> keys = sandbox->GetPropertyNames();
for (uint32_t i = 0; i < keys->Length(); i++) {
Handle<String> key = keys->Get(Integer::New(i))->ToString();
Handle<Value> value = sandbox->Get(key);
if (value == sandbox) {
value = global;
}
global->Set(key, value);
}
}
return scope.Close(global);
}
示例11: DoneWithSuspectCallback
void NovaNode::DoneWithSuspectCallback(Persistent<Value> suspect, void *paramater) {
Suspect *s = static_cast<Suspect*>(paramater);
delete s;
suspect.ClearWeak();
suspect.Dispose();
suspect.Clear();
}
示例12: execute_string
extern "C" Handle<Value> execute_string(Persistent<Context> context,
const char* s,
bool* is_exception) {
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<String> source = String::New(s);
// Compile it
Handle<Script> script = Script::Compile(source);
// try-catch handler
TryCatch trycatch;
// Run it
Persistent<Value> result = Persistent<Value>::New(script->Run());
// Script->Run() returns an empty handle if the code threw an exception
if (result.IsEmpty()) {
*is_exception = true;
Handle<Value> exception = trycatch.Exception();
// String::AsciiValue exception_str(exception);
return Persistent<Value>::New(exception);
}
return result;
}
示例13: test_WriteAscii
void
test_WriteAscii()
{
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
char TEST_STRING[] = "this is a UTF-8 test! This is pi: π";
int TEST_LENGTH = strlen(TEST_STRING);
Handle<String> str = String::New(TEST_STRING);
char* buf = new char[TEST_LENGTH * 2];
// Iterate over the entire string and use it as the start.
int EXPECTED_LENGTH = TEST_LENGTH - 1; // We should drop the UTF-8 char.
for (int start = 0; start < TEST_LENGTH; start++) {
// Fill the buffer with 'a' to ensure there are no NULLs to start with.
fill_string(buf, 'a', TEST_LENGTH * 2);
int copied = str->WriteAscii(buf, start, TEST_LENGTH * 2);
do_check_eq(copied, EXPECTED_LENGTH - start);
do_check_eq(strlen(buf), EXPECTED_LENGTH - start);
}
delete[] buf;
context.Dispose();
}
示例14: ScanHelper_initOnLoad
void ScanHelper_initOnLoad(Handle<Object> target) {
Persistent<Object> scanObj = Persistent<Object>(Object::New());
Persistent<String> scanKey = Persistent<String>(String::NewSymbol("Scan"));
target->Set(scanKey, scanObj);
DEFINE_JS_FUNCTION(scanObj, "create", DBScanHelper_wrapper);
Persistent<Object> ScanHelper = Persistent<Object>(Object::New());
Persistent<Object> ScanFlags = Persistent<Object>(Object::New());
scanObj->Set(Persistent<String>(String::NewSymbol("helper")), ScanHelper);
scanObj->Set(Persistent<String>(String::NewSymbol("flags")), ScanFlags);
WRAP_CONSTANT(ScanFlags, SF_TupScan);
WRAP_CONSTANT(ScanFlags, SF_DiskScan);
WRAP_CONSTANT(ScanFlags, SF_OrderBy);
WRAP_CONSTANT(ScanFlags, SF_OrderByFull);
WRAP_CONSTANT(ScanFlags, SF_Descending);
WRAP_CONSTANT(ScanFlags, SF_ReadRangeNo);
WRAP_CONSTANT(ScanFlags, SF_MultiRange);
WRAP_CONSTANT(ScanFlags, SF_KeyInfo);
DEFINE_JS_INT(ScanHelper, "table_record", SCAN_TABLE_RECORD);
DEFINE_JS_INT(ScanHelper, "index_record", SCAN_INDEX_RECORD);
DEFINE_JS_INT(ScanHelper, "lock_mode", SCAN_LOCK_MODE);
DEFINE_JS_INT(ScanHelper, "bounds", SCAN_BOUNDS);
DEFINE_JS_INT(ScanHelper, "flags", SCAN_OPTION_FLAGS);
DEFINE_JS_INT(ScanHelper, "batch_size", SCAN_OPTION_BATCH_SIZE);
DEFINE_JS_INT(ScanHelper, "parallel", SCAN_OPTION_PARALLELISM);
DEFINE_JS_INT(ScanHelper, "filter_code", SCAN_FILTER_CODE);
}
示例15: if
/* called by the Java environment for objects that have been finalized */
void Conv::releaseV8Handle(JNIEnv *jniEnv, Persistent<Object> val, int type) {
HandleScope scope;
Handle<String> sHiddenKey;
Interface *interface = 0;
ArrayType *arr = 0;
if(type == -1) {
sHiddenKey = sObjectHiddenKey;
} else if(isArray(type)) {
arrayConv->GetRefsForComponentType(jniEnv, getComponentType(type), &arr);
sHiddenKey = arr->getHiddenKey();
} else if(isInterface(type)) {
interface = env->getInterface(getClassId(type));
sHiddenKey = interface->getHiddenKey();
}
//LOGV("releaseV8Handle; interface = %p; getting hidden value; sHiddenKey = %p\n", interface, sHiddenKey);
if(!sHiddenKey.IsEmpty()) {
Local<Value> hiddenVal = val->GetHiddenValue(sHiddenKey);
if(!hiddenVal.IsEmpty() && !hiddenVal->IsUndefined()) {
jobject extRef = (jobject)External::Unwrap(hiddenVal);
Conv::deleteGlobalRef(jniEnv, extRef);
val->DeleteHiddenValue(sHiddenKey);
if(interface) {
while((interface = interface->getParent())) {
val->DeleteHiddenValue(interface->getHiddenKey());
}
}
}
}
val.Dispose();
}