Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
5 var data = [ -1, 0, 1, 1.5, /* null ,*/ undefined, true, false, "foo",
6 "123456789012345", "1234567890123456", "12345678901234567"];
8 var str = "";
9 for (var i = 0; i < 30; i++) {
10 data.push(str);
11 str += i % 2 ? "b" : "a";
12 }
14 onmessage = function(event) {
15 data.forEach(function(string) {
16 var encoded = btoa(string);
17 postMessage({ type: "btoa", value: encoded });
18 postMessage({ type: "atob", value: atob(encoded) });
19 });
21 var threw;
22 try {
23 atob();
24 }
25 catch(e) {
26 threw = true;
27 }
29 if (!threw) {
30 throw "atob didn't throw when called without an argument!";
31 }
32 threw = false;
34 try {
35 btoa();
36 }
37 catch(e) {
38 threw = true;
39 }
41 if (!threw) {
42 throw "btoa didn't throw when called without an argument!";
43 }
45 postMessage({ type: "done" });
46 }