[TIMOB-7413] Android: Function variables for Windows methods cannot be successfully invoked.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2012-02-08T17:20:47.000+0000 |
Affected Version/s | Release 1.8.0.1, Release 2.0.0, Release 1.8.1 |
Fix Version/s | n/a |
Components | Android |
Labels | qe-and012312 |
Reporter | Dustin Hyde |
Assignee | Bill Dawson |
Created | 2012-01-25T17:23:25.000+0000 |
Updated | 2013-05-01T20:06:59.000+0000 |
Description
The following app.js results in a runtime error in both runtimes:
/titanium_mobile_tests_internal/FeatureTest/Window/Window_timob7246
Note: Will investigate behavior on other devices in future.
var f = Ti.UI.createWindow().open;
f();
The error:
E/TiJSError( 764): (main) [512,1939] ----- Titanium Javascript Runtime Error -----
E/TiJSError( 764): (main) [1,1940] - In ti:/window.js:173,38
E/TiJSError( 764): (main) [0,1940] - Message: Uncaught TypeError: Cannot read property 'closed' of undefined
E/TiJSError( 764): (main) [0,1940] - Source: if (this.currentState != this.state.closed) {
E/V8Exception( 764): Exception occurred at ti:/window.js:173: Uncaught TypeError: Cannot read property 'closed' of undefined
It could be that this goes beyond windows methods... It's just that we know of this particular example.
Original Description
Running standard code causes internal runtime error. Log Attached. There is a similar crash in Rhino. Code works fine in iOS. Steps to Reproduce: 1. Run Code:
function Window1(){
var self = {};
var win = Ti.UI.createWindow();
var btn = Ti.UI.createButton({
title:'open',
left:20,
right:20,
height:44
});
btn.addEventListener('click', function(){
Window2().open();
});
win.add(btn);
self.open = win.open;
self.close = win.close;
return self;
}
function Window2(){
var self = {};
var win = Ti.UI.createWindow({
backgroundColor:'green'
});
win.addEventListener('open', function(){
win.animate({
left:10,
duration:300
}, function(){
Ti.API.info('complete');
});
});
var btn = Ti.UI.createButton({title:'close', left:20,right:20,height:44});
btn.addEventListener('click', function(){
win.close();
});
win.add(btn);
self.open = win.open;
self.close = win.close;
return self;
}
Window1().open();
Expected Result:
App should run.
Actual Result:
Runtime error.
Note: This test code exists in Attachments
File | Date | Size |
---|---|---|
android v8 runtime error.txt | 2012-01-25T17:23:25.000+0000 | 6992 |
Same test code as TIMOB-7246.
Changed the title and description to reflect underlying problem.
self.open = win.open
(and then callingself.open();
viaWindow1().open();
) is not really valid Javascript. (I mean, it's syntactically okay, but the hoped-for behavior shouldn't occur.) If it's working in iOS, then it's really kinda just luck, i.e., setting a window'sopen
method to a variable and having it work successfully must mean that the method itself somehow has a pre-bound context to it due to some kind of plumbing in our iOS implementation. This similar plain-old Javascript code makes the point:When you take
f
away fromo
it becomes "this-less", so to speak. :) So the result is:The same with
window.open
... Whenopen
is taken by itself, any code within it (when it is invoked) that tries to manipulate "its" window ... itsthis
... is going to fail. You can get the test to work by changing those lines that setself.open
andself.close
so they do something like:Closing.