Created
October 18, 2012 02:37
-
-
Save monjudoh/3909563 to your computer and use it in GitHub Desktop.
Transferablesサポートチェック
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 参考 | |
// http://updates.html5rocks.com/2011/12/Transferable-Objects-Lightning-Fast | |
// http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string | |
var isSupportTransferables = (function () { | |
var global = window; | |
// URLにベンダプレフィクスが付いているのはwebkitだけ!! | |
var URL = global.URL || global.webkitURL; | |
var supportsBlobUrls = URL !== undefined && URL.createObjectURL; | |
// Transferablesの方がBlobURLよりサポートが遅いし、BlobURLsを使わないと外部JSなしでworkerを作れないのでこうしている | |
if (!supportsBlobUrls) { | |
return false; | |
} | |
// 空JavaScript | |
var blob = new Blob([''],{type:'application/javascript'}); | |
var worker = new Worker(URL.createObjectURL(blob)); | |
worker.postMessage = worker.webkitPostMessage || worker.postMessage; | |
try { | |
var ab = new ArrayBuffer(1); | |
worker.postMessage(ab, [ab]); | |
return !ab.byteLength; | |
} catch (e) { | |
} finally { | |
worker.terminate(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment