store v8::Local in std containers like vector, unordered_map

16 views
Skip to first unread message

dark...@gmail.com

unread,
Nov 28, 2017, 3:20:00 AM11/28/17
to v8-users
I have code like:


v8
::Isolate::Scope isolate_scope(isolate);
v8
::HandleScope handle_scope(isolate);

v8
::Local<v8::Context> context = v8::Context::New(isolate);
v8
::Context::Scope context_scope(isolate);

{
  std
::vector<v8::Local<v8::Object> > ret = some_func();
  some_another_func(ret);
}


Is this code valid if container lifetime < lifetime of handle_scope? Is normal to store v8::Local in heap (like std containers do)?








Zac Hansen

unread,
Nov 29, 2017, 2:18:35 AM11/29/17
to v8-users
You'll want to put it in a global, not a local.   Globals outlive their lexical scope.

Just as a note, they're move-only.

Ben Noordhuis

unread,
Nov 29, 2017, 7:06:11 AM11/29/17
to v8-users
I believe that should work as long as you respect the lifetimes, yes.

Zac Hansen

unread,
Nov 29, 2017, 10:29:53 AM11/29/17
to v8-users
Oops, I didn't look closely enough at your example.   What ben said.

But if you want to store them longer, then you'll want the global.. 
Reply all
Reply to author
Forward
0 new messages