There is a global event manager in my application. To listen to an event, I 
need to specify the string name of the event and a lambda as callback function.

Event->Listen("WindowResize", [=]{
        // ...
});

Now I want to register to event in JavaScript, too. I show you my code below. 
There are some engine specific calls but it should be quite easy to understand.

v8::Handle<v8::Value> ModuleConsole::jsOn(const v8::Arguments& args)
{
        ModuleConsole *module = 
(ModuleConsole*)HelperScript::Unwrap(args.Data());
 
        if(args.Length() < 1 || !args[0]->IsString())
                return v8::Undefined();
        string name = *v8::String::Utf8Value(args[0]);
        
        if(args.Length() < 2 || !args[1]->IsFunction())
                return v8::Undefined();
        v8::Handle<v8::Function> callback = 
v8::Local<v8::Function>::Cast(args[1]->ToObject());
        
        if(callback.IsEmpty())
        {
                HelperDebug::Fail("script", "invalid callback function");
                return v8::Undefined();
        }
 
        v8::Persistent<v8::Function> persistent = 
v8::Persistent<v8::Function>::New(args.GetIsolate(), callback);
 
        module->Event->Listen(name, [&]{
                v8::HandleScope scope(args.GetIsolate());
                v8::TryCatch trycatch;
                persistent->Call(v8::Context::GetCurrent()->Global(), 0, NULL);
        });
 
        return v8::Undefined();
}

However, when I register to an event from JavaScript like below, there is a 
access violation at persistent->Call(...).

on('WindowResize', function () {
    print('Hello World!');
});

I am using a single JavaScript context in my application. What am I doing wrong?

-- 
-- 
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