summaryrefslogtreecommitdiff
path: root/source/bower_components/modernizr/feature-detects/workers-blobworkers.js
diff options
context:
space:
mode:
Diffstat (limited to 'source/bower_components/modernizr/feature-detects/workers-blobworkers.js')
-rw-r--r--source/bower_components/modernizr/feature-detects/workers-blobworkers.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/source/bower_components/modernizr/feature-detects/workers-blobworkers.js b/source/bower_components/modernizr/feature-detects/workers-blobworkers.js
new file mode 100644
index 0000000..33e82eb
--- /dev/null
+++ b/source/bower_components/modernizr/feature-detects/workers-blobworkers.js
@@ -0,0 +1,66 @@
+// 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);
+ }
+ }
+}());