Instead of hardcoding each event, since there will be plenty more.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/xmlhttprequest.c | 47 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-)
diff --git a/dlls/mshtml/xmlhttprequest.c b/dlls/mshtml/xmlhttprequest.c index b9f6f1f..baef36e 100644 --- a/dlls/mshtml/xmlhttprequest.c +++ b/dlls/mshtml/xmlhttprequest.c @@ -94,12 +94,23 @@ static HRESULT return_nscstr(nsresult nsres, nsACString *nscstr, BSTR *p) return S_OK; }
+#define EVENTS_LIST \ + X(readystatechange) \ + X(load) + +#undef X +#define X(event) EVENT_##event, +enum { EVENTS_LIST }; +#undef X +#define X(event) L"" #event, +static const WCHAR *events[] = { EVENTS_LIST }; +#undef X + typedef struct { nsIDOMEventListener nsIDOMEventListener_iface; LONG ref; HTMLXMLHttpRequest *xhr; - BOOL readystatechange_event; - BOOL load_event; + DWORD events_mask; } XMLHttpReqEventListener;
struct HTMLXMLHttpRequest { @@ -115,21 +126,17 @@ struct HTMLXMLHttpRequest { static void detach_xhr_event_listener(XMLHttpReqEventListener *event_listener) { nsIDOMEventTarget *event_target; + DWORD events_mask, i; nsAString str; nsresult nsres;
nsres = nsIXMLHttpRequest_QueryInterface(event_listener->xhr->nsxhr, &IID_nsIDOMEventTarget, (void**)&event_target); assert(nsres == NS_OK);
- if(event_listener->readystatechange_event) { - nsAString_InitDepend(&str, L"onreadystatechange"); - nsres = nsIDOMEventTarget_RemoveEventListener(event_target, &str, &event_listener->nsIDOMEventListener_iface, FALSE); - nsAString_Finish(&str); - assert(nsres == NS_OK); - } - - if(event_listener->load_event) { - nsAString_InitDepend(&str, L"load"); + for(events_mask = event_listener->events_mask, i = 0; events_mask; events_mask >>= 1, i++) { + if(!(events_mask & 1)) + continue; + nsAString_InitDepend(&str, events[i]); nsres = nsIDOMEventTarget_RemoveEventListener(event_target, &str, &event_listener->nsIDOMEventListener_iface, FALSE); nsAString_Finish(&str); assert(nsres == NS_OK); @@ -941,18 +948,18 @@ static void HTMLXMLHttpRequest_bind_event(DispatchEx *dispex, eventid_t eid) { HTMLXMLHttpRequest *This = impl_from_DispatchEx(dispex); nsIDOMEventTarget *nstarget; - const WCHAR *type_name; nsAString type_str; nsresult nsres; + DWORD event;
TRACE("(%p)\n", This);
switch(eid) { case EVENTID_READYSTATECHANGE: - type_name = L"readystatechange"; + event = EVENT_readystatechange; break; case EVENTID_LOAD: - type_name = L"load"; + event = EVENT_load; break; default: return; @@ -966,25 +973,21 @@ static void HTMLXMLHttpRequest_bind_event(DispatchEx *dispex, eventid_t eid) This->event_listener->nsIDOMEventListener_iface.lpVtbl = &XMLHttpReqEventListenerVtbl; This->event_listener->ref = 1; This->event_listener->xhr = This; - This->event_listener->readystatechange_event = FALSE; - This->event_listener->load_event = FALSE; + This->event_listener->events_mask = 0; }
nsres = nsIXMLHttpRequest_QueryInterface(This->nsxhr, &IID_nsIDOMEventTarget, (void**)&nstarget); assert(nsres == NS_OK);
- nsAString_InitDepend(&type_str, type_name); + nsAString_InitDepend(&type_str, events[event]); nsres = nsIDOMEventTarget_AddEventListener(nstarget, &type_str, &This->event_listener->nsIDOMEventListener_iface, FALSE, TRUE, 2); nsAString_Finish(&type_str); if(NS_FAILED(nsres)) - ERR("AddEventListener(%s) failed: %08lx\n", debugstr_w(type_name), nsres); + ERR("AddEventListener(%s) failed: %08lx\n", debugstr_w(events[event]), nsres);
nsIDOMEventTarget_Release(nstarget);
- if(eid == EVENTID_READYSTATECHANGE) - This->event_listener->readystatechange_event = TRUE; - else - This->event_listener->load_event = TRUE; + This->event_listener->events_mask |= 1 << event; }
static void HTMLXMLHttpRequest_init_dispex_info(dispex_data_t *info, compat_mode_t compat_mode)