atob_worker.js (931B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 var data = [ 6 -1, 7 0, 8 1, 9 1.5, 10 /* null ,*/ undefined, 11 true, 12 false, 13 "foo", 14 "123456789012345", 15 "1234567890123456", 16 "12345678901234567", 17 ]; 18 19 var str = ""; 20 for (var i = 0; i < 30; i++) { 21 data.push(str); 22 str += i % 2 ? "b" : "a"; 23 } 24 25 onmessage = function (event) { 26 data.forEach(function (string) { 27 var encoded = btoa(string); 28 postMessage({ type: "btoa", value: encoded }); 29 postMessage({ type: "atob", value: atob(encoded) }); 30 }); 31 32 var threw; 33 try { 34 atob(); 35 } catch (e) { 36 threw = true; 37 } 38 39 if (!threw) { 40 throw "atob didn't throw when called without an argument!"; 41 } 42 threw = false; 43 44 try { 45 btoa(); 46 } catch (e) { 47 threw = true; 48 } 49 50 if (!threw) { 51 throw "btoa didn't throw when called without an argument!"; 52 } 53 54 postMessage({ type: "done" }); 55 };