[TIMOB-10412] MobileWeb: inject RTE for addEventListener call with null or undefined callback argument
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Low |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2017-06-26T22:15:22.000+0000 |
Affected Version/s | Release 2.1.0, Release 2.1.1, Release 2.1.2 |
Fix Version/s | n/a |
Components | MobileWeb |
Labels | mobileweb, qe-sdk3.0.2 |
Reporter | Dustin Hyde |
Assignee | Eric Merriman |
Created | 2012-08-12T17:38:09.000+0000 |
Updated | 2017-08-24T20:52:40.000+0000 |
Description
If addEventListener is called on a Titanium object with a null, undefined, or any non-function callback argument, a runtime error should be generated (as in Android and iOS). See runtime errors below.
This not a regression.
See API Docs below.
API Docs 2.1:
Steps to Reproduce:
1. Run sample code:
Methods
Titanium.Proxy
addEventListener( String name, Callback<Object> callback )
Adds the specified callback as an event listener for the named event.
Parameters
name : String
Name of the event.
callback : Callback<Object>
Callback function to invoke when the event is fired.
Returns
void
iOS Runtime Error:
[ERROR] Invalid type passed to function. expected: KrollCallback, was: NSNull in -[TiProxy addEventListener:] (TiProxy.m:764)
[ERROR] Script Error = Invalid type passed to function. expected: KrollCallback, was: NSNull in -[TiProxy addEventListener:] (TiProxy.m:764) at app.js (line 1).
Android Runtime Error:
[ERROR][TiJSError( 487)] (main) [345,1716] ----- Titanium Javascript Runtime Error -----
[ERROR][TiJSError( 487)] (main) [0,1716] - In ti:/events.js:141,10
[ERROR][TiJSError( 487)] (main) [0,1716] - Message: Uncaught Error: addListener only takes instances of Function. The listener for event "" is "object"
[ERROR][TiJSError( 487)] (main) [1,1717] - Source: throw new Error('addListener only takes instances of Function. The listener
[ERROR][V8Exception( 487)] Exception occurred at ti:/events.js:141: Uncaught Error: addListener only takes instances of Function. The listener for event "" is "object"
MobileWeb Runtime Error:
var win = Ti.UI.createWindow({
backgroundColor:'green'
});
win.addEventListener('click', undefined);
win.open();
Actual Result:
No runtime error. Program executes without interference.
Expected Result:
Runtime error.
2. If no runtime error is generated, click on green background.
Expected Result:
Click events should fire, runtime errors should generate.
I'm strongly against expected result. :) Silent fail (and passing wrong parameter is developer's error) is the worst possible scenario for developers (because, we cannot know something went wrong if it failed silently). It's better to throw an exception than to do nothing. Making that exception catchable is proper way to handle this kind of fail in production environment.
Also add RTE if only one arg passed to addEventListener:
Mobile Web has been deprecated and will be removed in fixVersion 7.0.0.