summaryrefslogtreecommitdiff
path: root/op_crates/web/00_dom_exception.js
diff options
context:
space:
mode:
authorYacine Hmito <yacinehmito@users.noreply.github.com>2021-01-09 07:27:46 +0100
committerGitHub <noreply@github.com>2021-01-09 07:27:46 +0100
commit96372097657685b5655bba95ce5a329364a9301b (patch)
tree7f0fda60e9cdad0c4a4862e86f8c1e45e3f92f82 /op_crates/web/00_dom_exception.js
parentf3ead9c6a7184d2b592f018795f73d34399a9c83 (diff)
fix(web): implement DOMException#code (#9015)
Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
Diffstat (limited to 'op_crates/web/00_dom_exception.js')
-rw-r--r--op_crates/web/00_dom_exception.js55
1 files changed, 45 insertions, 10 deletions
diff --git a/op_crates/web/00_dom_exception.js b/op_crates/web/00_dom_exception.js
index 6d72779b0..5fb130452 100644
--- a/op_crates/web/00_dom_exception.js
+++ b/op_crates/web/00_dom_exception.js
@@ -1,15 +1,50 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-class DOMException extends Error {
- #name = "";
+((window) => {
+ const nameToCodeMapping = Object.create(
+ null,
+ {
+ IndexSizeError: { value: 1 },
+ HierarchyRequestError: { value: 3 },
+ WrongDocumentError: { value: 4 },
+ InvalidCharacterError: { value: 5 },
+ NoModificationAllowedError: { value: 7 },
+ NotFoundError: { value: 8 },
+ NotSupportedError: { value: 9 },
+ InvalidStateError: { value: 11 },
+ SyntaxError: { value: 12 },
+ InvalidModificationError: { value: 13 },
+ NamespaceError: { value: 14 },
+ InvalidAccessError: { value: 15 },
+ TypeMismatchError: { value: 17 },
+ SecurityError: { value: 18 },
+ NetworkError: { value: 19 },
+ AbortError: { value: 20 },
+ URLMismatchError: { value: 21 },
+ QuotaExceededError: { value: 22 },
+ TimeoutError: { value: 23 },
+ InvalidNodeTypeError: { value: 24 },
+ DataCloneError: { value: 25 },
+ },
+ );
+ class DOMException extends Error {
+ #name = "";
+ #code = 0;
- constructor(message = "", name = "Error") {
- super(message);
- this.#name = name;
- }
+ constructor(message = "", name = "Error") {
+ super(message);
+ this.#name = name;
+ this.#code = nameToCodeMapping[name] ?? 0;
+ }
+
+ get name() {
+ return this.#name;
+ }
- get name() {
- return this.#name;
+ get code() {
+ return this.#code;
+ }
}
-}
+
+ window.DOMException = DOMException;
+})(this);