tor-browser

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

DOMException-constructor-behavior.any.js (5678B)


      1 // META: global=window,dedicatedworker,shadowrealm
      2 
      3 'use strict';
      4 
      5 test(function() {
      6  var ex = new DOMException();
      7  assert_equals(ex.name, "Error",
      8                "Not passing a name should end up with 'Error' as the name");
      9  assert_equals(ex.message, "",
     10                "Not passing a message should end up with empty string as the message");
     11 }, 'new DOMException()');
     12 
     13 test(function() {
     14  var ex = new DOMException();
     15  assert_false(ex.hasOwnProperty("name"),
     16               "The name property should be inherited");
     17  assert_false(ex.hasOwnProperty("message"),
     18               "The message property should be inherited");
     19 }, 'new DOMException(): inherited-ness');
     20 
     21 test(function() {
     22  var ex = new DOMException(null);
     23  assert_equals(ex.name, "Error",
     24                "Not passing a name should end up with 'Error' as the name");
     25  assert_equals(ex.message, "null",
     26                "Passing null as message should end up with stringified 'null' as the message");
     27 }, 'new DOMException(null)');
     28 
     29 test(function() {
     30  var ex = new DOMException(undefined);
     31  assert_equals(ex.name, "Error",
     32                "Not passing a name should end up with 'Error' as the name");
     33  assert_equals(ex.message, "",
     34                "Not passing a message should end up with empty string as the message");
     35 }, 'new DOMException(undefined)');
     36 
     37 test(function() {
     38  var ex = new DOMException(undefined);
     39  assert_false(ex.hasOwnProperty("name"),
     40               "The name property should be inherited");
     41  assert_false(ex.hasOwnProperty("message"),
     42               "The message property should be inherited");
     43 }, 'new DOMException(undefined): inherited-ness');
     44 
     45 test(function() {
     46  var ex = new DOMException("foo");
     47  assert_equals(ex.name, "Error",
     48                "Not passing a name should still end up with 'Error' as the name");
     49  assert_equals(ex.message, "foo", "Should be using passed-in message");
     50 }, 'new DOMException("foo")');
     51 
     52 test(function() {
     53  var ex = new DOMException("foo");
     54  assert_false(ex.hasOwnProperty("name"),
     55               "The name property should be inherited");
     56  assert_false(ex.hasOwnProperty("message"),
     57              "The message property should be inherited");
     58 }, 'new DOMException("foo"): inherited-ness');
     59 
     60 test(function() {
     61  var ex = new DOMException("bar", undefined);
     62  assert_equals(ex.name, "Error",
     63                "Passing undefined for name should end up with 'Error' as the name");
     64  assert_equals(ex.message, "bar", "Should still be using passed-in message");
     65 }, 'new DOMException("bar", undefined)');
     66 
     67 test(function() {
     68  var ex = new DOMException("bar", "NotSupportedError");
     69  assert_equals(ex.name, "NotSupportedError", "Should be using the passed-in name");
     70  assert_equals(ex.message, "bar", "Should still be using passed-in message");
     71  assert_equals(ex.code, DOMException.NOT_SUPPORTED_ERR,
     72                "Should have the right exception code");
     73 }, 'new DOMException("bar", "NotSupportedError")');
     74 
     75 test(function() {
     76  var ex = new DOMException("bar", "NotSupportedError");
     77  assert_false(ex.hasOwnProperty("name"),
     78              "The name property should be inherited");
     79  assert_false(ex.hasOwnProperty("message"),
     80              "The message property should be inherited");
     81 }, 'new DOMException("bar", "NotSupportedError"): inherited-ness');
     82 
     83 test(function() {
     84  var ex = new DOMException("bar", "foo");
     85  assert_equals(ex.name, "foo", "Should be using the passed-in name");
     86  assert_equals(ex.message, "bar", "Should still be using passed-in message");
     87  assert_equals(ex.code, 0,
     88                "Should have 0 for code for a name not in the exception names table");
     89 }, 'new DOMException("bar", "foo")');
     90 
     91 [
     92  {name: "IndexSizeError", code: 1},
     93  {name: "HierarchyRequestError", code: 3},
     94  {name: "WrongDocumentError", code: 4},
     95  {name: "InvalidCharacterError", code: 5},
     96  {name: "NoModificationAllowedError", code: 7},
     97  {name: "NotFoundError", code: 8},
     98  {name: "NotSupportedError", code: 9},
     99  {name: "InUseAttributeError", code: 10},
    100  {name: "InvalidStateError", code: 11},
    101  {name: "SyntaxError", code: 12},
    102  {name: "InvalidModificationError", code: 13},
    103  {name: "NamespaceError", code: 14},
    104  {name: "InvalidAccessError", code: 15},
    105  {name: "TypeMismatchError", code: 17},
    106  {name: "SecurityError", code: 18},
    107  {name: "NetworkError", code: 19},
    108  {name: "AbortError", code: 20},
    109  {name: "URLMismatchError", code: 21},
    110  {name: "QuotaExceededError", code: 22},
    111  {name: "TimeoutError", code: 23},
    112  {name: "InvalidNodeTypeError", code: 24},
    113  {name: "DataCloneError", code: 25},
    114 
    115  // These were removed from the error names table.
    116  // See https://github.com/heycam/webidl/pull/946.
    117  {name: "DOMStringSizeError", code: 0},
    118  {name: "NoDataAllowedError", code: 0},
    119  {name: "ValidationError", code: 0},
    120 
    121  // The error names which don't have legacy code values.
    122  {name: "EncodingError", code: 0},
    123  {name: "NotReadableError", code: 0},
    124  {name: "UnknownError", code: 0},
    125  {name: "ConstraintError", code: 0},
    126  {name: "DataError", code: 0},
    127  {name: "TransactionInactiveError", code: 0},
    128  {name: "ReadOnlyError", code: 0},
    129  {name: "VersionError", code: 0},
    130  {name: "OperationError", code: 0},
    131  {name: "NotAllowedError", code: 0}
    132 ].forEach(function(test_case) {
    133  test(function() {
    134    var ex = new DOMException("msg", test_case.name);
    135    assert_equals(ex.name, test_case.name,
    136                  "Should be using the passed-in name");
    137    assert_equals(ex.message, "msg",
    138                  "Should be using the passed-in message");
    139    assert_equals(ex.code, test_case.code,
    140                  "Should have matching legacy code from error names table");
    141  },'new DOMexception("msg", "' + test_case.name + '")');
    142 });