|
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 "mozilla/dom/DOMError.h" |
|
8 #include "mozilla/dom/DOMErrorBinding.h" |
|
9 #include "mozilla/dom/DOMException.h" |
|
10 #include "nsPIDOMWindow.h" |
|
11 |
|
12 namespace mozilla { |
|
13 namespace dom { |
|
14 |
|
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMError, mWindow) |
|
16 NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMError) |
|
17 NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMError) |
|
18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMError) |
|
19 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
|
20 NS_INTERFACE_MAP_ENTRY(nsISupports) |
|
21 NS_INTERFACE_MAP_END |
|
22 |
|
23 DOMError::DOMError(nsPIDOMWindow* aWindow) |
|
24 : mWindow(aWindow) |
|
25 { |
|
26 SetIsDOMBinding(); |
|
27 } |
|
28 |
|
29 DOMError::DOMError(nsPIDOMWindow* aWindow, nsresult aValue) |
|
30 : mWindow(aWindow) |
|
31 { |
|
32 nsCString name, message; |
|
33 NS_GetNameAndMessageForDOMNSResult(aValue, name, message); |
|
34 |
|
35 CopyUTF8toUTF16(name, mName); |
|
36 CopyUTF8toUTF16(message, mMessage); |
|
37 |
|
38 SetIsDOMBinding(); |
|
39 } |
|
40 |
|
41 DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName) |
|
42 : mWindow(aWindow) |
|
43 , mName(aName) |
|
44 { |
|
45 SetIsDOMBinding(); |
|
46 } |
|
47 |
|
48 DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName, |
|
49 const nsAString& aMessage) |
|
50 : mWindow(aWindow) |
|
51 , mName(aName) |
|
52 , mMessage(aMessage) |
|
53 { |
|
54 SetIsDOMBinding(); |
|
55 } |
|
56 |
|
57 DOMError::~DOMError() |
|
58 { |
|
59 } |
|
60 |
|
61 JSObject* |
|
62 DOMError::WrapObject(JSContext* aCx) |
|
63 { |
|
64 return DOMErrorBinding::Wrap(aCx, this); |
|
65 } |
|
66 |
|
67 /* static */ already_AddRefed<DOMError> |
|
68 DOMError::Constructor(const GlobalObject& aGlobal, |
|
69 const nsAString& aName, const nsAString& aMessage, |
|
70 ErrorResult& aRv) |
|
71 { |
|
72 nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports()); |
|
73 |
|
74 // Window is null for chrome code. |
|
75 |
|
76 nsRefPtr<DOMError> ret = new DOMError(window, aName, aMessage); |
|
77 return ret.forget(); |
|
78 } |
|
79 |
|
80 } // namespace dom |
|
81 } // namespace mozilla |