File tree Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,19 @@ var WorkerMessageHandler = {
152
152
}
153
153
154
154
handler .on ('test' , function wphSetupTest (data ) {
155
- handler .send ('test' , data instanceof Uint8Array );
155
+ // check if Uint8Array can be sent to worker
156
+ if (!(data instanceof Uint8Array )) {
157
+ handler .send ('test' , false );
158
+ return ;
159
+ }
160
+ // check if the response property is supported by xhr
161
+ var xhr = new XMLHttpRequest ();
162
+ if (!('response' in xhr || 'mozResponse' in xhr ||
163
+ 'responseArrayBuffer' in xhr || 'mozResponseArrayBuffer' in xhr )) {
164
+ handler .send ('test' , false );
165
+ return ;
166
+ }
167
+ handler .send ('test' , true );
156
168
});
157
169
158
170
handler .on ('GetDocRequest' , function wphSetupDoc (data ) {
Original file line number Diff line number Diff line change @@ -512,6 +512,37 @@ var tests = [
512
512
},
513
513
impact : 'Important' ,
514
514
area : 'Core'
515
+ },
516
+ {
517
+ id : 'Worker-xhr-response' ,
518
+ name : 'XMLHttpRequest supports the reponse property in web workers' ,
519
+ run : function () {
520
+ if (typeof Worker == 'undefined' )
521
+ return { output : 'Skipped' , emulated : '' };
522
+
523
+ try {
524
+ var worker = new Worker ('worker-stub.js' );
525
+
526
+ var promise = new Promise ();
527
+ var timeout = setTimeout (function () {
528
+ promise .resolve ({ output : 'Failed' , emulated : '?' });
529
+ }, 5000 );
530
+
531
+ worker .addEventListener ('message' , function (e ) {
532
+ var data = e .data ;
533
+ if (data .action == 'xhr' && data .result )
534
+ promise .resolve ({ output : 'Success' , emulated : '' });
535
+ else
536
+ promise .resolve ({ output : 'Failed' , emulated : 'Yes' });
537
+ });
538
+ worker .postMessage ({action : 'xhr' });
539
+ return promise ;
540
+ } catch (e ) {
541
+ return { output : 'Failed' , emulated : 'Yes' };
542
+ }
543
+ },
544
+ impact : 'Important' ,
545
+ area : 'Core'
515
546
}
516
547
];
517
548
Original file line number Diff line number Diff line change 17
17
18
18
onmessage = function (e ) {
19
19
var data = e .data ;
20
- postMessage ({action : 'test' , result : data .action == 'test' &&
21
- data .data instanceof Uint8Array });
20
+ switch (data .action ) {
21
+ case 'test' :
22
+ postMessage ({action : 'test' , result : data .data instanceof Uint8Array });
23
+ break ;
24
+ case 'xhr' :
25
+ var xhr = new XMLHttpRequest ();
26
+ var responseExists = 'response' in xhr || 'mozResponse' in xhr ||
27
+ 'responseArrayBuffer' in xhr || 'mozResponseArrayBuffer' in xhr ;
28
+ postMessage ({action : 'xhr' , result : responseExists });
29
+ break ;
30
+ }
22
31
};
23
32
You can’t perform that action at this time.
0 commit comments