Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to create a V8::Persistent<Object> from a V8::Handle<Object>

Tags:

v8

embedded-v8

I just upgraded my V8 version to 3.20.16 (from some very old version). I can no longer use

Handle<Object> obj /* = ... */;
Persistent<Object> p = Persistent<Object>::New( obj );

to create a persistent handle to an object. The compiler suggests using static T* v8::Persistent<T>::New(v8::Isolate*, T*) [with T = v8::Object] instead. However, if I change my code to

Handle<Object> obj /* = ... */;
Persistent<Object> p = Persistent<Object>::New( Isolate::GetCurrent(), *obj );

the compiler complains that this function is private. How do I create a Persistent<Object> handle from a normal Handle<Object> now?

I've googled and the only thing I found was that the documentations seem to contradict each other:

  • https://developers.google.com/v8/embed#handles says that persistent handles are now created using the Persistence constructor
  • http://bespin.cz/~ondras/html/classv8_1_1Persistent.html indicates that Persistence<T>::New is still the way to go

thanks for any help in advance

like image 338
DeX3 Avatar asked Oct 04 '22 04:10

DeX3


1 Answers

There is a constructor that accepts normal Handle<T> you don't need to dereference it.

Persistent<Object>::New(Isolate::GetCurrent(), obj)

should work.

like image 197
Vyacheslav Egorov Avatar answered Oct 07 '22 20:10

Vyacheslav Egorov