tor-browser

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

test_exception_options_from_jsimplemented.html (6290B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1107592
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1107592</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12  /* global TestInterfaceJS */
     13  /** Test for Bug 1107592 */
     14 
     15  SimpleTest.waitForExplicitFinish();
     16 
     17  function doTest() {
     18    var file = location.href;
     19 
     20    var asyncFrame;
     21    /* Async parent frames from pushPrefEnv don't show up in e10s.  */
     22    if (!SpecialPowers.getBoolPref("javascript.options.asyncstack_capture_debuggee_only")) {
     23      asyncFrame = `Async*@${file}:152:17
     24 `;
     25    } else {
     26      asyncFrame = "";
     27    }
     28 
     29    var t = new TestInterfaceJS();
     30    try {
     31      t.testThrowError();
     32    } catch (e) {
     33      ok(e instanceof Error, "Should have an Error here");
     34      ok(!(e instanceof DOMException), "Should not have DOMException here");
     35      ok(!("code" in e), "Should not have a 'code' property");
     36      is(e.name, "Error", "Should not have an interesting name here");
     37      is(e.message, "We are an Error", "Should have the right message");
     38      is(e.stack,
     39         `doTest@${file}:31:9
     40 ${asyncFrame}`,
     41         "Exception stack should still only show our code");
     42      is(e.fileName,
     43         file,
     44         "Should have the right file name");
     45      is(e.lineNumber, 31, "Should have the right line number");
     46      is(e.columnNumber, 9, "Should have the right column number");
     47    }
     48 
     49    try {
     50      t.testThrowDOMException();
     51    } catch (e) {
     52      ok(e instanceof Error, "Should also have an Error here");
     53      ok(e instanceof DOMException, "Should have DOMException here");
     54      is(e.name, "NotSupportedError", "Should have the right name here");
     55      is(e.message, "We are a DOMException",
     56         "Should also have the right message");
     57      is(e.code, DOMException.NOT_SUPPORTED_ERR,
     58         "Should have the right 'code'");
     59      is(e.stack,
     60         `doTest@${file}:50:9
     61 ${asyncFrame}`,
     62         "Exception stack should still only show our code");
     63      is(e.filename,
     64         file,
     65         "Should still have the right file name");
     66      is(e.lineNumber, 50, "Should still have the right line number");
     67      is(e.columnNumber, 9, "Should have the right column number");
     68    }
     69 
     70    try {
     71      t.testThrowTypeError();
     72    } catch (e) {
     73      ok(e instanceof TypeError, "Should have a TypeError here");
     74      ok(!(e instanceof DOMException), "Should not have DOMException here (2)");
     75      ok(!("code" in e), "Should not have a 'code' property (2)");
     76      is(e.name, "TypeError", "Should be named TypeError");
     77      is(e.message, "We are a TypeError",
     78         "Should also have the right message (2)");
     79      is(e.stack,
     80         `doTest@${file}:71:9
     81 ${asyncFrame}`,
     82         "Exception stack for TypeError should only show our code");
     83      is(e.fileName,
     84         file,
     85         "Should still have the right file name for TypeError");
     86      is(e.lineNumber, 71, "Should still have the right line number for TypeError");
     87      is(e.columnNumber, 9, "Should have the right column number for TypeError");
     88    }
     89 
     90    try {
     91      t.testThrowCallbackError(function() { Array.prototype.forEach(); });
     92    } catch (e) {
     93      ok(e instanceof TypeError, "Should have a TypeError here (3)");
     94      ok(!(e instanceof DOMException), "Should not have DOMException here (3)");
     95      ok(!("code" in e), "Should not have a 'code' property (3)");
     96      is(e.name, "TypeError", "Should be named TypeError (3)");
     97      is(e.message, "missing argument 0 when calling function Array.prototype.forEach",
     98         "Should also have the right message (3)");
     99      is(e.stack,
    100         `doTest/<@${file}:91:61
    101 doTest@${file}:91:9
    102 ${asyncFrame}`,
    103         "Exception stack for TypeError should only show our code (3)");
    104      is(e.fileName,
    105         file,
    106         "Should still have the right file name for TypeError (3)");
    107      is(e.lineNumber, 91, "Should still have the right line number for TypeError (3)");
    108      is(e.columnNumber, 61, "Should have the right column number for TypeError (3)");
    109    }
    110 
    111    try {
    112      t.testThrowXraySelfHosted();
    113    } catch (e) {
    114      ok(!(e instanceof Error), "Should have an Exception here (4)");
    115      ok(!(e instanceof DOMException), "Should not have DOMException here (4)");
    116      ok(!("code" in e), "Should not have a 'code' property (4)");
    117      is(e.name, "NS_ERROR_UNEXPECTED", "Name should be sanitized (4)");
    118      is(e.message, "", "Message should be sanitized (5)");
    119      is(e.stack,
    120         `doTest@${file}:112:9
    121 ${asyncFrame}`,
    122         "Exception stack for sanitized exception should only show our code (4)");
    123      is(e.filename,
    124         file,
    125         "Should still have the right file name for sanitized exception (4)");
    126      is(e.lineNumber, 112, "Should still have the right line number for sanitized exception (4)");
    127      is(e.columnNumber, 9, "Should have the right column number for sanitized exception (4)");
    128    }
    129 
    130    try {
    131      t.testThrowSelfHosted();
    132    } catch (e) {
    133      ok(!(e instanceof Error), "Should have an Exception here (5)");
    134      ok(!(e instanceof DOMException), "Should not have DOMException here (5)");
    135      ok(!("code" in e), "Should not have a 'code' property (5)");
    136      is(e.name, "NS_ERROR_UNEXPECTED", "Name should be sanitized (5)");
    137      is(e.message, "", "Message should be sanitized (5)");
    138      is(e.stack,
    139         `doTest@${file}:131:9
    140 ${asyncFrame}`,
    141         "Exception stack for sanitized exception should only show our code (5)");
    142      is(e.filename,
    143         file,
    144         "Should still have the right file name for sanitized exception (5)");
    145      is(e.lineNumber, 131, "Should still have the right line number for sanitized exception (5)");
    146      is(e.columnNumber, 9, "Should have the right column number for sanitized exception (5)");
    147    }
    148 
    149    SimpleTest.finish();
    150  }
    151 
    152  SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]},
    153                            doTest);
    154  </script>
    155 </head>
    156 <body>
    157 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1107592">Mozilla Bug 1107592</a>
    158 <p id="display"></p>
    159 <div id="content" style="display: none">
    160 
    161 </div>
    162 <pre id="test">
    163 </pre>
    164 </body>
    165 </html>