Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17457] Android: JS Global Object - JS global object is undefined after calling Ti.App.addEventListener

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2014-09-18T19:19:38.000+0000
Affected Version/sRelease 3.2.3, Release 3.3.0
Fix Version/sn/a
ComponentsAndroid
Labelsqe-3.4.0
ReporterWilson Luu
AssigneePing Wang
Created2014-08-05T23:55:37.000+0000
Updated2017-03-24T17:10:25.000+0000

Description

*Details:* JS global object is undefined after calling Ti.App.addEventListener. *Note:* 1. This does *not* occur on iOS 2. This is not a regression with 3.2.3.GA *Steps to reproduce:* 1. Create a classic Titanium app 2. Download and unzip Archive.zip 3. Copy all contents in the Archive folder and paste them in the Resources directory from step 1 4. Next, install app to an Android device 5. After app is installed, press "Start Automation" button *Actual:* After test is complete, "Cannot read property" runtime error appears (see runtime_error.png attachment). The bug is in testExecutor.js on line 34. *Expected:* App should run without throwing a runtime error.

Attachments

FileDateSize
Archive.zip2014-08-05T23:55:37.000+00002884
runtime_error.png2014-08-05T23:55:37.000+0000124223

Comments

  1. jithinpv 2014-08-20

    Cannot reproduce Titanium SDK version 3.4.0 master, 3.3.0.GA, 3.2.3.GA, 3.2.2.GA Titanium Studio, build: 3.3.0.201407100905 Titanium Command-Line Interface CLI version 3.3.0, Android device : Motorola Moto G, Android version : 4.4.4
  2. Wilson Luu 2014-08-21

    Reopening ticket since I can still reproduce the issue. I noticed that I was missing one more step in the bug description which was to press the "Start Automation" button. Will update the bug description.
  3. Ping Wang 2014-09-18

    In the event listener of Ti.App, "this" means the Ti.App object, not the "global". That's why this.textArea inside the event listener is undefined. So "testExecutor.js" line 28-50 should be:
       var self = this;
       Ti.App.addEventListener(doneEvent, function(evt) {
           Ti.API.info("this = " + this);
           Ti.API.info("self = " + self);
           
           var tests = evt[overallTestsKey];
           var passed = evt[overallPassKey];
           
           // Use self instead of this
           self.textArea.value +=
               "Done! \n" + 
               "Total: " + tests + "\n" + 
               "Passed: " + passed + "\n\n";
           // workAround.textArea.value +=
               // "Done! \n" + 
               // "Total: " + tests + "\n" + 
               // "Passed: " + passed + "\n\n";
           
           overallTests += tests;
           overallPass += passed;
           
           executeNextTest();
       });
       
    Resolved the ticket as Invalid.
  4. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source