1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | define(['Modernizr', 'addTest'], function(Modernizr, addTest) {
|
20 | Modernizr.addAsyncTest(function() {
|
21 | try {
|
22 |
|
23 |
|
24 | var BlobBuilder = window.BlobBuilder;
|
25 | var URL = window.URL;
|
26 | if (Modernizr._config.usePrefix) {
|
27 | BlobBuilder = BlobBuilder || window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder || window.OBlobBuilder;
|
28 | URL = URL || window.MozURL || window.webkitURL || window.MSURL || window.OURL;
|
29 | }
|
30 | var data = 'Modernizr',
|
31 | blob,
|
32 | bb,
|
33 | worker,
|
34 | url,
|
35 | timeout,
|
36 | scriptText = 'this.onmessage=function(e){postMessage(e.data)}';
|
37 |
|
38 | try {
|
39 | blob = new Blob([scriptText], {type: 'text/javascript'});
|
40 | } catch (e) {
|
41 |
|
42 | }
|
43 | if (!blob) {
|
44 | bb = new BlobBuilder();
|
45 | bb.append(scriptText);
|
46 | blob = bb.getBlob();
|
47 | }
|
48 |
|
49 | url = URL.createObjectURL(blob);
|
50 | worker = new Worker(url);
|
51 |
|
52 | worker.onmessage = function(e) {
|
53 | addTest('blobworkers', data === e.data);
|
54 | cleanup();
|
55 | };
|
56 |
|
57 |
|
58 | worker.onerror = fail;
|
59 | timeout = setTimeout(fail, 200);
|
60 |
|
61 | worker.postMessage(data);
|
62 | } catch (e) {
|
63 | fail();
|
64 | }
|
65 |
|
66 | function fail() {
|
67 | addTest('blobworkers', false);
|
68 | cleanup();
|
69 | }
|
70 |
|
71 | function cleanup() {
|
72 | if (url) {
|
73 | URL.revokeObjectURL(url);
|
74 | }
|
75 | if (worker) {
|
76 | worker.terminate();
|
77 | }
|
78 | if (timeout) {
|
79 | clearTimeout(timeout);
|
80 | }
|
81 | }
|
82 | });
|
83 | });
|