/src/mozilla-central/dom/base/DOMError.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=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 "mozilla/UseCounter.h" |
11 | | #include "nsIDocument.h" |
12 | | #include "nsPIDOMWindow.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMError, mWindow) |
18 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMError) |
19 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMError) |
20 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMError) |
21 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
22 | 0 | NS_INTERFACE_MAP_ENTRY(DOMError) |
23 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
24 | 0 | NS_INTERFACE_MAP_END |
25 | | |
26 | | DOMError::DOMError(nsPIDOMWindowInner* aWindow) |
27 | | : mWindow(aWindow) |
28 | 0 | { |
29 | 0 | } |
30 | | |
31 | | DOMError::DOMError(nsPIDOMWindowInner* aWindow, nsresult aValue) |
32 | | : mWindow(aWindow) |
33 | 0 | { |
34 | 0 | nsCString name, message; |
35 | 0 | NS_GetNameAndMessageForDOMNSResult(aValue, name, message); |
36 | 0 |
|
37 | 0 | CopyUTF8toUTF16(name, mName); |
38 | 0 | CopyUTF8toUTF16(message, mMessage); |
39 | 0 | } |
40 | | |
41 | | DOMError::DOMError(nsPIDOMWindowInner* aWindow, const nsAString& aName) |
42 | | : mWindow(aWindow) |
43 | | , mName(aName) |
44 | 0 | { |
45 | 0 | } |
46 | | |
47 | | DOMError::DOMError(nsPIDOMWindowInner* aWindow, const nsAString& aName, |
48 | | const nsAString& aMessage) |
49 | | : mWindow(aWindow) |
50 | | , mName(aName) |
51 | | , mMessage(aMessage) |
52 | 0 | { |
53 | 0 | } |
54 | | |
55 | | DOMError::~DOMError() |
56 | 0 | { |
57 | 0 | } |
58 | | |
59 | | JSObject* |
60 | | DOMError::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
61 | 0 | { |
62 | 0 | return DOMError_Binding::Wrap(aCx, this, aGivenProto); |
63 | 0 | } |
64 | | |
65 | | /* static */ already_AddRefed<DOMError> |
66 | | DOMError::Constructor(const GlobalObject& aGlobal, |
67 | | const nsAString& aName, const nsAString& aMessage, |
68 | | ErrorResult& aRv) |
69 | 0 | { |
70 | 0 | nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports()); |
71 | 0 |
|
72 | 0 | if (window) { |
73 | 0 | nsCOMPtr<nsIDocument> doc = window->GetExtantDoc(); |
74 | 0 | if (doc) { |
75 | 0 | doc->SetDocumentAndPageUseCounter(eUseCounter_custom_DOMErrorConstructor); |
76 | 0 | } |
77 | 0 | } |
78 | 0 |
|
79 | 0 | // Window is null for chrome code. |
80 | 0 |
|
81 | 0 | RefPtr<DOMError> ret = new DOMError(window, aName, aMessage); |
82 | 0 | return ret.forget(); |
83 | 0 | } |
84 | | |
85 | | } // namespace dom |
86 | | } // namespace mozilla |