tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fileReaderSyncErrors_worker.js (1966B)


      1 /**
      2 * Delegates "is" evaluation back to main thread.
      3 */
      4 function is(actual, expected, message) {
      5  var rtnObj = new Object();
      6  rtnObj.actual = actual;
      7  rtnObj.expected = expected;
      8  rtnObj.message = message;
      9  postMessage(rtnObj);
     10 }
     11 
     12 /**
     13 * Tries to write to property.
     14 */
     15 function writeProperty(file, property) {
     16  var oldValue = file[property];
     17  file[property] = -1;
     18  is(file[property], oldValue, "Property " + property + " should be readonly.");
     19 }
     20 
     21 /**
     22 * Passes junk arguments to FileReaderSync methods and expects an exception to
     23 * be thrown.
     24 */
     25 function fileReaderJunkArgument(blob) {
     26  var fileReader = new FileReaderSync();
     27 
     28  try {
     29    fileReader.readAsBinaryString(blob);
     30    is(
     31      false,
     32      true,
     33      "Should have thrown an exception calling readAsBinaryString."
     34    );
     35  } catch (ex) {
     36    is(true, true, "Should have thrown an exception.");
     37  }
     38 
     39  try {
     40    fileReader.readAsDataURL(blob);
     41    is(false, true, "Should have thrown an exception calling readAsDataURL.");
     42  } catch (ex) {
     43    is(true, true, "Should have thrown an exception.");
     44  }
     45 
     46  try {
     47    fileReader.readAsArrayBuffer(blob);
     48    is(
     49      false,
     50      true,
     51      "Should have thrown an exception calling readAsArrayBuffer."
     52    );
     53  } catch (ex) {
     54    is(true, true, "Should have thrown an exception.");
     55  }
     56 
     57  try {
     58    fileReader.readAsText(blob);
     59    is(false, true, "Should have thrown an exception calling readAsText.");
     60  } catch (ex) {
     61    is(true, true, "Should have thrown an exception.");
     62  }
     63 }
     64 
     65 onmessage = function (event) {
     66  var file = event.data;
     67 
     68  // Test read only properties.
     69  writeProperty(file, "size");
     70  writeProperty(file, "type");
     71  writeProperty(file, "name");
     72 
     73  // Bad types.
     74  fileReaderJunkArgument(undefined);
     75  fileReaderJunkArgument(-1);
     76  fileReaderJunkArgument(1);
     77  fileReaderJunkArgument(new Object());
     78  fileReaderJunkArgument("hello");
     79 
     80  // Post undefined to indicate that testing has finished.
     81  postMessage(undefined);
     82 };