5

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:

thanks for any help in advance

DeX3
  • 5,200
  • 6
  • 44
  • 68

1 Answers1

5

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

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

should work.

Vyacheslav Egorov
  • 10,302
  • 2
  • 43
  • 45
  • Yep, that did it, got confused as there is also no longer a public assignment operator and I had used that in the same line where I used the constructor. For cases where the `Persistent`-Handle already exists, `Persistent.Reset()` can be used. – DeX3 Aug 21 '13 at 07:07
  • 5
    I end up getting this page many times when I try to find out how to convert v8::Persistent to v8::Local. Here is how. `Persistent perMyFunc; Local localMyFunc = Local::New(isolate, perMyFunc);` – yoshi Feb 21 '14 at 03:17
  • 4
    If anyone is having a similar issue with more recent versions of V8 and this doesn't work, try [this answer](http://stackoverflow.com/a/22648552/1144176). – Jake Stoeffler Apr 02 '14 at 04:23