workers-dataworkers.js 776 B

12345678910111213141516171819202122232425262728293031323334
  1. // by jussi-kalliokoski
  2. // This test is asynchronous. Watch out.
  3. // The test will potentially add garbage to console.
  4. (function(){
  5. try {
  6. var data = 'Modernizr',
  7. worker = new Worker('data:text/javascript;base64,dGhpcy5vbm1lc3NhZ2U9ZnVuY3Rpb24oZSl7cG9zdE1lc3NhZ2UoZS5kYXRhKX0=');
  8. worker.onmessage = function(e) {
  9. worker.terminate();
  10. Modernizr.addTest('dataworkers', data === e.data);
  11. worker = null;
  12. };
  13. // Just in case...
  14. worker.onerror = function() {
  15. Modernizr.addTest('dataworkers', false);
  16. worker = null;
  17. };
  18. setTimeout(function() {
  19. Modernizr.addTest('dataworkers', false);
  20. }, 200);
  21. worker.postMessage(data);
  22. } catch (e) {
  23. Modernizr.addTest('dataworkers', false);
  24. }
  25. }());