Snippets code from my daily experience

July 7, 2007

Short-circuits, innocent code and nsIDOMEvent targets

Filed under: firefox,flock,mozilla,xpcom,xul — dafi @ 6:08 pm

An user on AMI tells me that my bonsai RichFeedButton doesn’t work when installed together with another extension.

I install the offended extension and discover that RichFeedButton breaks this little jewel!

The solution was simple but the bug hunting was hard😦

The problem was into an innocent function associated with a listener that simply checks the nsIDOMEvent‘s target id and attrName as shown below
if (event.target.id == "xxx" && event.attrName == "yyy") {
...
}


For some motivations the “event.target” expression breaks the other extension.

I suspect event.target at some event stage isn’t valid and generates internally some error corrupting (???) the full event queue or simply I’m a bad programmer😦

The solution??

Simply swaps first equality test with second one

if (event.attrName == "yyy" && event.target.id == "xxx") {
...
}


The javascript short-circuit evaluation ensures me event.target.id is parsed only if first condition is true.🙂

Every day I learn something about XUL and its implementation…😉

Create a free website or blog at WordPress.com.

%d bloggers like this: