{ "id": "134125", "key": "TIMOB-17454", "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": null, "resolutiondate": null, "created": "2014-08-04T19:48:28.000+0000", "priority": { "name": "None", "id": "6" }, "labels": [], "versions": [ { "id": "15422", "description": "Release 3.3.0", "name": "Release 3.3.0", "archived": false, "released": true, "releaseDate": "2014-07-16" } ], "issuelinks": [], "assignee": null, "updated": "2018-02-28T20:03:59.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "h2. problem\r\n\r\n*DISCLAIMER:* This description is gonna sound confusing until you read the (simple) error and working cases.\r\n\r\nWhen a subcontext is created using the {{url}} property of a call to {{Ti.UI.createWindow()}}, you cannot assign {{this}} from within the subcontext to {{Ti.UI.currentWindow}} or it will result in a Kroll error. You can however assign a function that returns {{this}} in the subcontext, and then that function can be invoked in the original context to get the subcontext's {{this}}.\r\n\r\nI have not tested this on any other platforms.\r\n\r\nh2. error case\r\n\r\nh4. app.js\r\n\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({ url: 'context.js' }).open();\r\n{code}\r\n\r\nh4. context.js\r\n\r\n{code:javascript}\r\nTi.UI.currentWindow.__context = this;\r\n{code}\r\n\r\nh4. result\r\n\r\n{code}\r\n[DEBUG] 2014-08-04 15:34:40.449 conty[50898:4e0b] -[KrollContext target]: unrecognized selector sent to instance 0xd336f10\r\n[ERROR] Script Error {\r\n[ERROR] backtrace = \"#0 () at :0\";\r\n[ERROR] line = 6;\r\n[ERROR] message = \"-[KrollContext target]: unrecognized selector sent to instance 0xd336f10\";\r\n[ERROR] sourceId = 349233056;\r\n[ERROR] sourceURL = \"file:///Users/tlukasavage/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/5EB2D06A-CE21-4B5C-A0B1-CF9BB995DF8C/conty.app/context.js\";\r\n[ERROR] } \r\n{code}\r\n\r\nh2. working case\r\n\r\nThe working case here is a little longer so as to show not only does it not cause an error in context.js, but also that the context returned from it is able to be used and iterated over when returned to app.js.\r\n\r\nh4. app.js\r\n\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({ url: 'context.js' });\r\nwin.addEventListener('open', function() {\r\n\tTi.API.info(Object.keys(win.__context()));\r\n});\r\nwin.open();\r\n{code}\r\n\r\nh4. context.js\r\n\r\n{code:javascript}\r\nvar self = this;\r\nTi.UI.currentWindow.__context = function() {\r\n\treturn self;\r\n};\r\n{code}\r\n\r\nh4. result\r\n\r\n{code}\r\n[INFO] (\r\n[INFO] self,\r\n[INFO] Kroll,\r\n[INFO] setTimeout,\r\n[INFO] setInterval,\r\n[INFO] clearTimeout,\r\n[INFO] clearInterval,\r\n[INFO] require,\r\n[INFO] L,\r\n[INFO] alert,\r\n[INFO] Titanium,\r\n[INFO] Ti,\r\n[INFO] console\r\n[INFO] )\r\n{code}\r\n\r\nh2. Additional Notes\r\n\r\nThis is likely related to TIMOB-17449.", "attachment": [], "flagged": false, "summary": "iOS: Cannot use \"this\" for assignments in subcontext", "creator": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "TiSDK 3.3.0.GA\r\niOS 7.1 sim", "comment": { "comments": [], "maxResults": 0, "total": 0, "startAt": 0 } } }