1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "DOMError.h"
8 :
9 : #include "mozilla/Util.h"
10 : #include "nsDOMClassInfo.h"
11 :
12 : using mozilla::ArrayLength;
13 : using mozilla::dom::DOMError;
14 :
15 : namespace {
16 :
17 : struct NameMap
18 : {
19 : PRUint16 code;
20 : const char* name;
21 : };
22 :
23 : } // anonymous namespace
24 :
25 : // static
26 : already_AddRefed<nsIDOMDOMError>
27 0 : DOMError::CreateForDOMExceptionCode(PRUint16 aDOMExceptionCode)
28 : {
29 : // All of these codes (and yes, some are skipped) come from the spec.
30 : static const NameMap kNames[] = {
31 : { 1, "IndexSizeError" },
32 : { 3, "HierarchyRequestError" },
33 : { 4, "WrongDocumentError" },
34 : { 5, "InvalidCharacterError" },
35 : { 7, "NoModificationAllowedError" },
36 : { 8, "NotFoundError" },
37 : { 9, "NotSupportedError" },
38 : { 11, "InvalidStateError" },
39 : { 12, "SyntaxError" },
40 : { 13, "InvalidModificationError" },
41 : { 14, "NamespaceError" },
42 : { 15, "InvalidAccessError" },
43 : { 17, "TypeMismatchError" },
44 : { 18, "SecurityError" },
45 : { 19, "NetworkError" },
46 : { 20, "AbortError" },
47 : { 21, "URLMismatchError" },
48 : { 22, "QuotaExceededError" },
49 : { 23, "TimeoutError" },
50 : { 24, "InvalidNodeTypeError" },
51 : { 25, "DataCloneError" }
52 : };
53 :
54 0 : for (size_t index = 0; index < ArrayLength(kNames); index++) {
55 0 : if (kNames[index].code == aDOMExceptionCode) {
56 0 : nsString name;
57 0 : name.AssignASCII(kNames[index].name);
58 0 : return CreateWithName(name);
59 : }
60 : }
61 :
62 0 : NS_NOTREACHED("Unknown DOMException code!");
63 0 : return nsnull;
64 : }
65 :
66 0 : NS_IMPL_ADDREF(DOMError)
67 0 : NS_IMPL_RELEASE(DOMError)
68 :
69 0 : NS_INTERFACE_MAP_BEGIN(DOMError)
70 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMError)
71 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMDOMError)
72 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
73 0 : NS_INTERFACE_MAP_END
74 :
75 : DOMCI_DATA(DOMError, DOMError)
76 :
77 : NS_IMETHODIMP
78 0 : DOMError::GetName(nsAString& aName)
79 : {
80 0 : aName = mName;
81 0 : return NS_OK;
82 : }
|