michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: var data = [ -1, 0, 1, 1.5, /* null ,*/ undefined, true, false, "foo", michael@0: "123456789012345", "1234567890123456", "12345678901234567"]; michael@0: michael@0: var str = ""; michael@0: for (var i = 0; i < 30; i++) { michael@0: data.push(str); michael@0: str += i % 2 ? "b" : "a"; michael@0: } michael@0: michael@0: onmessage = function(event) { michael@0: data.forEach(function(string) { michael@0: var encoded = btoa(string); michael@0: postMessage({ type: "btoa", value: encoded }); michael@0: postMessage({ type: "atob", value: atob(encoded) }); michael@0: }); michael@0: michael@0: var threw; michael@0: try { michael@0: atob(); michael@0: } michael@0: catch(e) { michael@0: threw = true; michael@0: } michael@0: michael@0: if (!threw) { michael@0: throw "atob didn't throw when called without an argument!"; michael@0: } michael@0: threw = false; michael@0: michael@0: try { michael@0: btoa(); michael@0: } michael@0: catch(e) { michael@0: threw = true; michael@0: } michael@0: michael@0: if (!threw) { michael@0: throw "btoa didn't throw when called without an argument!"; michael@0: } michael@0: michael@0: postMessage({ type: "done" }); michael@0: }