123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- // by jussi-kalliokoski
- // This test is asynchronous. Watch out.
- // The test will potentially add garbage to console.
- (function(){
- try {
- // we're avoiding using Modernizr._domPrefixes as the prefix capitalization on
- // these guys are notoriously peculiar.
- var BlobBuilder = window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder || window.OBlobBuilder || window.BlobBuilder;
- var URL = window.MozURL || window.webkitURL || window.MSURL || window.OURL || window.URL;
- var data = 'Modernizr',
- blob,
- bb,
- worker,
- url,
- timeout,
- scriptText = 'this.onmessage=function(e){postMessage(e.data)}';
- try {
- blob = new Blob([scriptText], {type:'text/javascript'});
- } catch(e) {
- // we'll fall back to the deprecated BlobBuilder
- }
- if (!blob) {
- bb = new BlobBuilder();
- bb.append(scriptText);
- blob = bb.getBlob();
- }
- url = URL.createObjectURL(blob);
- worker = new Worker(url);
- worker.onmessage = function(e) {
- Modernizr.addTest('blobworkers', data === e.data);
- cleanup();
- };
- // Just in case...
- worker.onerror = fail;
- timeout = setTimeout(fail, 200);
- worker.postMessage(data);
- } catch (e) {
- fail();
- }
- function fail() {
- Modernizr.addTest('blobworkers', false);
- cleanup();
- }
- function cleanup() {
- if (url) {
- URL.revokeObjectURL(url);
- }
- if (worker) {
- worker.terminate();
- }
- if (timeout) {
- clearTimeout(timeout);
- }
- }
- }());
|