{ "id": "84530", "key": "TIMOB-7025", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "2", "description": "The problem described is an issue which will never be fixed.", "name": "Won't Fix" }, "resolutiondate": "2018-03-12T14:24:53.000+0000", "created": "2012-01-06T10:39:56.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [], "versions": [ { "id": "12580", "description": "Dual Runtime 1.8.0", "name": "Release 1.8.0.1", "archived": true, "released": true, "releaseDate": "2011-12-22" }, { "id": "14162", "description": "Release 3.1.0", "name": "Release 3.1.0", "archived": true, "released": true, "releaseDate": "2013-04-16" } ], "issuelinks": [], "assignee": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2018-03-12T15:55:10.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "h2. Problem\r\nA CommonJS (JavaScript) module which is require()d by a url-based Window (a window created with the 'url' property) from inside of that window's 'open' event tries to access Ti.Network.online, but instead a runtime error is produced:\r\n{code}\r\n[ERROR] Script Error = Result of expression 'Ti.Network' [undefined] is not an object.\r\n{code}\r\nPlease see the attached project (code repeated at the bottom of this description). It's a 5-step process to expose this error. The attached code has been minimized down from an actual project, so while it may look weird and seem to contain unnecessary steps, keep in mind that this is an excerpt from a real project with a real problem. I have reduced it down to the bare minimum necessary to reproduce the problem.\r\n\r\nThe normal workaround of adding a reference to \"Ti.Network\" in app.js does *not work* in this case.\r\n\r\nAnother problem that is evident in the example:\r\n- In app.js, you shouldn't have to reference \"Ti.App\" to get past the use of Ti.App in deep.js, but without that line in app.js, you get the same \"undefined\" error on Ti.App.\r\n\r\nThe problem does *not occur on Android*...the app works fine.\r\n\r\nh2. Steps to Reproduce\r\n- Unzip the attached project and run it to the iPhone simulator.\r\n- Look at the console log.\r\n- Right after \"** trying Network\", you will see this error\r\n{code}\r\n[ERROR] Script Error = Result of expression 'Ti.Network' [undefined] is not an object.\r\n{code}\r\n\r\nh2. Expected Result\r\nThe app should run without error and give the console message \"** Network is there!\".\r\n\r\nh2. Testcase Code\r\n{code:lang=javascript|title=app.js}\r\nvar Sequencer=require('Sequencer');\r\nSequencer.SetML('deep',require('deep'));\r\n\r\nTi.App; // without this here, the Ti.App in deep.js crashes.\r\nTi.Network; // this workaround doesn't work.\r\n\r\nvar w1=Ti.UI.createWindow({url:'win1.js'});\r\nw1.Sequencer=Sequencer;\r\nw1.open();\r\n{code}\r\n{code:title=Sequencer.js}\r\nTi.API.info('** Loading Sequencer');\r\n\r\nexports.ML={};\r\n\r\n\r\nexports.SetML=function(Prop,Val)\r\n{\r\n exports.ML[Prop]=Val;\r\n};\r\n\r\n\r\nexports.GetML=function()\r\n{\r\n return exports.ML;\r\n};\r\n{code}\r\n{code:title=deep.js}\r\nexports.RegisterWindowLoadEvent=function(TheWindow,OnLoadEvent)\r\n{\r\n Ti.App.CurrentWindow=TheWindow;\r\n Ti.App.CurrentWindow.addEventListener('open',OnLoadEvent);\r\n};\r\n{code}\r\n{code:title=win1.js}\r\nvar Sequencer=Ti.UI.currentWindow.Sequencer;\r\ndeep=Sequencer.GetML().deep;\r\n\r\ndeep.RegisterWindowLoadEvent(Ti.UI.currentWindow,MainWinLoad);\r\n\r\n\r\nfunction MainWinLoad()\r\n{\r\n Ti.API.info('** MainWinLoad');\r\n Ti.API.info('** step 1');\r\n var Killer=require('win2');\r\n Ti.API.info('** step 2');\r\n}\r\n{code}\r\n\r\n{code:title=win2.js}\r\nTi.API.info('** trying Network');\r\n if (Ti.Network.online)\r\n Ti.API.info('** Network is there!');\r\nTi.API.info('** done trying Network');\r\n{code}\r\n", "attachment": [ { "id": "24955", "filename": "TiNamespaceTest.zip", "author": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "created": "2012-01-06T10:39:56.000+0000", "size": 745908, "mimeType": "application/zip" } ], "flagged": false, "summary": "iOS: CommonJS - JavaScript module require()d by a url-based Window can't see Ti.Network", "creator": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "subtasks": [], "reporter": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "environment": "* iOS SDK 5.0\r\n* simulator\r\n* Mac OSX 10.7.2\r\n* Titanium SDK 1.8.0.1", "closedSprints": [ { "id": 1008, "state": "closed", "name": "2018 Sprint 06 SDK", "startDate": "2018-03-11T22:18:04.396Z", "endDate": "2018-03-25T22:18:00.000Z", "completeDate": "2018-03-25T21:52:36.683Z", "originBoardId": 216 } ], "comment": { "comments": [ { "id": "178363", "author": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "updateAuthor": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "created": "2012-01-06T10:44:35.000+0000", "updated": "2012-01-06T10:44:35.000+0000" }, { "id": "178439", "author": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "body": "If only all tickets were as well defined as this! Thank you, Shawn, I have escalated it immediately. :)", "updateAuthor": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "created": "2012-01-06T19:27:29.000+0000", "updated": "2012-01-06T19:27:29.000+0000" }, { "id": "178459", "author": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "body": "Thanks, Paul. It took me 1 whole work day to reduce this down to a small reproducable case from the actual project...it gave me one hell of a headache.", "updateAuthor": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "created": "2012-01-07T19:34:05.000+0000", "updated": "2012-01-07T19:34:05.000+0000" }, { "id": "182307", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Note that the following version of {{win1}} *does* work, for the same reasons that the above {{app.js}} does (namely, it preloads the module into the right context):\r\n\r\n{code:title=win1.js}\r\nvar Sequencer=Ti.UI.currentWindow.Sequencer;\r\ndeep=Sequencer.GetML().deep;\r\n\r\nTi.Network; // Pre-loads Ti.Network into this context\r\ndeep.RegisterWindowLoadEvent(Ti.UI.currentWindow,MainWinLoad);\r\n\r\n\r\nfunction MainWinLoad()\r\n{\r\n Ti.API.info('** MainWinLoad');\r\n Ti.API.info('** step 1');\r\n var Killer=require('win2');\r\n Ti.API.info('** step 2');\r\n}\r\n{code}\r\n\r\nThe problem is that the require()d module has its *page* in the context in which it was evaluated, which in this case, is always {{app.js}}. But the module is *executed* in {{win1.js}} and that's where the discrepancy comes from. This can only really be resolved by moving to single context, either within the app or changing the iOS infrastructure.\r\n\r\nCurrently there is still the restriction that modules must be require()ed in the context in which they are evaluated.", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-02-07T16:37:35.000+0000", "updated": "2012-02-07T16:39:55.000+0000" }, { "id": "248331", "author": { "name": "shameerj", "key": "shameerj", "displayName": "Shameer Jan", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Issue reproduces \n\nTested with\n\nTitanium Studio, build: 3.0.1.201212181159\nTitanium SDK version: 3.1.0 \nTitanium SDK version: 3.0.2 \niOS iPhone Simulator: iOS SDK version: 6.0\n", "updateAuthor": { "name": "shameerj", "key": "shameerj", "displayName": "Shameer Jan", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-04-19T09:22:19.000+0000", "updated": "2013-04-19T09:22:19.000+0000" }, { "id": "435487", "author": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "body": "url-based window is no longer supported", "updateAuthor": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-03-12T14:24:53.000+0000", "updated": "2018-03-12T14:24:53.000+0000" } ], "maxResults": 7, "total": 7, "startAt": 0 } } }