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/. */
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 "mozilla/dom/Document.h"
12 #include "nsPIDOMWindow.h"
17 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMError
, mWindow
)
18 NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMError
)
19 NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMError
)
20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMError
)
21 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22 NS_INTERFACE_MAP_ENTRY(DOMError
)
23 NS_INTERFACE_MAP_ENTRY(nsISupports
)
26 DOMError::DOMError(nsPIDOMWindowInner
* aWindow
) : mWindow(aWindow
) {}
28 DOMError::DOMError(nsPIDOMWindowInner
* aWindow
, nsresult aValue
)
30 nsCString name
, message
;
31 NS_GetNameAndMessageForDOMNSResult(aValue
, name
, message
);
33 CopyUTF8toUTF16(name
, mName
);
34 CopyUTF8toUTF16(message
, mMessage
);
37 DOMError::DOMError(nsPIDOMWindowInner
* aWindow
, const nsAString
& aName
)
38 : mWindow(aWindow
), mName(aName
) {}
40 DOMError::DOMError(nsPIDOMWindowInner
* aWindow
, const nsAString
& aName
,
41 const nsAString
& aMessage
)
42 : mWindow(aWindow
), mName(aName
), mMessage(aMessage
) {}
44 DOMError::~DOMError() {}
46 JSObject
* DOMError::WrapObject(JSContext
* aCx
,
47 JS::Handle
<JSObject
*> aGivenProto
) {
48 return DOMError_Binding::Wrap(aCx
, this, aGivenProto
);
52 already_AddRefed
<DOMError
> DOMError::Constructor(const GlobalObject
& aGlobal
,
53 const nsAString
& aName
,
54 const nsAString
& aMessage
,
56 nsCOMPtr
<nsPIDOMWindowInner
> window
=
57 do_QueryInterface(aGlobal
.GetAsSupports());
60 nsCOMPtr
<Document
> doc
= window
->GetExtantDoc();
62 doc
->SetDocumentAndPageUseCounter(eUseCounter_custom_DOMErrorConstructor
);
66 // Window is null for chrome code.
68 RefPtr
<DOMError
> ret
= new DOMError(window
, aName
, aMessage
);
73 } // namespace mozilla