Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10412] MobileWeb: inject RTE for addEventListener call with null or undefined callback argument

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionWon't Fix
Resolution Date2017-06-26T22:15:22.000+0000
Affected Version/sRelease 2.1.0, Release 2.1.1, Release 2.1.2
Fix Version/sn/a
ComponentsMobileWeb
Labelsmobileweb, qe-sdk3.0.2
ReporterDustin Hyde
AssigneeEric Merriman
Created2012-08-12T17:38:09.000+0000
Updated2017-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:
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: Steps to Reproduce: 1. Run sample code:
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.

Comments

  1. Ivan Skugor 2012-08-13

    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.
  2. Dustin Hyde 2013-01-17

    Also add RTE if only one arg passed to addEventListener:
       win.addEventListener(function(){});
       
  3. Lee Morris 2017-08-24

    Mobile Web has been deprecated and will be removed in fixVersion 7.0.0.

JSON Source