Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /** |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | */ |
michael@0 | 5 | var data = [ -1, 0, 1, 1.5, /* null ,*/ undefined, true, false, "foo", |
michael@0 | 6 | "123456789012345", "1234567890123456", "12345678901234567"]; |
michael@0 | 7 | |
michael@0 | 8 | var str = ""; |
michael@0 | 9 | for (var i = 0; i < 30; i++) { |
michael@0 | 10 | data.push(str); |
michael@0 | 11 | str += i % 2 ? "b" : "a"; |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | onmessage = function(event) { |
michael@0 | 15 | data.forEach(function(string) { |
michael@0 | 16 | var encoded = btoa(string); |
michael@0 | 17 | postMessage({ type: "btoa", value: encoded }); |
michael@0 | 18 | postMessage({ type: "atob", value: atob(encoded) }); |
michael@0 | 19 | }); |
michael@0 | 20 | |
michael@0 | 21 | var threw; |
michael@0 | 22 | try { |
michael@0 | 23 | atob(); |
michael@0 | 24 | } |
michael@0 | 25 | catch(e) { |
michael@0 | 26 | threw = true; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | if (!threw) { |
michael@0 | 30 | throw "atob didn't throw when called without an argument!"; |
michael@0 | 31 | } |
michael@0 | 32 | threw = false; |
michael@0 | 33 | |
michael@0 | 34 | try { |
michael@0 | 35 | btoa(); |
michael@0 | 36 | } |
michael@0 | 37 | catch(e) { |
michael@0 | 38 | threw = true; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | if (!threw) { |
michael@0 | 42 | throw "btoa didn't throw when called without an argument!"; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | postMessage({ type: "done" }); |
michael@0 | 46 | } |