On Tue, Jul 16, 2013 at 11:44 PM, Mike Moening <[email protected]> wrote:
> I've got a simple example in yellow below of using Persistent that is broken
> with the recent API changes.
> Can somebody tell me how to re-write this so that it will compile with the
> new API changes?
> I'm a tad lost on how to make it work...
>
> I'm seeing many errors now:
>
> error C2664: 'v8::Persistent<T>::New' : cannot convert parameter 2 from
> 'v8::Persistent<T>' to 'v8::Context *'
>         with
>         [
>             T=v8::Context
>         ]
>         No user-defined-conversion operator available that can perform this
> conversion, or the operator cannot be called
> error C2248: 'v8::Persistent<T>::operator ->' : cannot access private member
> declared in class 'v8::Persistent<T>'
>         with
>         [
>             T=v8::Context
>         ]
>         C:\Dev\common\V8\include\v8.h(771) : see declaration of
> 'v8::Persistent<T>::operator ->'
>         with
>         [
>             T=v8::Context
>         ]
> error C2664: 'v8::Persistent<T>::New' : cannot convert parameter 2 from
> 'v8::Local<T>' to 'v8::Object *'
>         with
>         [
>             T=v8::Object
>         ]
>         No user-defined-conversion operator available that can perform this
> conversion, or the operator cannot be called
> error C2248: 'v8::Persistent<T>::Persistent' : cannot access private member
> declared in class 'v8::Persistent<T>'
>         with
>         [
>             T=v8::Context
>         ]
> v8.h(751) : see declaration of 'v8::Persistent<T>::Persistent'
>         with
>         [
>             T=v8::Context
>         ]
> -------------------------------------------------------------------
> The Code:
> class ExecState
> {
> private:
>     Persistent<Object>  m_oGlobal;
>
> protected:
>     Isolate*            m_pIsolate;
>     Persistent<Context> m_oContext;
>
> public:
>
>     void SetContext(Isolate* pIsolate, Persistent<Context> oContext)
>     {
>        m_pIsolate = pIsolate;
>        m_oContext  = Persistent<Context>::New(pIsolate, oContext);
>        m_oGlobal   = Persistent<Object>::New(pIsolate, oContext->Global());
>     }
>
>     Persistent<Context> GetContext() {return m_oContext;}
> };
>
> Thank you very much!
>
> Mike M

You replace this:

  pers = Persistent<Object>::New(isolate, obj);

With this:

  pers.Reset(isolate, obj);

Then, when you want to unwrap the object:

  Local<Object> obj = Local<Object>::New(isolate, pers);

You can take a shortcut that avoids the call to Local<T>::New() when
the persistent handle is strong:

  Local<Object> obj;
  if (pers.IsWeak())
    obj = Local<Object>::New(isolate, pers);  // same as before
  else
    obj = *reinterpret_cast<Local<Object>*>(&pers);

Yes, it looks very gnarly.

-- 
-- 
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to