Thanks Scott,

What if, instead of passing the context and function as arguments to
CallBack, I save them at a time when I have the V8 lock, as persistent
handles in a C++ object then pass the C++ object as the argument to
CallBack() ?

Cheers, Paul.

On Sep 8, 4:55 am, "Erik Corry" <[EMAIL PROTECTED]> wrote:
> That looks reasonable, except you need to hold the V8 lock in order to
> do anything with Handles, and that includes passing them as arguments
> to a method like CallBack. Passing them as arguments makes a copy of
> the handle.  So you can't take the V8 lock in CallBack, you have to
> already have it before calling.
>
>
>
> On Sun, Sep 7, 2008 at 10:51 AM,  <[EMAIL PROTECTED]> wrote:
>
> > On further inspection of the v8 source it appears that the correct
> > approach might be something of the form...
>
> > void CallBack( Handle<Context> _context, Handle<Object> _function,
> > arg1, arg2, arg3, ... )
> > {
> >    // ... we are on a different thread to that running the script...
> >    Locker locker;                              // gain a mutex on v8
> >    Scope scope( _context );              // Select the function's
> > context
> >    HandleScope handleScope;          // create a scope for locals
> >    const int argc = ??;
> >    // Compose args from arg1, arg2 ...
> >    Handle<Value> argv[ argc ] = { Handle<Type>( arg1),
> > Handle<Type>( arg2), ... };
> >    _funcation->Call( _context_->Global(), argc, argv );
> > }
>
> > On Sep 7, 8:48 am, [EMAIL PROTECTED] wrote:
> >> Thanks, I was aware of the need to use a Locker, I was unsure if any
> >> other precautions were necessary ?
>
> >> Paul.
>
> >> On Sep 7, 1:47 am, CGamesPlay <[EMAIL PROTECTED]> wrote:
>
> >> > The Locker is advisory, so you need to use it in all threads that will
> >> > be contending for v8.
>
> >> > On Sep 6, 4:01 am, [EMAIL PROTECTED] wrote:
>
> >> > > I have a server application where I handle incoming requests by
> >> > > passing them to a callback into a javascript function that exists in
> >> > > an already compiled and executing ( doing other things ) javascript
> >> > > context.
>
> >> > > Do I need to do anything special other than instantiating a v8::Locker
> >> > > prior to the call to the javascript function ? At the time of callback
> >> > > I have a reference to the running context.
>
> >> > > Cheers, Paul.
>
> --
> Erik Corry, Software Engineer
>
> Google Denmark ApS. CVR nr. 28 86 69 84
> c/o Philip & Partners, 7 Vognmagergade, P.O. Box 2227, DK-1018
> Copenhagen K, Denmark.
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to