summaryrefslogtreecommitdiff
path: root/op_crates/web/00_dom_exception.js
blob: 5fb130452484fdd915b80bfc598fd7c54312617e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

((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;
      this.#code = nameToCodeMapping[name] ?? 0;
    }

    get name() {
      return this.#name;
    }

    get code() {
      return this.#code;
    }
  }

  window.DOMException = DOMException;
})(this);