Skip to content

Instantly share code, notes, and snippets.

@yajd
Last active August 29, 2015 14:05
Show Gist options
  • Save yajd/748ad2a74b8821f43bae to your computer and use it in GitHub Desktop.
Save yajd/748ad2a74b8821f43bae to your computer and use it in GitHub Desktop.
interesting notes on jsctypes cross os

var runtime = Components.classes["@mozilla.org/xre/app-info;1"] .getService(Components.interfaces.nsIXULRuntime); var abi = runtime.OS + "_" + runtime.XPCOMABI; var lib_name; this.data_loc = ""; //================================================================== // Detect shared library name to load //================================================================== if (abi == "Linux_x86-gcc3" || abi == "Linux_x86_64-gcc3") { lib_name = "libvoikko.so.1"; } else if (abi == "WINNT_x86-msvc" || abi == "WINNT_x86_64-msvc") { lib_name = "libvoikko-1.dll"; this.call_abi = ctypes.winapi_abi; } else if (abi == "Darwin_x86_64-gcc3" || abi == "Darwin_x86-gcc3" || abi == "Darwin_ppc-gcc3") { lib_name = "libvoikko.1.dylib"; } else { throw "Unsupported ABI " + abi; }


* https://github.com/stephenfox/iceweasel-dev/blob/c1ebf8be93add288837377e4fdd87f9c9f1082cc/l10n-gu-IN/services/crypto/modules/WeaveCrypto.js#L112

let os = Services.appinfo.OS; switch (os) { case "WINNT": case "WINMO": case "WINCE": nssfile.append("nss3.dll"); break; case "Darwin": nssfile.append("libnss3.dylib"); break; case "Linux": case "SunOS": case "WebOS": // Palm Pre nssfile.append("libnss3.so"); break; case "Android": // Android uses a $GREDIR/lib/ subdir. nssfile.append("lib"); nssfile.append("libnss3.so"); break; default: throw this.makeException("unsupported platform: " + os, Cr.NS_ERROR_UNEXPECTED); }


* https://github.com/mozilla/deuxdrop/blob/2404f3fccaf762dfb935ee1563f68ca2c61d32b4/clients/addon/lib/nacl.js#L68

let runtime = Cc["@mozilla.org/xre/app-info;1"] .getService(Ci.nsIXULRuntime); let platLibName; switch (runtime.OS) { case 'WINNT': if (numbits !== 32) throw new Error('64-bit windows not supported right now.'); platLibName = 'nacl-i686.dll'; break; case 'Linux': platLibName = 'libnacl-' + platCode + '.so'; break; case 'Darwin': if (numbits !== 64) throw new Error('32-bit OS X not supported right now.'); platLibName = 'libnacl-x86_64.dylib'; break; case 'Android': platLibName = 'libnacl-arm.so'; break; default: throw new Error('No native library for platform: ' + runtime.OS); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment