如何正确使用 Context::Scope ? [英] How to correctly use Context::Scope ?

查看:55
本文介绍了如何正确使用 Context::Scope ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何正确使用 Context::Scope ?我是在方法/函数范围内分配它,同时实际执行某些东西,还是可以在 Context 对象旁边拥有它的全局副本?文档对此不是很清楚.我想创建一个全局 Application 类并将所有持久性内容保留在那里,不确定是否可以将上下文范围放在那里.

How to correctly use Context::Scope ? Do i allocate it while within a method/function scope while actually executing something or can i have a global copy of it next to the Context object ? The documentation isn't very clear on that. I want to make a global Application class and keep all the persistent stuff there not sure if i can put context scope there.

推荐答案

Context::Scope 必须在调用链之外的调用堆栈上分配.你想要做的是使用一个 Persistent 来全局存储你的 Context 对象,然后当你创建一个 Context::Scope输入 JavaScript 调用堆栈.V8 的所有范围对象(HandleScopeIsolate::Scope 等)都是这种情况.

Context::Scope has to be allocated on the call stack outside of your call chain. What you want to do is use a Persistent<Context> to store your Context object globally, and then create a Context::Scope when you enter a JavaScript call stack. This is the case for all of V8's scope objects (HandleScope, Isolate::Scope, etc.).

这篇关于如何正确使用 Context::Scope ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆