v8::Object to void *

36 views
Skip to first unread message

Ubuntu Explorer

unread,
Jul 21, 2011, 3:55:14 AM7/21/11
to v8-users
I am using v8 in a custom C++ application with callbacks.
I need to pass a v8::Object as a (void *) to the callback and retrive
it back as a v8:Object in the callback.
How can I do this?

I can get the pointer, but how do I cast it back?

Regards,
UE

Stephan Beal

unread,
Jul 21, 2011, 4:19:15 AM7/21/11
to v8-u...@googlegroups.com
On Thu, Jul 21, 2011 at 9:55 AM, Ubuntu Explorer <ubuntue...@gmail.com> wrote:
I can get the pointer, but how do I cast it back?

Which pointer do you have? Object's API doesn't publish any members which give you access to the Object's underlying native void *. Objects themselves are _never_ passed around by pointer - only via Handle<Object> and friends.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/

Matthias Ernst

unread,
Jul 22, 2011, 12:10:11 PM7/22/11
to v8-u...@googlegroups.com
On Thu, Jul 21, 2011 at 9:55 AM, Ubuntu Explorer
<ubuntue...@gmail.com> wrote:
> I am using v8 in a custom C++ application with callbacks.
> I need to pass a v8::Object as a (void *) to the callback and retrive
> it back as a v8:Object in the callback.
> How can I do this?

The right way to do this IMHO would be to
a) pass around a "new
Persistent<Object>(Persistent<Object>::New(theLocalObjectHandle))"
b) (*static_cast<Persistent<Object>*>(data))->Get...
c) when done, "handlep->Dispose()" and "delete handlep" .

>
> I can get the pointer, but how do I cast it back?
>
> Regards,
> UE
>

> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users

Ubuntu Explorer

unread,
Jul 29, 2011, 4:57:19 AM7/29/11
to v8-users
Segfaults in step (b).

Could you tell me which Get() function I need to use?



On Jul 23, 1:10 am, Matthias Ernst <matth...@mernst.org> wrote:
> On Thu, Jul 21, 2011 at 9:55 AM, Ubuntu Explorer
>
Reply all
Reply to author
Forward
0 new messages