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