On Mon, Sep 8, 2008 at 2:51 PM, <[EMAIL PROTECTED]> wrote:
>
> I'm calling a single line non-recursive javascript function that
> simple increments a counter and during the function call the exception
>
> RangeError : Maximum call stack size exceeded
>
> is raised.
This sounds very like a problem with locking. The max stack limit is
per-thread and one of the things the Locker class does is to set it up
with a sensible value for the current thread. If you have JS code
running in one thread (accidentally without a Locker) and you enter a
Locker in another thread then the first thread will fairly quickly
fail with this error.
There's an AssertIsLocked method on the Locker which you can call at
points where you make a call into JS to check that you actually have
the lock when you think you do. Also the Locker is reentrant so you
can add more if control flow is ambiguous.
> I'm guessing I need to set up a call stack frame on the foreign thread
> before calling into javascript ?
You have to construct a Locker object before calling into JavaScript.
>
> I've been sifting through the source but can't see an obvious way to
> do this, does anyone have some tips ?
>
> Paul S.
>
>
> On Sep 8, 6:54 am, "Erik Corry" <[EMAIL PROTECTED]> wrote:
>> T
>>
>> On Sun, Sep 7, 2008 at 10:41 PM, <[EMAIL PROTECTED]> wrote:
>>
>> > 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() ?
>>
>> That sounds fine.
>>
>>
>>
>>
>>
>> > 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.
>>
>> --
>> 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.
> >
>
--
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
-~----------~----~----~----~------~----~------~--~---