dom/workers/test/atob_worker.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/test/atob_worker.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +/**
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +var data = [ -1, 0, 1, 1.5, /* null ,*/ undefined, true, false, "foo",
     1.9 +             "123456789012345", "1234567890123456", "12345678901234567"];
    1.10 +
    1.11 +var str = "";
    1.12 +for (var i = 0; i < 30; i++) {
    1.13 +  data.push(str);
    1.14 +  str += i % 2 ? "b" : "a";
    1.15 +}
    1.16 +
    1.17 +onmessage = function(event) {
    1.18 +  data.forEach(function(string) {
    1.19 +    var encoded = btoa(string);
    1.20 +    postMessage({ type: "btoa", value: encoded });
    1.21 +    postMessage({ type: "atob", value: atob(encoded) });
    1.22 +  });
    1.23 +
    1.24 +  var threw;
    1.25 +  try {
    1.26 +    atob();
    1.27 +  }
    1.28 +  catch(e) {
    1.29 +    threw = true;
    1.30 +  }
    1.31 +
    1.32 +  if (!threw) {
    1.33 +    throw "atob didn't throw when called without an argument!";
    1.34 +  }
    1.35 +  threw = false;
    1.36 +
    1.37 +  try {
    1.38 +    btoa();
    1.39 +  }
    1.40 +  catch(e) {
    1.41 +    threw = true;
    1.42 +  }
    1.43 +
    1.44 +  if (!threw) {
    1.45 +    throw "btoa didn't throw when called without an argument!";
    1.46 +  }
    1.47 +
    1.48 +  postMessage({ type: "done" });
    1.49 +}

mercurial