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


newer versions of android ( > 2.2) include v8 javascript engine, while older versions had jsc. however, according http://blogs.nitobi.com/joe/2011/01/14/android-your-js-engine-is-not-always-v8/, javascript engine used @ runtime seems depend on environment variable present @ build-time (js_engine), hardware specs of device:

# default / alternative engine depends on device class. # on devices lot of memory (e.g. passion/sholes), # default v8. on else, choice jsc. 

my question this: there way can determine javascript engine in use within webpage, embedded webview, or application?

if answer no, know js engine used android emulator?


the reason i'm asking because of issue: http://code.google.com/p/android/issues/detail?id=12987

basically, may javascript-to-java bridge in jsc broken on android 2.3.x, , impacts application i'm trying write. i'm seeing segfault somewhere deep in jni on emulator, not on handful of physical devices i've tested. i'm trying determine if emulator-only thing, jsc-only thing, or different altogether.

i think better question is: why care? you're falling "browser detection" trap lot of people fell in late 90's / 00's. since then, though, we've learned it's feature detection that's more useful approach, not least because features supported in given browser (mostly) moving target. there's code now, running on ie9 dramatically-improved dom , javascript support, that's not using features because it's doing browser detection , falling on ie6 techniques.

so rather worrying v8 vs. jsc, worry features want. don't know jsc, instance let's assume doesn't have foreach method on arrays v8 has (part of ecmascript 5th edition standard). rather throwing big "v8 vs. jsc" lever, you'd do:

if (typeof array.prototype.foreach === "function") {     // code expects `foreach` } else {     // code falls } 

(your "code falls back" might add foreach prototype, or maybe test in own iterator function , want know whether defer native implementation or supply own.)

and other features want use may or may not present.


but if need detect v8 vs. jsc (and comment seems may), this page seems demonstrate means of doing so, though seems awfully fragile. here's slightly-edited version (not least replace window.devicepixelratio test webkitappearance — former gives false positives on @ least other browsers [firefox, instance, uses gecko, not webkit]):

var v8string = 'function%20javaenabled%28%29%20%7b%20%5bnative%20code%5d%20%7d';  if ('webkitappearance' in document.documentelement.style)  //if (probably) webkit browser {    if (escape(navigator.javaenabled.tostring()) === v8string)    {       display('v8 detected');    }    else    {       display('jsc detected');    } } else {   display("not webkit browser"); } 

live example

works me detecting difference between chrome (which uses v8) , safari (which uses jsc).


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -