Blog Home

iOS and JavaScript - for Real this Time!

Less talk, more action – Apple just approved two of my JavaScript games for the AppStore: Biolab Disaster and Drop. Both are free; go check them out. You can also play them in your browser here and here.

Both games are pretty simple (the source for Drop is only 300 odd lines long) and written with my JavaScript Game Engine Impact.

These are certainly not the first games written in JavaScript to be available in the AppStore. Tools like AppMobi, PhoneGap or Titanium make it easy to bundle some HTML pages and JavaScript together in an App and display them in a UIWebView, which is basically just a browser window (correction: Titanium doesn't use a UIWebView but instead has some native bindings). Games written with Impact already work okay-ish in the iPhone's browser and thus also in AppMobi and PhoneGap.

So what's so special about these two games now? They don't use PhoneGap or Titanium. They don't even use a UIWebView. Instead, they bypass the iPhone's browser altogether and use Apple's JavaScript interpreter (JavaScriptCore) directly. All graphics are rendered with OpenGL instead of in a browser window and all sound and music is played back with OpenAL instead of… well, having no sound at all.

What makes this possible is a compatibility layer that mimics the HTML5 Canvas and Audio APIs but is implemented with OpenGL and OpenAL behind the scenes. Think of it as a browser that can only display a Canvas element and play Audio elements, but does not render generic HTML pages. A browser perfectly suited for HTML5 games.

This means you can take your JavaScript games written for Impact and run them on iOS with perfect sound and touch input and way better drawing performance than with Mobile Safari. Now, to be clear, I only implemented a bare minimum of the Canvas API - just enough to be able to run Impact. The whole thing is still in a very experimental state.

If you have a license for Impact you will find the complete source code for this all on your download page. I also wrote some basic documentation to get you started. In theory, you don't have to know anything about Objective-C to use this, but at this stage some Objective-C knowledge will sure come in handy. Again, this is very experimental. Don't expect it to work at all.

If you've been following this blog for a while, you might remember a post from October 2010 where I attempted the exact same thing. Back then I used the JavaScriptCore library that is already available on iOS and used by Apple in Mobile Safari. The problem was, that this library is "private", meaning that Apple does not want you to use it. And since you can't publish anything in the AppStore that uses private libraries I abandoned the idea.

However I recently revisited the project, because there was still a chance to make this work: JavaScriptCore is a part of the open source WebKit project. Instead of using the private library that comes with iOS, you theoretically could compile your own version of this library and bundle it together with your App. Which is exactly what I did.

Since Apple does not provide any project files to compile JavaScriptCore for iOS (presumably to annoy us) and JavaScriptCore itself uses some of iOS' private APIs, compiling this beast into a static library - in an App Store compatible fashion - took me a few days.

I also had to make a small sacrifice: JavaScriptCore uses libicu to sort strings according to a unicode locale. Sadly, libicu is also private on iOS and bundling it is not an option because of its size. So I got rid of libicu completely. This means that only ASCII strings are now sorted correctly (e.g. the umlaut "Ä" will come after "Z", not after "A" as it should). Other than that, the JavaScript library should behave exactly as the private one that comes with iOS.

Also, the JavaScriptCore library bundled with iOSImpact does not use the JIT compiler (Nitro). You can't allocate executable memory on the iPhone and if Apple doesn't lift that restriction, there's nothing I can do about it. However, Apple recently made an exception for Mobile Safari – if they would make their JavaScriptCore API public, they probably could enable the JIT for everyone. That's a big if though; I don't see it happening, because Apple loves native code (Objective-C) and hates scripting languages.

I was afraid Apple would reject the two games for some obscure reason, but they didn't. Which leaves me to wonder why the JavaScriptCore library that comes with iOS is private in the first place. Bundling JavaScriptCore with your App adds about 2MB in size – not much, but I fail to see how this can be in Apple's interest.

Anyway, the performance of both games is pretty good. I still get some occasional slowdowns (~20fps) on my iPhone3GS in Biolab Disaster when there are too many particles on the screen, but it remains playable at all times. It's also nice to have perfectly working sound on iOS now - something even some desktop browsers still struggle with.

Wednesday, April 27th 2011
— Dominic Szablewski, @phoboslab


#1Juerg – Wednesday, April 27th 2011, 12:00

That's excellent news! One thought that popped up while reading about this: Couldn't you use Google's Skia to fully translate Canvas to Open GL?

#2Bruno Garcia – Wednesday, April 27th 2011, 12:06

Impressive that it runs at full speed even without JIT!

I've been building a similar native shim for JS games, although using Spidermonkey. What made you decide on JavaScriptCore?

#3Patrick Mueller – Wednesday, April 27th 2011, 14:19

Rather than include your own JSC, I've wondered if you could make use of the JSC included in iOS by using a UIWebView (or WebView on Android), and just not actually using the view - interact with JS and the native language (objC/Java) using the exist JS bridges.

You'd presumably have less control, more code to handle the layer, but on the other hand be able to make use of existing capabilies that UIWebView has to offer (whatever those might be).

I suspect it would be a bit of work to support, and I'm not sure how much you'd really get from it, but let me know if you're interested in getting this supported in weinre -

#4Tony Carrera – Wednesday, April 27th 2011, 14:41

You're awesome. Keep up the good work!

#5Peter Jaric – Wednesday, April 27th 2011, 14:53

As a side note: in Swedish (which uses Å, Ä and Ö) Ä is *supposed* to come after Z, so I guess that's a bug that turned into a feature for at least a subset of your users.

#6 – Julian Haupt – Wednesday, April 27th 2011, 14:55


#7Dominic – Wednesday, April 27th 2011, 15:09

@Juerg: skia sure is interesting, but it's also a fairly big library and I have no idea how easy this would be to compile for iOS. I'll look into it.

@Patrick Mueller: I actually tried that using a "hack" to pass JSON strings from JS to Objective-C by navigating to a special URL - similar to how PhoneGap does it, because there is no "bridge" in that direction. It worked better than expected and there are some benefits (readily available AJAX and other JS APIs) but it felt just wrong and in the end, bundling my own JSC lib had much better performance.

And damn, weinre looks interesting. I wish I would've know about it before for some other projects. I don't think it would make much sense for iOSImpact though, because there is neither any HTML nor CSS used.

#8Spot – Wednesday, April 27th 2011, 18:06

Very nice indeed. Quite impressive.

I notice that Biolab requires iOS 4.2. Is that because of the way you've done this? Or is that just something you chose arbitrarily?

#9schell – Wednesday, April 27th 2011, 19:06

Awesome! Have any plans of describing the JSC build process?

#10Zac Bowling – Wednesday, April 27th 2011, 19:08


...but you are still violating the iOS agreement. Specifically the no interpreter rule except those provided by Apple. They probably didn't notice but blogging about it may get your apps pulled.

Take it from someone that has been on Apple's bad side: this is a bad idea and will probably get you pulled.

#11Diogo Gomes – Wednesday, April 27th 2011, 19:14

This is great! A little slow on ipod touch 2g in the begining of bio lab dissaster because of the particles though.
I noticed a little bug (or annoying feature), it only detects a button press on touch start, this is annoying on bio lab since I need to lift my finger when I want to change direction.

#12 – Philippe – Wednesday, April 27th 2011, 19:51

It's a great decision.

And it's actually what Titanium mobile does: include the JS VM and expose the native UIKit (source on github:

@Zak: Apple doesn't rule out interpreters anymore if they don't JIT.

#13bunnyhero – Wednesday, April 27th 2011, 20:05

Zac: Apple allows interpreters now, as long as all the code is self-contained in the app and not downloaded from an external source.

#14Luca Matteis – Wednesday, April 27th 2011, 20:22

That's some interesting hacking you did with those low-level APIs... great accomplishment. You deserve all the success ImpactJS is having.

#15Joe McCann – Wednesday, April 27th 2011, 20:30

This is bad ass.

#16Adrian Sinclair – Wednesday, April 27th 2011, 22:09

I don't know if you can use C++ in iOS development as model files like you can in mac cocoa, and I'm barely familiar with mac cocoa too, but if you can use c++ in some context during iOS development, you might be able to implement some node js modules in the cocoa project. This would come in handy because there is already a node module that mimics the canvas api with (I think) OpenGL. This would also be advantageous because nodejs uses the v8 javascript engine which is significantly faster than apple's CoreJavaScript engine. This is mainly because v8 works a lot like the JVM in that it uses just-in-time native machine code compilation instead of just interpreting the javascript. I don't even know if nodejs or v8 will compile on iPhone, or if this is at all feasible, but it would be an interesting experiment if you're up for it.

#17Terry – Wednesday, April 27th 2011, 22:16

Glad you shared this with everyone. Really great work.

Just to clarify... Titanium uses JavaScriptCore as well to create native bindings to UIKit. Titanium is not a UIWebView wrapper per se, although that is one of many UIViews you can create and embed web apps. The result is a much more "native" experience and tighter integration to platform capabilities.

#18Jens Alfke – Wednesday, April 27th 2011, 22:26

Another alternative to JSC would be the V8 interpreter used in Chrome. It's extremely fast, and I know for a fact it has Xcode project files since that's how it's built in Chrome.

#19Julian Haupt – Wednesday, April 27th 2011, 23:18


we're working on this stuff, too. Embedding V8 would be the best solution but it has not been ported to iOS yet (see )

However Spidermonkey has been already ported to iOS ( )

Doing this kind of stuff in C++ has many benefits. Just think about using this technique to publish games on steam (native pc)/android/xbox/ whatever.


#20Martin Dederer – Thursday, April 28th 2011, 12:06

It looks like nathan, the original poster from , managed to build node.js for ios. Since node.js embeds v8 i conclude that he successfully build v8 for ios. His post does not go into detail about how he solved the ios jit problem.

#21 – karlozm – Thursday, April 28th 2011, 16:12

Congratulations on this Dominic ! :D

#22Justin – Thursday, April 28th 2011, 18:29

If you're trying to develop graphics for your canvas games, I highly recomment this free tool:

#23 – Ric – Thursday, April 28th 2011, 19:14

Congratulations on good work through great coding ! I love the barrier you have broached. Why is Apple so closed ?? So unnecessary, but you found a way around the beast and I applaud you.

#24Grant Galitz – Thursday, April 28th 2011, 19:40

If you want direct access to the audio system in Firefox 4+, use

And webkit is soon getting web audio:

#25 – abcd – Thursday, April 28th 2011, 21:54

Are you asking 99$ for this library? You should sell it apart from 'impact' framework.

#26 – Bb – Friday, April 29th 2011, 10:04

A po polsku nie mozna :p

#27 – @domrein – Friday, April 29th 2011, 17:38

I'm also interested in knowing if you'd consider providing this library apart from Impact whether that be open source or license. I have non Impact games that are nearing completion and I'd love to take advantage of what you have here.

#28 – weepy – Friday, April 29th 2011, 18:04

Awsome man - very impressive. fingers xssed for the JIT enabling!

#29 – Tom – Friday, April 29th 2011, 20:52

Well, yes. Would be great to be able to get the iOS opengl-canvas library apart from Impact, and a way cheaper than 99. Too expensive for homebrewers.

#30Tyler Washburn – Saturday, April 30th 2011, 00:23

Also, I noticed that this fixes the multitouch issues that you experience in the browser.

#31Tyler Washburn – Saturday, April 30th 2011, 00:26

@abcd and @Tom It still uses Impact for the game, so he would have to give you the full version of Impact anyway what he should do is charge extra for the iOS Library. (Like $30 or so.)

#32Iouri – Saturday, April 30th 2011, 07:48

@26Bb po polsku nie nuzhno

#33 – Tom – Saturday, April 30th 2011, 10:51

Well, if he wants to charge 99 + 30 for everything. I have to pray to someone with enough heart and knowledge to do the same free of charge.

#34 – UIHacker – Sunday, May 1st 2011, 19:29

Great work! I love it.

#35Seasons – Wednesday, May 4th 2011, 18:02


I purchased iOSIMPACT license.
This blog translated into Japanese.

Twitter @Seasons

#36 – panzi – Sunday, May 8th 2011, 23:03


However, when you press a button in Biolab and then slide your finger to the next button Biolab thinks you are still pressing the first button. Also I wonder if it would be possible to use iPhones accelerator to control Drop (like Doodlejump)?

#37MarkW – Wednesday, May 11th 2011, 23:29

Fantastic work going on here.
You have pretty much convinced me to give Impact a spin for my arcade games.

#38 – Andy – Tuesday, May 17th 2011, 13:21

Very clever! Your engine is impressive and it's interesting following your progress as one of the people at the forefront of canvas game development. I can only say that I hope Apple opens up their own javascript engine so we needn't jump like hoops to get canvas apps on iOS in the future.

#39Pikuseru – Tuesday, May 24th 2011, 15:43

This stuff is really cool, I've been wishing for something like this ever since I started playing around with iOS programming. So glad I paid up the $99 when I saw the demos, I wasn't expecting an iOS version.

Have you thought about opening up your build of JSC ? (I would happily stump up some more money for this in itself) I would love to branch it and add support for using ASIHTTPRequest (and any other native code) with it.

I'd also like to see how CoffeeScript (or other languages that could get translated into JS) could be used with ImpactJS; you could start imagining this turning into a DSL for games development - the kind of thing perfect for beginners, teaching and prototyping.

Well done on this!

#40 – Rick Blalock – Thursday, June 2nd 2011, 23:21

We package JSCore in Titanium just don't have any exposure to openGL. I bet we could make an openGL module that would allow for this type of thing

#41iamyellow – Tuesday, August 9th 2011, 10:02

Hi all! I succeed integrating Impact and Appcelerator's Titanium Mobile (ios only, sorry).
I've modified Dominic's iOSImpact following Titanium module architecture. I had to change JavascriptCore calls to 'Ti' namescape as well, but you know... that's only a find and replace task!
And... it worked!
I'm moving slowly, I have limited time for this... but my next steps are focused in:
- draw the control GUI with Titanium, send its events to the game
- send 'game events' to Titanium

One more thing :) they (Appcelerator's fantastic team) have updated their version of JavaScriptCore to 721.26, and they say is the version Apple ships with iOS 4.3.3. Does anyone know whether it uses the JIT compiler or not? At least there IS a folder in the source code which is called 'jit', see:

#42dc – Sunday, October 23rd 2011, 10:11

i understand iOS5 allows JIT for apps too?

Q: Did they fix the bug from 4.3 where home screen web apps don’t use Nitro?
A: This is probably breaking my NDA to say this, but yes, they did. now has the “dynamic-codesigning” entitlement, which enables Nitro.


also, any thoughts on a Android version for the canvas calls :P

#43dc – Wednesday, November 16th 2011, 03:24

any further thoughts on opensourcing just this code?

I'm sure there are a lot of other people who are working with javascript and canvas apps that could extend it. for example as a phonegap "game canvas" plugin.

would also be good to have an app with a webUIview layer over the game, or callable from the game (like what appmobi added) so we could use the normal browser/DOM features like dialogs etc. and yet still take advantage of native-like performance for the impact game.

i would be happy to contribute some funds toward development of this as a project. the $99 price for this part alone is well worth it... if it were a bit more polished.

#44 – brad – Friday, December 16th 2011, 18:32

I'm strongly considering using ImpactJS - but was wondering if you can answer the following:

- I want to be able to integrate some custom Objective C code with ImpactJS with the iOs acceleration you've got going using the custom Javascript library. I know I could do this if I used the approach detailed in this post, but could I use custom Objective C code with the AppMobi approach and ImpactJS?


#45 – Sam – Saturday, January 14th 2012, 03:25

Isn't JavascriptCore licensed under LGPL ? which means if you statically link to will have to release the source code of your project too under LGPL compatible terms ?

#46 – andreas – Thursday, February 9th 2012, 09:49

I'm working with impact and IMHO impact does not statically link with LGPL-lizensed JavascriptCore.

Note 1: I'am not in any way tied to impact or the impact-developer - don't blame anybody else for my temper. BUT!: Shame on you @Sam - parasitic guys like you make me avoid working with the OSCommunity. Hey vultures, c'mon indicate your personal contribution before asking other people to give away their work for free. Note that there are people who need to make a living by coding.

Note 2: Have a look at this fabulous project that is draught out working "for free" in the FOSS sector SOFA:
(I'm not bound to SOFA either ...)

#47 – tyler – Wednesday, February 15th 2012, 19:55

anyone who says "shame on you" is a tool

#48 – 78c – Sunday, September 9th 2012, 23:04

This is such nonsense. So you proved that javascript can provide a Sega Genesis-level game experience in the year 2012. Big deal. You could make a game like this in Processing and port it to javascript for free, so Impact is basically a big fat waste of money for noobs.

#49 – jonas_man – Tuesday, October 2nd 2012, 08:30

just one small note:
(e.g. the umlaut "Ä" will come after "Z", not after "A" as it should).

In many languages Ä comes after Z and not after A. So it is actually good! :)

#50 – Mehul Patel – Wednesday, August 21st 2013, 09:24

With the Introduction of iOS 7. What complexity is involved if I want to use JavaScriptCore.framework as provided by Apple for iOS 7 & To support iOS 5/6, I want to use JavaScriptCore.a static library?
Q1: Is it Technically feasible to have .a & .framework co-exist within a single project? ( I would say there will be conflicts in symbols/structures etc...)

Q2: If Answer of Q1 is Yes, then how do I make a selection at runtime that I want to use .a & not .framework? (for example, JSObject * should point to the structure defined in .a & not in .framework)

#51raiyan – Sunday, January 19th 2014, 15:49


#52Tony – Wednesday, June 4th 2014, 11:26


this is great, and you seem to have a lot of knowledge about what is allowed and what is not allowed, what is private and what is not private. I was wondering if you could help us gauge whether an app we're creating would make it through the app store?

Post a Comment:

Comment: (Required)

(use <code> tags for preformatted text; URLs are recognized automatically)

Name: (Required)

Please type phoboslab into the following input field or enable Javascript. This is an anti-spam measure. Sorry for the inconvenience.