1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | define(['Modernizr', 'addTest', 'test/blob', 'test/url/bloburls', 'test/workers/webworkers', 'test/typed-arrays'], function(Modernizr, addTest) {
|
18 | Modernizr.addAsyncTest(function() {
|
19 | var prerequisites = !!(Modernizr.blobconstructor &&
|
20 | Modernizr.bloburls &&
|
21 | Modernizr.webworkers &&
|
22 | Modernizr.typedarrays);
|
23 |
|
24 |
|
25 | if (!prerequisites) {
|
26 | return addTest('transferables', false);
|
27 | }
|
28 |
|
29 |
|
30 | try {
|
31 | var buffer,
|
32 | scriptText = 'var hello = "world"',
|
33 | blob = new Blob([scriptText], {type: 'text/javascript'}),
|
34 | url = URL.createObjectURL(blob),
|
35 | worker = new Worker(url),
|
36 | timeout;
|
37 |
|
38 |
|
39 | worker.onerror = fail;
|
40 | timeout = setTimeout(fail, 200);
|
41 |
|
42 |
|
43 | buffer = new ArrayBuffer(1);
|
44 |
|
45 |
|
46 | worker.postMessage(buffer, [buffer]);
|
47 |
|
48 |
|
49 | addTest('transferables', buffer.byteLength === 0);
|
50 | cleanup();
|
51 | } catch (e) {
|
52 | fail();
|
53 | }
|
54 |
|
55 | function fail() {
|
56 | addTest('transferables', false);
|
57 | cleanup();
|
58 | }
|
59 |
|
60 | function cleanup() {
|
61 | if (url) {
|
62 | URL.revokeObjectURL(url);
|
63 | }
|
64 | if (worker) {
|
65 | worker.terminate();
|
66 | }
|
67 | if (timeout) {
|
68 | clearTimeout(timeout);
|
69 | }
|
70 | }
|
71 | });
|
72 | });
|