Thanks Ben. I want to re-use my context for performance reasons, but some JavaScript programs have constant global variables that cannot be re-defined, such as those declared with let or const. To work around this, I thought I could just evaluate each program in a closure by artificially enclosing the script with {}. Do you see any issue with doing it? Is there any better way to do so?
On Friday, May 11, 2018 at 5:50:07 AM UTC-7, Ben Noordhuis wrote: > > On Thu, May 10, 2018 at 10:24 PM, Jane Chen <jxch...@gmail.com > <javascript:>> wrote: > > Embedding v8 v5.3. > > > > Is there any way to reset global object for a context so that the > context > > can be re-used? > > > > How is Context::DetachGlobal() is meant to be used? > > > > Thanks, > > Jane > > You can't reset a context but you can detach the global object and > create a new context with it. It will revert to its pristine state in > the new context. In a nutshell: > > auto global = old_context->Global(); > old_context->Exit(); // Need to exit the context before detaching. > old_context->DetachGlobal(); > auto new_context = v8::Context::New(global->GetIsolate(), > v8::Local<v8::ObjectTemplate>(), global); > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.