问题
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.
回答1:
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.).
来源:https://stackoverflow.com/questions/13842018/how-to-correctly-use-contextscope