Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / base / DOMError.cpp
blob370f6033d9818ced0b3583ddc5df85c8e0cf8505
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/. */
7 #include "mozilla/dom/DOMError.h"
8 #include "mozilla/dom/DOMErrorBinding.h"
9 #include "mozilla/dom/DOMException.h"
10 #include "nsPIDOMWindow.h"
12 namespace mozilla {
13 namespace dom {
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(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(DOMError)
21 NS_INTERFACE_MAP_ENTRY(nsISupports)
22 NS_INTERFACE_MAP_END
24 DOMError::DOMError(nsPIDOMWindow* aWindow)
25 : mWindow(aWindow)
27 SetIsDOMBinding();
30 DOMError::DOMError(nsPIDOMWindow* aWindow, nsresult aValue)
31 : mWindow(aWindow)
33 nsCString name, message;
34 NS_GetNameAndMessageForDOMNSResult(aValue, name, message);
36 CopyUTF8toUTF16(name, mName);
37 CopyUTF8toUTF16(message, mMessage);
39 SetIsDOMBinding();
42 DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName)
43 : mWindow(aWindow)
44 , mName(aName)
46 SetIsDOMBinding();
49 DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName,
50 const nsAString& aMessage)
51 : mWindow(aWindow)
52 , mName(aName)
53 , mMessage(aMessage)
55 SetIsDOMBinding();
58 DOMError::~DOMError()
62 JSObject*
63 DOMError::WrapObject(JSContext* aCx)
65 return DOMErrorBinding::Wrap(aCx, this);
68 /* static */ already_AddRefed<DOMError>
69 DOMError::Constructor(const GlobalObject& aGlobal,
70 const nsAString& aName, const nsAString& aMessage,
71 ErrorResult& aRv)
73 nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
75 // Window is null for chrome code.
77 nsRefPtr<DOMError> ret = new DOMError(window, aName, aMessage);
78 return ret.forget();
81 } // namespace dom
82 } // namespace mozilla