C ++ v8持久范围

时间:2016-10-09 08:21:36

标签: c++ v8 persistent

我可以某种方式持久v8::Isolate::Scopev8::HandleScopev8::Context::Scope吗?

我知道我可以创建持久化的上下文 - v8::Persistent<v8::Context, v8::CopyablePersistentTraits<v8::Context>> pContext(isolate, v8::Context::New(isolate, nullptr, global));和持久性函数,但是我可以实际保留上面列出的所有范围吗?

这样我就可以消除这样的范围堆栈变量:

v8::Isolate::Scope isolate_scope(isolate); // can I persist isolate_scope ?
v8::HandleScope scope(isolate); // can I persist handlescope ?

v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
    global->Set(v8::String::NewFromUtf8(isolate, "print"), v8::FunctionTemplate::New(isolate, Print));
    global->Set(v8::String::NewFromUtf8(isolate, "require"), v8::FunctionTemplate::New(isolate, Require));

v8::Persistent<v8::Context, v8::CopyablePersistentTraits<v8::Context>> pContext(isolate, v8::Context::New(isolate, nullptr, global));
v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, pContext);

v8::Context::Scope context_scope(context); // can I persist this ?

非常感谢。

0 个答案:

没有答案