UNPKG

1.21 kBJavaScriptView Raw
1/*!
2{
3 "name": "Workers from Data URIs",
4 "property": "dataworkers",
5 "tags": ["performance", "workers"],
6 "builderAliases": ["workers_dataworkers"],
7 "notes": [{
8 "name": "W3C Spec",
9 "href": "https://www.w3.org/TR/workers/"
10 }],
11 "knownBugs": ["This test may output garbage to console."],
12 "authors": ["Jussi Kalliokoski"],
13 "async": true
14}
15!*/
16/* DOC
17Detects support for creating Web Workers from Data URIs.
18*/
19define(['Modernizr', 'addTest'], function(Modernizr, addTest) {
20 Modernizr.addAsyncTest(function() {
21 try {
22 var data = 'Modernizr',
23 worker = new Worker('data:text/javascript;base64,dGhpcy5vbm1lc3NhZ2U9ZnVuY3Rpb24oZSl7cG9zdE1lc3NhZ2UoZS5kYXRhKX0=');
24
25 worker.onmessage = function(e) {
26 worker.terminate();
27 addTest('dataworkers', data === e.data);
28 worker = null;
29 };
30
31 // Just in case...
32 worker.onerror = function() {
33 addTest('dataworkers', false);
34 worker = null;
35 };
36
37 setTimeout(function() {
38 addTest('dataworkers', false);
39 }, 200);
40
41 worker.postMessage(data);
42 } catch (e) {
43 setTimeout(function() {
44 addTest('dataworkers', false);
45 }, 0);
46 }
47 });
48});