|
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"]; |
|
7 |
|
8 var str = ""; |
|
9 for (var i = 0; i < 30; i++) { |
|
10 data.push(str); |
|
11 str += i % 2 ? "b" : "a"; |
|
12 } |
|
13 |
|
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 }); |
|
20 |
|
21 var threw; |
|
22 try { |
|
23 atob(); |
|
24 } |
|
25 catch(e) { |
|
26 threw = true; |
|
27 } |
|
28 |
|
29 if (!threw) { |
|
30 throw "atob didn't throw when called without an argument!"; |
|
31 } |
|
32 threw = false; |
|
33 |
|
34 try { |
|
35 btoa(); |
|
36 } |
|
37 catch(e) { |
|
38 threw = true; |
|
39 } |
|
40 |
|
41 if (!threw) { |
|
42 throw "btoa didn't throw when called without an argument!"; |
|
43 } |
|
44 |
|
45 postMessage({ type: "done" }); |
|
46 } |