diegoles / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.events.listen(form, 'foo', fn) failed #459

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1. prepare a form:
<form id="myform">
    <input name="pw">
</form>
2. listen some event use the closure-lib api:
goog.events.listen(form, 'submit', fn)
3. compile in advance mode

What is the expected output? What do you see instead?
failed to listen submit event.

What version of the product are you using? On what operating system?
- some particular version
- "5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like 
Gecko) Chrome/18.0.1025.165 Safari/535.19"

Please provide any additional information below.

## Cause
http://code.google.com/p/closure-library/source/browse/trunk/closure/goog/events
/events.js#215

if (src.addEventListener) { if (src == goog.global || !src.customEvent_) { src.addEventListener(type, proxy, capture); } }


It failed because the `customEvent_` prop compiled to `pw', and `myform.pw` is 
and input element.

I viewed the compiled results in  three environments, the `customEvent_` prop 
compiled to shorter names such as pw, tx, and Lx:

env 1:
if (a.addEventListener) {
    if (a == q || !a.pw)
        a.addEventListener(b, j, d)
}

env 2:
if (a.addEventListener) {
    if (a == q || !a.tw)
        a.addEventListener(b, j, d)
}

env 3:
if (a.addEventListener) {
    if (a == q || !a.Lx)
        a.addEventListener(b, j, d)
}

## Solve
In my opinion, I thinked about three ways to solve the problem:

- the safer one, do not detect expando, hide it

internelcache = {} var isCustomEvents = internel_cache[ element[goog.UIDPROPERTY] ][customEvents] if (isCustomEvents_) then ...


- ignore the naming and third-party libs

// strict type compare if ( element.cutomEvent === true) then … // or, disable compile it if ( element['customEvent] ) then...

Original issue reported on code.google.com by ambar....@gmail.com on 28 Apr 2012 at 11:13

GoogleCodeExporter commented 8 years ago
Wow, nice catch :)

Original comment by pall...@google.com on 30 Apr 2012 at 7:27

GoogleCodeExporter commented 8 years ago
events.js no longer adds properties to src.

Original comment by pall...@google.com on 30 Jul 2013 at 7:36