Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect which javascript engine (v8 or JSC) is used at runtime in Android?

Newer versions of Android ( > 2.2) include the v8 javascript engine, while older versions only had JSC. However, according to http://blogs.nitobi.com/joe/2011/01/14/android-your-js-engine-is-not-always-v8/, which javascript engine is used at runtime seems to depend on an environment variable present at build-time (JS_ENGINE), as well as the hardware specs of the device:

# The default / alternative engine depends on the device class.
# On devices with a lot of memory (e.g. Passion/Sholes), the
# default is V8. On everything else, the only choice is JSC.

My question is this: is there any way that I can determine which javascript engine is in use from within a webpage, an embedded WebView, or an application?

If the answer is no, does anybody know which JS engine is used by the Android emulator?


The reason I'm asking this is because of this issue: http://code.google.com/p/android/issues/detail?id=12987

Basically, it may be that the javascript-to-java bridge in JSC is broken on Android 2.3.X, and this impacts the application I'm trying to write. I'm seeing a segfault from somewhere deep in the JNI on my emulator, but not on the handful of physical devices I've tested. I'm trying to determine if this is an emulator-only thing, a JSC-only thing, or something different altogether.

like image 768
digitalbath Avatar asked Jul 20 '11 20:07

digitalbath


1 Answers

var s = '';
for (x in {
    3: 3,
    1: 1
  }) {
  s += x
}
if (s === '31') {
  alert('JSC');
} else {
  alert('V8');
}

By the way this will categorize Firefox as 'JSC' and newer IE versions will look like V8.

My blog post has more V8 sniffing tricks: http://erikcorry.blogspot.dk/2012/12/which-version-of-v8-do-i-have.html

like image 170
Erik Corry Avatar answered Oct 18 '22 21:10

Erik Corry