[webkit-help] Help: Why js can't receive the event from c++

Liu Robin liu.samba at gmail.com
Wed Aug 8 02:35:18 PDT 2012


Hi, guys
I extend webkit a custom js object inherited from EventTarget (codes listed
below). When it fire a event, the registered js function receive
nothing(the js function hasn't been invoked).
I logged in c++ codes(see "LOGT_" below), and the output value "ec" is as
same as its initial value.
I also logged in EventTarget.cpp for "EventTarget::fireEventListeners"
function, the logs  show that the code
 "registeredListener.listener->handleEvent(scriptExecutionContext(),
event);" is invoked.
I don't understand why the js callback function didn't be invoked while the
same js function was successfully invoked by js button object.
Any suggest is appreciated. Thank you.

//.idl
module window {

    interface [
        Conditional=MEDIA_STREAM,
        EventTarget,
        CallWith=ScriptExecutionContext,
        V8CustomConstructor
    ] SignalChannel {
        attribute EventListener onmessage;
        attribute EventListener onopen;

        void processSignalingMessage(in DOMString msg, in short
call_back_func_type);

        void connectToServer(in DOMString ip, in short port);

        // EventTarget interface
        void addEventListener(in DOMString type,
                              in EventListener listener,
                              in [Optional] boolean useCapture);
        void removeEventListener(in DOMString type,
                                 in EventListener listener,
                                 in [Optional] boolean useCapture);
        boolean dispatchEvent(in Event event)
            raises(EventException);
    };
}

//.h
class SignalChannel : public RefCounted<SignalChannel>,  public EventTarget,
{   ....
     DEFINE_ATTRIBUTE_EVENT_LISTENER(open);
     DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
}

//.cpp
void SignalChannel::OnSignedIn()
{
    sendMsgToJS(ON_SIGNEDIN, "");
}

void SignalChannel::sendMsgToJS(const int call_back_func_type, const String
msg)
{
    event = WebSocketMsgEvent::create(eventNames().messageEvent,
call_back_func_type, msg);
    context_->postTask(createCallbackTask(&start, this));
}

static void start(ScriptExecutionContext*, SignalChannel* obj)
{
    obj->run();
}

void SignalChannel::run()
{
    int ec = -1;
    dispatchEvent(event, ec);
    LOGT_("SignalChannel::run, dispatchEvent(event), errorcode:%d", ec);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-help/attachments/20120808/ac12933e/attachment-0001.html>


More information about the webkit-help mailing list