Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6231] Android: Ti.include doesn't work correctly in event handler

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-02-10T00:26:40.000+0000
Affected Version/sRelease 1.7.0, Release 1.7.5, Release 1.7.6, Release 1.8.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsparity
ReporterArthur Evans
AssigneePing Wang
Created2011-11-17T23:39:02.000+0000
Updated2012-02-10T00:26:40.000+0000

Description

This is related to the customer issue reported in TIMOB-1662. In trying to describe the behavior of Ti.include to resolve the related doc bug, TIMOB-4108, I came across the following parity issue: Ti.include works correctly when called from an event handler on iOS, but not on Android. Consider the following code: app.js:
var win1 = Titanium.UI.createWindow({
  title:'Window 1',
  backgroundColor:'blue',
  fullscreen:false
});

win1.open();



var testVar1 = "I can see the global context.";

var testMe = function(){
  Ti.API.info("In the function");
  Ti.include('include_test2.js');

  Ti.API.info("testVar2 defined in include_test2.js and output in app.js: " + testVar2);
};

testMe();
win1.addEventListener('click', function()
{
	Ti.API.info("In the event handler");
	testMe();
});
win1.fireEvent('click', {});
And the include file, include_test2.js:
var testVar2 = "Variable defined in the include file.";
Ti.API.info("In the include file.")
Ti.API.info("testVar1: " + testVar1);
On iOS, whether the testMe function is called directly or from inside the event handler, the include file can access the global context. On Android, though, it succeeds when the function is called directly, and fails with a reference error when called from the event handler.

Attached new test case (whole small runnable project).

Reproducible Steps

1. Press "Click button"

Attachments

FileDateSize
namespace2.zip2011-12-09T12:07:28.000+00002321943

Comments

  1. Ping Wang 2012-01-10

    Can not reproduce with the latest master.

JSON Source