W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2001

RE: [Events] removeEventListener on EventListeners currently bein g processed

From: Allen, Michael B (RSCH) <Michael_B_Allen@ml.com>
Date: Tue, 21 Aug 2001 20:05:16 -0400
Message-ID: <B27EB33BAB29D2119ABF0001FA7EF289053BF175@ewfd04.exchange.ml.com>
To: www-dom@w3.org
I realise this is a little OT but I thought some people might like to know that I have
found the implementation details of the "ugly" exception discussed in this thread
to be Not That Bad. In fact it is _less_ code than I posted before. Here's an
excerpt:

    /* Trigger capturers
     */
    evt->eventPhase = DOM_EVENT_CAPTURING_PHASE;
    for (i = 0; i < tcount && evt->sp == 0; i++) {
        DOM_EventListener cpy_of_listener_fns[targets[i]->listeners_len];
                                                        /* use stack ok? */
        t = targets[i];
        lcount = t->listeners_len;
        for (j = 0; j < lcount; j++) {           /* copy functions */
            e = t->listeners[j];
            cpy_of_listener_fns[j] = e ? e->listener_fn : NULL; 
        }

        evt->currentTarget = t;
        for (j = 0; j < lcount; j++) {
            e = t->listeners[j]; /* if NULL, listener has been removed -- skip it */
            if (e && cpy_of_listener_fns[j] && e->useCapture &&
                                    DOM_String_cmp(e->type, evt->type) == 0) { 
                cpy_of_listener_fns[j](evt);
            }
        }
    }

The key here is checking both the listener directly _and_ a copy made before
events are dispatched for a given set of listeners on a node. As you can see this
is pretty simple if arrays are used that can have NULL entries (holes are created
in the array if listeners are removed). The first check will fail if the listener has
been removed and the second will fail if there was no listener when the copy was
made (whereas it will not be null if a listener was _added_ after a copy was
made).

I have not tested this but as soon as I do you can view the whole implementation
when I upload domc-0.4.1 (http://auditorymodels.org/domc/).

Mike
Received on Tuesday, 21 August 2001 20:05:18 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:49 GMT