Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15009] LiveView: cannot see Alloy.Globals in modules when using LiveView

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-09-25T22:45:13.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 20, 2013 Sprint 20 Tooling, Release 3.2.0
ComponentsLiveView
Labelsqe-closed-3.2.0
ReporterDavide Cassenti
AssigneeChristian Sullivan
Created2013-08-29T15:00:03.000+0000
Updated2013-12-13T09:07:04.000+0000

Description

Problem description

When using LiveView, the global variable Alloy.Globals is not defined in modules. Disabling LiveView would not throw the error.

Code to reproduce

Create an Alloy app with this code: index.js
var win = Ti.UI.createWindow({
    backgroundColor:'#ffffff'
});

Ti.API.info(Alloy.Globals.test);

var Test = require('test');
new Test();

win.open();
lib/test.js
function Test() {
	Ti.API.info(Alloy.Globals.test);
};

module.exports = Test;
Add the global variable in alloy.js:
Alloy.Globals.test = "TEST";

Actual behavior

When running the app with LiveView on, the following error is thrown:
[INFO] :   [LiveView] Error Evaluating app.js @ Line: 2
[ERROR] :  TypeError: 'undefined' is not an object (evaluating 'Alloy.Globals')
[ERROR] :  File: app.js
[ERROR] :  Line: 2
[ERROR] :  SourceId: 323744256
[ERROR] :  Backtrace:
[ERROR] :   #0 Controller() at :21
[ERROR] :  #1 () at :214
[ERROR] :  #2 anonymous() at :15
[ERROR] :  #3 () at file://localhost/Users/dcassenti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/4822E77B-90A1-4555-8E22-DA55E5976F16/DavideAlloyTestApp.app/app.js:628
[ERROR] :  #4 () at file://localhost/Users/dcassenti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/4822E77B-90A1-4555-8E22-DA55E5976F16/DavideAlloyTestApp.app/app.js:493
[ERROR] :  #5 () at file://localhost/Users/dcassenti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/4822E77B-90A1-4555-8E22-DA55E5976F16/DavideAlloyTestApp.app/app.js:460
[ERROR] :  #6 () at file://localhost/Users/dcassenti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/4822E77B-90A1-4555-8E22-DA55E5976F16/DavideAlloyTestApp.app/app.js:392
[ERROR] :  #7 () at file://localhost/Users/dcassenti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/4822E77B-90A1-4555-8E22-DA55E5976F16/DavideAlloyTestApp.app/app.js:663
Without LiveView, the error is not shown. Note that in index.js the error is not thrown.

Comments

  1. Michael Xia 2013-09-03

    Marking TIMOB-14903 a duplicate of this since this has a simpler reproducible case.
  2. Christian Sullivan 2013-09-04

    I found an easy fix for this by removing all the vars from the variable declarations in the alloy generated app.js this allows for my original fix to work. To test do the following: 1. disable the alloy plugin so it doesn't overwrite you app.js 2. In your app.js generated by alloy remove var everywhere you see it. 3. Run
     $ ti build -p ios --liveview 
    This should fix the error
    [ERROR] TypeError: 'undefined' is not an object (evaluating 'Alloy.Globals')
  3. Tony Lukasavage 2013-09-05

    As stated in a conversation with [~csullivan] offline, we should in theory be able to do that, but I don't think I'm comfortable doing so on a patch release of Alloy. Given that there are known (and likely unknown) disparities between how global scope is handled on our runtimes/platforms, there seems a high change for some sort of regression to result from this, if not many. I think a change like this should likely wait for a minor release of Alloy, namely 1.3.0. If this is a course of action that we all agree on, a ticket should be logged to ALOY covering all the particulars and I can look into implementing it. After that comes the real task, which will be the extensive testing that will have to be done to ensure that everything still behaves as expected.
  4. Christian Sullivan 2013-09-05

    We might actually want to fix this via liveview so it also covers non alloy apps that rely on this same global scope feature/bug. I am looking into the fix now. I will have to make sure to only remove the var from local lexical scope vars
  5. Christian Sullivan 2013-09-24

    [~mxia] or [~tlukasavage] here is the pr on master https://github.com/appcelerator/liveview/pull/58 if one of you could please test to verify this does in fact solve the issue for you. I am unable to reproduce the above test case with this PR.
  6. Michael Xia 2013-09-25

    Yes, I'll do the testing here.
  7. Michael Xia 2013-09-25

    Local testing looks good. Merged the PR.
  8. Priya Agarwal 2013-12-13

    Tested Environment: Appcelerator Studio: 3.2.0.201312121648 SDK:3.2.0.v20131212122847 alloy: 1.3.0-cr acs: 1.0.10 npm: 1.3.2 titanium: 3.2.0-cr3 titanium-code-processor: 1.1.0-cr2 Xcode:5.0.2 OS: Mac OSX 10.9 Device: iphone simulator(v7.0.3) Could see Alloy.Globals declared values in app.js while liveview enabled. Hence verified and closing.

JSON Source