| 1 |
"use strict"; |
| 2 |
module.exports = DOMException; |
| 3 |
|
| 4 |
var INDEX_SIZE_ERR = 1; |
| 5 |
var HIERARCHY_REQUEST_ERR = 3; |
| 6 |
var WRONG_DOCUMENT_ERR = 4; |
| 7 |
var INVALID_CHARACTER_ERR = 5; |
| 8 |
var NO_MODIFICATION_ALLOWED_ERR = 7; |
| 9 |
var NOT_FOUND_ERR = 8; |
| 10 |
var NOT_SUPPORTED_ERR = 9; |
| 11 |
var INVALID_STATE_ERR = 11; |
| 12 |
var SYNTAX_ERR = 12; |
| 13 |
var INVALID_MODIFICATION_ERR = 13; |
| 14 |
var NAMESPACE_ERR = 14; |
| 15 |
var INVALID_ACCESS_ERR = 15; |
| 16 |
var TYPE_MISMATCH_ERR = 17; |
| 17 |
var SECURITY_ERR = 18; |
| 18 |
var NETWORK_ERR = 19; |
| 19 |
var ABORT_ERR = 20; |
| 20 |
var URL_MISMATCH_ERR = 21; |
| 21 |
var QUOTA_EXCEEDED_ERR = 22; |
| 22 |
var TIMEOUT_ERR = 23; |
| 23 |
var INVALID_NODE_TYPE_ERR = 24; |
| 24 |
var DATA_CLONE_ERR = 25; |
| 25 |
|
| 26 |
// Code to name |
| 27 |
var names = [ |
| 28 |
null, // No error with code 0 |
| 29 |
'INDEX_SIZE_ERR', |
| 30 |
null, // historical |
| 31 |
'HIERARCHY_REQUEST_ERR', |
| 32 |
'WRONG_DOCUMENT_ERR', |
| 33 |
'INVALID_CHARACTER_ERR', |
| 34 |
null, // historical |
| 35 |
'NO_MODIFICATION_ALLOWED_ERR', |
| 36 |
'NOT_FOUND_ERR', |
| 37 |
'NOT_SUPPORTED_ERR', |
| 38 |
'INUSE_ATTRIBUTE_ERR', // historical |
| 39 |
'INVALID_STATE_ERR', |
| 40 |
'SYNTAX_ERR', |
| 41 |
'INVALID_MODIFICATION_ERR', |
| 42 |
'NAMESPACE_ERR', |
| 43 |
'INVALID_ACCESS_ERR', |
| 44 |
null, // historical |
| 45 |
'TYPE_MISMATCH_ERR', |
| 46 |
'SECURITY_ERR', |
| 47 |
'NETWORK_ERR', |
| 48 |
'ABORT_ERR', |
| 49 |
'URL_MISMATCH_ERR', |
| 50 |
'QUOTA_EXCEEDED_ERR', |
| 51 |
'TIMEOUT_ERR', |
| 52 |
'INVALID_NODE_TYPE_ERR', |
| 53 |
'DATA_CLONE_ERR', |
| 54 |
]; |
| 55 |
|
| 56 |
// Code to message |
| 57 |
// These strings are from the 13 May 2011 Editor's Draft of DOM Core. |
| 58 |
// http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html |
| 59 |
// Copyright © 2011 W3C® (MIT, ERCIM, Keio), All Rights Reserved. |
| 60 |
// Used under the terms of the W3C Document License: |
| 61 |
// http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231 |
| 62 |
var messages = [ |
| 63 |
null, // No error with code 0 |
| 64 |
'INDEX_SIZE_ERR (1): the index is not in the allowed range', |
| 65 |
null, |
| 66 |
'HIERARCHY_REQUEST_ERR (3): the operation would yield an incorrect nodes model', |
| 67 |
'WRONG_DOCUMENT_ERR (4): the object is in the wrong Document, a call to importNode is required', |
| 68 |
'INVALID_CHARACTER_ERR (5): the string contains invalid characters', |
| 69 |
null, |
| 70 |
'NO_MODIFICATION_ALLOWED_ERR (7): the object can not be modified', |
| 71 |
'NOT_FOUND_ERR (8): the object can not be found here', |
| 72 |
'NOT_SUPPORTED_ERR (9): this operation is not supported', |
| 73 |
'INUSE_ATTRIBUTE_ERR (10): setAttributeNode called on owned Attribute', |
| 74 |
'INVALID_STATE_ERR (11): the object is in an invalid state', |
| 75 |
'SYNTAX_ERR (12): the string did not match the expected pattern', |
| 76 |
'INVALID_MODIFICATION_ERR (13): the object can not be modified in this way', |
| 77 |
'NAMESPACE_ERR (14): the operation is not allowed by Namespaces in XML', |
| 78 |
'INVALID_ACCESS_ERR (15): the object does not support the operation or argument', |
| 79 |
null, |
| 80 |
'TYPE_MISMATCH_ERR (17): the type of the object does not match the expected type', |
| 81 |
'SECURITY_ERR (18): the operation is insecure', |
| 82 |
'NETWORK_ERR (19): a network error occurred', |
| 83 |
'ABORT_ERR (20): the user aborted an operation', |
| 84 |
'URL_MISMATCH_ERR (21): the given URL does not match another URL', |
| 85 |
'QUOTA_EXCEEDED_ERR (22): the quota has been exceeded', |
| 86 |
'TIMEOUT_ERR (23): a timeout occurred', |
| 87 |
'INVALID_NODE_TYPE_ERR (24): the supplied node is invalid or has an invalid ancestor for this operation', |
| 88 |
'DATA_CLONE_ERR (25): the object can not be cloned.' |
| 89 |
]; |
| 90 |
|
| 91 |
// Name to code |
| 92 |
var constants = { |
| 93 |
INDEX_SIZE_ERR: INDEX_SIZE_ERR, |
| 94 |
DOMSTRING_SIZE_ERR: 2, // historical |
| 95 |
HIERARCHY_REQUEST_ERR: HIERARCHY_REQUEST_ERR, |
| 96 |
WRONG_DOCUMENT_ERR: WRONG_DOCUMENT_ERR, |
| 97 |
INVALID_CHARACTER_ERR: INVALID_CHARACTER_ERR, |
| 98 |
NO_DATA_ALLOWED_ERR: 6, // historical |
| 99 |
NO_MODIFICATION_ALLOWED_ERR: NO_MODIFICATION_ALLOWED_ERR, |
| 100 |
NOT_FOUND_ERR: NOT_FOUND_ERR, |
| 101 |
NOT_SUPPORTED_ERR: NOT_SUPPORTED_ERR, |
| 102 |
INUSE_ATTRIBUTE_ERR: 10, // historical |
| 103 |
INVALID_STATE_ERR: INVALID_STATE_ERR, |
| 104 |
SYNTAX_ERR: SYNTAX_ERR, |
| 105 |
INVALID_MODIFICATION_ERR: INVALID_MODIFICATION_ERR, |
| 106 |
NAMESPACE_ERR: NAMESPACE_ERR, |
| 107 |
INVALID_ACCESS_ERR: INVALID_ACCESS_ERR, |
| 108 |
VALIDATION_ERR: 16, // historical |
| 109 |
TYPE_MISMATCH_ERR: TYPE_MISMATCH_ERR, |
| 110 |
SECURITY_ERR: SECURITY_ERR, |
| 111 |
NETWORK_ERR: NETWORK_ERR, |
| 112 |
ABORT_ERR: ABORT_ERR, |
| 113 |
URL_MISMATCH_ERR: URL_MISMATCH_ERR, |
| 114 |
QUOTA_EXCEEDED_ERR: QUOTA_EXCEEDED_ERR, |
| 115 |
TIMEOUT_ERR: TIMEOUT_ERR, |
| 116 |
INVALID_NODE_TYPE_ERR: INVALID_NODE_TYPE_ERR, |
| 117 |
DATA_CLONE_ERR: DATA_CLONE_ERR |
| 118 |
}; |
| 119 |
|
| 120 |
function DOMException(code) { |
| 121 |
Error.call(this); |
| 122 |
Error.captureStackTrace(this, this.constructor); |
| 123 |
this.code = code; |
| 124 |
this.message = messages[code]; |
| 125 |
this.name = names[code]; |
| 126 |
} |
| 127 |
DOMException.prototype.__proto__ = Error.prototype; |
| 128 |
|
| 129 |
// Initialize the constants on DOMException and DOMException.prototype |
| 130 |
for(var c in constants) { |
| 131 |
var v = { value: constants[c] }; |
| 132 |
Object.defineProperty(DOMException, c, v); |
| 133 |
Object.defineProperty(DOMException.prototype, c, v); |
| 134 |
} |