Titanium is not a wrapper around a web view as stated before (though that accurately explains how Phonegap works). Jeff’s answer, linked in the question, is a technically correct explanation of how Titanium works, but here’s the best version I’ve heard so far, from Marshall Culpepper: It’s true that Titanium Mobile used the WebView (in both Android and iOS) in the pre-1.0 days. However, this is no longer true and hasn’t been since our 1.0 release is March 2010. Since 1.0, we’ve shipped two separate Javascript runtimes with our apps, and we are running the Javascript code directly without a WebView. Your entire app from start to finish is now controlled by JS, and we provide a comprehensive set of Native APIs that enable this. Everything from UI widgets (yes, including WebView), Core APIs like Networking, Filesystem, Database, all the way to OS-specific things like JS Activities in Android. On the JS runtime front, we’re shipping a forked version of WebKit’s JavaScriptCore in iOS and a snapshot of Rhino 1.7 R3 CVS for Android. What we actually do with your javascript source is dependent on the platform, but generally it breaks up like this:
There are many more details that I could dive into specifically on each of these points, but the point I wanted to drive home is that we no longer use the WebView as our Javascript engine. You can however still embed WebViews, and we provide some simple integration that allows you to call Titanium APIs from an embedded WebView.
|
|||||
|
What jhaynie is saying in your linked question is that Titanium interprets your JS code and converts it into something that is almost identical to Objective-C. In a web application, the browser reads and interprets your Javascript and runs associated native code (perhaps C++) internally. For instance, the browser might say, “This script is executing That means you won’t find anything that looks similar to what you originally wrote in your script. Anything that must be left to an interpreter is still processed and converted, and your symbols will change (e.g. a call to The usual use of Javascript is to have it interpreted real-time by a running program. That’s not what’s going on here, and that’s why you can’t see any trace of your script. Titanium performs the interpretation of your script as any other program would do (such as a web browser). It figures out what dependencies your script has on the Titanium API and sets that stuff up. It then maps your symbols directly into (in the case of the iPhone) Objective-C. A program usually would read in your script (which is a simply a String), interprets it, and runs C code to accomplish what your script asked for. Titanium does this before-hand to figure out what C code should be run, and does the conversion in advance. Based on the interpretation of your code and its dependencies on the Titanium API, Titanium figures out what code can be directly compiled, and what must not be compiled in order to allow for they full dynamics of Javascript. I don’t know how it chooses what does and doesn’t get compiled, but you could check out the source if you want to know that much detail. Code that must still be interpretted (left as a script) is still converted into symbols that result in more efficient mapping to native code. So it’s still an interpreted script, but that doesn’t mean it’s still Javascript. This means that these parts of your script will still run faster than usual Javascript. For iPhone, the compilable C is compiled with GCC to create a native binary. Now you have an app that you can run on your mobile device. Your compilable code has been compiled and runs at lightning speed, while the rest is converted and still interpreted in a more efficient way which runs at near lightning speed. 😛 I hope this makes sense now, because it’s all I’ve got! 😀
|