[TIMOB-4201] iOS: Ti.Platform.displayCaps is undefined if called from another context
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2011-06-20T09:59:37.000+0000 |
Affected Version/s | Release 1.7.0 |
Fix Version/s | Sprint 2011-24 |
Components | iOS |
Labels | regression |
Reporter | Jon Alter |
Assignee | Blain Hamon |
Created | 2011-05-24T11:27:14.000+0000 |
Updated | 2017-03-02T21:06:50.000+0000 |
Description
If you call Ti.Platform.displayCaps from a different context it says that it is undefined.
Step 1: run the code below
Step 2: notice the error when you click the button
Step 3: when you call the same function from the same context it works fine.
app.js
var app ={
getWidth : function(){
return Ti.Platform.displayCaps.platformWidth;
}
};
var win = Ti.UI.createWindow({
backgroundColor:'white',
fullscreen: true
});
var button = Ti.UI.createButton({
title: 'Width',
top: 100,
height: 40,
width: 200
});
button.addEventListener('click', function(e){
// alert( app.getWidth() );
var newWin = Ti.UI.createWindow({
backgroundColor:'blue',
url: 'win1.js'
});
newWin.app = app;
newWin.open();
});
win.add(button);
win.open();
win1.js
(function(){
var win = Ti.UI.currentWindow;
alert( win.app.getWidth() );
})();
Attachments
File | Date | Size |
---|---|---|
4201.crash | 2011-06-06T14:54:11.000+0000 | 20774 |
Screen shot 2011-05-24 at 11.12.44 AM.png | 2011-05-24T11:27:14.000+0000 | 37977 |
Associated Helpdesk Ticket
http://appc.me/c/APP-783212Second Associated Helpdesk Ticket
http://appc.me/c/APP-367438Where The Regression Happened
I just tested this on a build I made last night from the latest source, and it is working again. So sometime between 1.6.2 and 1.7.0.RC1 this regressed, and from 1.7.0.RC1 to now it was fixed.Works With
Titanium SDK version: 1.8.0 (05/24/11 16:32 ce16436) (pulled from GitHub, built myself)Tested With
If it's working now, let's call it fixed.
Now it crashes. Mon Jun 6 14:41:35 unknown ReportCrash[4648]
Tempted to mark this is invalid; For reasons of safety, creating proxies in the wrong context is disallowed (It leads to deadlocks or crashes) and so displayCaps, since it wasn't defined previously and would be in the wrong context, is not registered. If you absolutely must make cross-context calls, refer to Ti.Platform.displayCaps in the JS file beforehand.
No objections to marking this invalid. Creating a proxy cross-context (That includes accessing previously un-accessed globals) was intentionally disallowed to stop things from crashing.
Closed as invalid.