{ "id": "93290", "key": "TIMOB-9560", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "13502", "description": "Sprint 2012-14 Core", "name": "Sprint 2012-14 Core", "archived": true, "released": true, "releaseDate": "2012-07-15" }, { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2012-07-12T14:48:24.000+0000", "created": "2012-06-14T16:44:35.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "core", "parity", "qe-testadded" ], "versions": [ { "id": "13273", "description": "Release 2.0.2", "name": "Release 2.0.2", "archived": false, "released": true, "releaseDate": "2012-05-31" } ], "issuelinks": [ { "id": "34706", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "inwardIssue": { "id": "125573", "key": "TIMOB-16351", "fields": { "summary": "Android: addEventListener via call()/apply() fails with exception", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "Medium", "id": "3" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "mstepanov", "key": "mstepanov", "displayName": "Max Stepanov", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2014-01-31T18:45:51.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "h2. Problem\r\n\r\nWhen a proxy's {{addEventListener}} or {{removeEventListener}} is called via Javascript's {{call()}} or {{apply()}} functions, as demonstrated in Test Case #1, you get the following exception on iOS:\r\n\r\n{code:lang=none}\r\n[ERROR] Script Error = 'undefined' is not a function (evaluating 'al.call(win, 'click', function(e) { alert('clicked window'); })') at app.js (line 5).\r\n{code}\r\n\r\nThe same call will work fine on Android and Mobileweb. On the other hand, calling these function without the call() function, as demonstrated in Test Case #2, fails on Android:\r\n\r\n{code:lang=none}\r\n[ERROR][TiJSError( 352)] (main) [607,2357] ----- Titanium Javascript Runtime Error -----\r\n[ERROR][TiJSError( 352)] (main) [3,2360] - In ti:/events.js:176,9\r\n[ERROR][TiJSError( 352)] (main) [7,2367] - Message: Uncaught TypeError: Object # has no method '_hasListenersForEventType'\r\n[ERROR][TiJSError( 352)] (main) [0,2367] - Source: \t\t\tthis._hasListenersForEventType(type, true);\r\n[ERROR][V8Exception( 352)] Exception occurred at ti:/events.js:176: Uncaught TypeError: Object # has no method '_hasListenersForEventType'\r\n{code} \r\n\r\nbut works on iOS and Mobileweb.\r\n\r\nh2. Test Case #1\r\n\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor: '#fff'\r\n});\r\nvar al = win.addEventListener;\r\nal.call(win, 'click', function(e) { alert('clicked window'); });\r\n// al.apply(win, ['click', function(e) { alert('clicked window'); }]);\r\nwin.open();\r\n{code}\r\n\r\nh2. Test Case #2\r\n\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor: '#fff'\r\n});\r\nvar al = win.addEventListener;\r\nal('click', function(e) { alert('clicked window'); });\r\nwin.open();\r\n{code}\r\n\r\nh2. Expected Result\r\n\r\nTest Case #1 for calling the {{addEventListener}} and {{removeEventListener}} functions should function properly on Android, iOS, and Mobileweb with {{call()}} and {{apply()}}.", "attachment": [], "flagged": false, "summary": "iOS: addEventListener via call()/apply() fails with exception", "creator": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Mac OSX 10.7.3\r\nTiSDK 2.0.2\r\niOS 5.1 iPhone simluator\r\nAndroid emulator 2.2\r\nChrome", "comment": { "comments": [ { "id": "198635", "author": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "body": "We need to add test case for apply too", "updateAuthor": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2012-06-14T20:20:58.000+0000", "updated": "2012-06-14T20:20:58.000+0000" }, { "id": "198647", "author": { "name": "ivan.skugor", "key": "ivan.skugor", "displayName": "Ivan Skugor", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "IMHO, second test case should not work since \"var al = win.addEventListener;\" unbinds \"win\" from that function (and changes \"this\" value to point to global object). Similar thing does not work in DOM environment. \r\n\r\n\r\nFirst test case opens Pandora's box. What if you do something like this:\r\n\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: '#fff'\r\n});\r\nvar button = Ti.UI.createButton({ title: 'Click me' });\r\nvar al = win.addEventListener;\r\nal.call(button, 'click', function(e) { alert('clicked button'); });\r\nwin.add(button);\r\nwin.open();\r\n{code}\r\n\r\nOr this:\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: '#fff'\r\n});\r\nvar customObject = {};\r\nvar al = win.addEventListener;\r\nal.call(customObject, 'customEvent', function(e) { alert('Test'); });\r\nwin.open();\r\n{code}\r\n\r\nThat should work in theory. In practice ... don't know. :)", "updateAuthor": { "name": "ivan.skugor", "key": "ivan.skugor", "displayName": "Ivan Skugor", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2012-06-14T23:59:57.000+0000", "updated": "2012-06-14T23:59:57.000+0000" }, { "id": "198661", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{{apply()}} added in Test Case #1. Ivan , you're probably right, I updated the Expected Result to indicate that Test Case #1 should work for all platforms.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-06-15T05:26:35.000+0000", "updated": "2012-06-15T05:26:35.000+0000" }, { "id": "202791", "author": { "name": "mstepanov", "key": "mstepanov", "displayName": "Max Stepanov", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Complete test cases:\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: '#fff'\r\n});\r\nvar al = win.addEventListener;\r\n\r\n// test 1\r\n//al.call(win, 'click', function(e) { alert('clicked window'); });\r\n\r\n// test 2\r\n//al.apply(win, ['click', function(e) { alert('clicked window'); }]);\r\n\r\n// test 3\r\n//al('click', function(e) { alert('clicked window'); });\r\n\r\n// test 4\r\n//Ti.UI.createWindow().addEventListener.call(win, 'click', function(e) { alert('clicked window'); });\r\n\r\n// test 5\r\n//Ti.UI.createWindow().addEventListener.apply(win, ['click', function(e) { alert('clicked window'); }]);\r\n\r\nwin.open();\r\n{code}", "updateAuthor": { "name": "mstepanov", "key": "mstepanov", "displayName": "Max Stepanov", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-07-11T16:28:28.000+0000", "updated": "2012-07-11T16:28:28.000+0000" }, { "id": "202793", "author": { "name": "mstepanov", "key": "mstepanov", "displayName": "Max Stepanov", "active": true, "timeZone": "America/Los_Angeles" }, "body": "PR pending https://github.com/appcelerator/titanium_mobile/pull/2541", "updateAuthor": { "name": "mstepanov", "key": "mstepanov", "displayName": "Max Stepanov", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-07-11T16:33:41.000+0000", "updated": "2012-07-11T16:33:41.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }