Bug 157375 - 4.0.1: addEventListener check fails (regression from 3.5)
Summary: 4.0.1: addEventListener check fails (regression from 3.5)
Status: RESOLVED NOT A BUG
Alias: None
Product: konqueror
Classification: Applications
Component: kjs (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-08 00:01 UTC by Luke-Jr
Modified: 2008-02-09 04:57 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke-Jr 2008-02-08 00:01:16 UTC
Version:            (using KDE 4.0.0)
Installed from:    Gentoo Packages

I use the following code in my AJAX webapp to determine the best method for trapping events. However, in KDE 4.0.1, the 3rd DOM-0 case is used, despite window.addEventListener evaluating to a Function object in the debugger at the time of the check (script startup).

if (window.addEventListener) {
	function trapEvent(o, t, func) {
		o.addEventListener(t, func, false);
	}
}
else
if (window.attachEvent) {
	function trapEvent(o, t, func) {
		o.attachEvent('on' + t, func);
	}
}
else
{
	function trapEvent(o, t, func) {
		o['on' + t] = func;
	}
}
Comment 1 Maksim Orlovich 2008-02-08 17:53:19 UTC
You're relying on a mozilla standards non-compliance there. There was a bug in KJS 3.x that made it sort-of-compatible with it, but it's now been changed to follow the standard, like every other web browser out there. Function declarations are specified by ECMA-262-3 to be processed at function entry time, the conditionals don't matter at all. See sections 10.1.3 and 13.


What you want to do is this:
if (window.addEventListener) { 
  var trapEvent = function trapEvent(o, t, func) { 
...

etc.
Comment 2 Luke-Jr 2008-02-08 22:27:32 UTC
Wouldn't that make 'trapEvent' scoped to just that 'if' statement?
Comment 3 Maksim Orlovich 2008-02-09 04:57:45 UTC
No. There are no local scopes in ECMAScript[1]. Anything defined with 'var' is scoped to the function. 

[1] Mozilla's JavaScript has non-standard extensions for those, of course.