[TIMOB-6458] iOS: CommonJS - native JavaScript modules for iOS encounter errors when referencing classes/objects in the Ti namespace
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2012-02-10T00:21:43.000+0000 |
Affected Version/s | Release 1.8.0.1 |
Fix Version/s | n/a |
Components | iOS |
Labels | dr-list |
Reporter | Dan Eyles |
Assignee | Stephen Tramer |
Created | 2011-12-04T18:02:15.000+0000 |
Updated | 2012-02-10T00:21:43.000+0000 |
Description
It looks like Titanium is having issues resolving symbols in the Ti/Titanium namespace referenced in code that is interpreted at run time. This issue has been observed when creating CommonJS native JavaScript modules for iOS.
To replicate the issue create a native JavaScript module for iOS using the steps described in the developer guide:
http://wiki.appcelerator.org/display/guides/iOS+Module+Development+Guide#iOSModuleDevelopmentGuide-BuildingJavaScriptNativeModules
In the CommonJS code for the module attempt to open a file using the following code:
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + "foo.txt");
This code will execute without issue in the iOS simulator, however on the handset it will cause your application to crash. Putting a reference to the Ti.Filesystem namespace in the app.js file before the module is loaded "fixes" the issue on the handset, e.g.:
Ti.API.info(Ti.Filesystem.applicationDataDirectory);
var o = require('your.module.name');
It appears that Titanium needs to resolve these symbols in code loaded in the main interpreter context before they can be used in code that is interpreted at run time.
Sample crash log:
[INFO] [object ComIrlgamingJsondbModule] loaded
[INFO] exists: file://localhost/var/mobile/Applications/90997746-D7DD-43A3-B0B5-900938FD7683/Documents/test.json
[INFO] exists: file://localhost/var/mobile/Applications/90997746-D7DD-43A3-B0B5-900938FD7683/Documents/test2.json
[ERROR] Script Error = {
expressionBeginOffset = 9119;
expressionCaretOffset = 9127;
expressionEndOffset = 9140;
line = 32;
message = "Result of expression 'Ti.Utils' [undefined] is not an object.";
name = TypeError;
sourceId = 65639384;
}.
[DEBUG] application booted in 310.460985 ms
2011-12-04 08:37:20.894 Kiosk[14350:707] -[__NSCFDictionary
sizeWithFont:constrainedToSize:lineBreakMode:]: unrecognized selector
sent to instance 0x1062bd0
[ERROR] The application has crashed with an unhandled exception. Stack trace:
0 CoreFoundation 0x3539e8bf __exceptionPreprocess + 162
1 libobjc.A.dylib 0x35e191e5 objc_exception_throw + 32
2 CoreFoundation 0x353a1acb -[NSObject
doesNotRecognizeSelector:] + 174
3 CoreFoundation 0x353a0945 ___forwarding___ + 300
4 CoreFoundation 0x353a17b8 __forwarding_prep_1___ + 56
5 Kiosk 0x000bf3cd -[TiErrorController
dynamicLabel:width:height:fontSize:bottom:] + 164
6 Kiosk 0x000bfae9 -[TiErrorController
loadView] + 1184
7 UIKit 0x376c378b -[UIViewController view] + 50
8 UIKit 0x376cdd53 -[UIViewController
viewControllerForRotation] + 58
9 UIKit 0x376cdcc1 -[UIViewController
_visibleView] + 100
10 UIKit 0x37808d5f
-[UIClientRotationContext
initWithClient:toOrientation:duration:andWindow:] + 334
11 UIKit 0x3776dd87 -[UIWindow
_setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:]
+ 798
12 UIKit 0x3776cdb7
-[UIWindowController
transition:fromViewController:toViewController:target:didEndSelector:]
+ 1810
13 UIKit 0x3776c14f -[UIViewController
presentViewController:withTransition:completion:] + 3122
14 UIKit 0x377c6d97 -[UIViewController
presentModalViewController:animated:] + 30
15 Kiosk 0x000be199 -[TiApp
showModalError:] + 240
16 CoreFoundation 0x352fd22b -[NSObject
performSelector:withObject:] + 42
17 Foundation 0x313e5757
__NSThreadPerformPerform + 350
18 CoreFoundation 0x35372b03
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
19 CoreFoundation 0x353722cf __CFRunLoopDoSources0 + 214
20 CoreFoundation 0x35371075 __CFRunLoopRun + 652
21 CoreFoundation 0x352f44dd CFRunLoopRunSpecific + 300
22 CoreFoundation 0x352f43a5 CFRunLoopRunInMode + 104
23 GraphicsServices 0x31ddefed GSEventRunModal + 156
24 UIKit 0x376b8743 UIApplicationMain + 1090
25 Kiosk 0x00003d6f main + 66
26 Kiosk 0x00003674 start + 40
2011-12-04 08:37:20.948 Kiosk[14350:707] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSCFDictionary sizeWithFont:constrainedToSize:lineBreakMode:]:
unrecognized selector sent to instance 0x1062bd0'
*** First throw call stack:
(0x3539e8bf 0x35e191e5 0x353a1acb 0x353a0945 0x353a17b8 0xbf3cd
0xbfae9 0x376c378b 0x376cdd53 0x376cdcc1 0x37808d5f 0x3776dd87
0x3776cdb7 0x3776c14f 0x377c6d97 0xbe199 0x352fd22b 0x313e5757
0x35372b03 0x353722cf 0x35371075 0x352f44dd 0x352f43a5 0x31ddefed
0x376b8743 0x3d6f 0x3674)
terminate called throwing an exception(gdb)
Attachments
File | Date | Size |
---|---|---|
timob6458.tar.gz | 2011-12-19T17:14:10.000+0000 | 1591260 |
Looks like this is the exact same issue as TIMOB-6457. Suggesting they be resolved together.
Stephen, Are you sure? This has to do with compiled modules, and the other with normal CommonJS...
Looks like this is a dupe and should be tested at the same time as TIMOB-5815.
Attached complete test for this bug.
I am getting failure to resolve Ti.Network inside a commonJS module, and the workaround of referencing Ti.Network in app.js is NOT solving this one.
^^^ I've been looking into this Ti.Network issue, and it's a little more complicated. There are several levels of require() being used. I'm trying to cut a test project down to a minimum...will post it here soon.
Ti.Network has some additional symbols associated with it. In particular you may need to explicitly create sockets or HTTPClient objects in addition to just declaring that you use Ti.Network, due to how conditional compilation on iOS behaves. There is a fix for this issue pending, but it does require module redistribution.
My app does use Ti.Network.createHTTPClient(), although it is done in a commonJS unit (which is required() by another commonJS unit that is required() in app.js). What is "module redistribution"? And can you post a comment to this JIRA ticket when the continuous build that includes this fix is ready, so I can try it out?
This ticket will be marked RESOLVED/FIXED when the fix is available in CI off master. If you're referring to compiled CommonJS modules, those modules are what need to be redistributed. If you're using a raw .js file, please provide some details about where the file is located (it should be in the Resources directory, which means it will be picked up for compile-time checking).
If this is a bug which is occurring with pure JS modules included via require() that are located in the
Resources
, then it likely is something different. I'll inform community that they should bring the bug into our database.It *is* with pure JS modules included via require() that are located in Resources.
Closing as a dupe of TIMOB-5815