Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2975] Ti.UI.createWindow lost from scope in sub-context global reference

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDuplicate
Resolution Date2011-05-31T02:25:22.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsiOS, scope
ReporterJeffrey Clark
AssigneeTony Guntharp
Created2011-05-18T12:57:38.000+0000
Updated2016-03-08T07:47:59.000+0000

Description

Code below shows how calling Ti.UI.createWindow from a global object method when the method is called from sub-context reference it produces no error, only returning undefined. Expected would be a throw error or a TiUIWindow object returned in line 10 of app.js. Wether it should or not, this code works on 1.6.3.
Titanium.UI.setBackgroundColor('#000');

var app = {
    windows: [],
    Window: function(id) {
        if (!this.windows[id]) {
            this.windows[id] = Ti.UI.createWindow({url: id + '.js'});
            Ti.API.log('created window: ' + JSON.stringify(this.windows[id]));
            this.windows[id].app = this;
        }
        this.windows[id].open();
        return this.windows[id];
    }
};

app.Window('win').open();
({
    init: function() {
        var button = Ti.UI.createButton({ bottom: 0, title: "open win2", width: '100%', height: '10%' });
        button.addEventListener('click', function(e) {
            Ti.UI.currentWindow.app.Window('win2');
        });

        Ti.UI.currentWindow.add(button);
    }
}).init();
Log when button is clicked: {noformat} [INFO] scopebug/1.0 (1.7.0.a41eefd...) [DEBUG] Analytics is enabled = YES [DEBUG] loading: /Users/jclark/Documents/Titanium Studio Workspace/scopebug/Resources/app.js, resource: Users/jclark/Documents/Titanium Studio Workspace/scopebug/Resources/app_js [INFO] created window: {"orientationModes":null,"url":"win.js"} [DEBUG] application booted in 32.694995 ms [DEBUG] loading: /Users/jclark/Documents/Titanium Studio Workspace/scopebug/Resources/win.js, resource: Users/jclark/Documents/Titanium Studio Workspace/scopebug/Resources/win_js [INFO] created window: undefined [WARN] Exception in event callback. { expressionBeginOffset = 391; expressionCaretOffset = 407; expressionEndOffset = 418; line = 10; message = "Result of expression 'this.windows[id]' [undefined] is not an object."; name = TypeError; sourceId = 116344464; sourceURL = "file://localhost/Users/jclark/Documents/Titanium%20Studio%20Workspace/scopebug/Resources/app.js"; } {noformat}

Comments

  1. Paul Dowsett 2011-05-30

    This request is subjective - the log indicates that there is a problem with the code that needs to be resolved:
       [WARN] Exception in event callback. {
       expressionBeginOffset = 391;
       expressionCaretOffset = 407;
       expressionEndOffset = 418;
       line = 10;
       message = "Result of expression 'this.windows[id]' [undefined] is not an object.";
       name = TypeError;
       sourceId = 116344464;
       
    If you can demonstrate that the window is lost from scope in sub-context for *working code*, then we can progress this.
  2. Jeffrey Clark 2011-05-30

    You can see the code work without error by running it on Android (I should have made that clear in the report). It also works with earlier SDK versions on any platform. Either way, the scope issue was addressed in [Commit f5912fe7538947f0654a ](https://github.com/appcelerator/titanium_mobile/commit/f5912fe7538947f0654a971009533fbc6b044c58#commitcomment-407054).
  3. Paul Dowsett 2011-05-31

    Jeffrey, your code produced an error on Android when I tested it.
  4. Paul Dowsett 2011-05-31

    Resolved in ticket TIMOB-4074
  5. Paul Dowsett 2011-08-16

    Closed after 30 days of inactivity.

JSON Source