Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "mozilla/dom/DOMError.h" |
michael@0 | 8 | #include "mozilla/dom/DOMErrorBinding.h" |
michael@0 | 9 | #include "mozilla/dom/DOMException.h" |
michael@0 | 10 | #include "nsPIDOMWindow.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | namespace dom { |
michael@0 | 14 | |
michael@0 | 15 | NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMError, mWindow) |
michael@0 | 16 | NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMError) |
michael@0 | 17 | NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMError) |
michael@0 | 18 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMError) |
michael@0 | 19 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
michael@0 | 20 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 21 | NS_INTERFACE_MAP_END |
michael@0 | 22 | |
michael@0 | 23 | DOMError::DOMError(nsPIDOMWindow* aWindow) |
michael@0 | 24 | : mWindow(aWindow) |
michael@0 | 25 | { |
michael@0 | 26 | SetIsDOMBinding(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | DOMError::DOMError(nsPIDOMWindow* aWindow, nsresult aValue) |
michael@0 | 30 | : mWindow(aWindow) |
michael@0 | 31 | { |
michael@0 | 32 | nsCString name, message; |
michael@0 | 33 | NS_GetNameAndMessageForDOMNSResult(aValue, name, message); |
michael@0 | 34 | |
michael@0 | 35 | CopyUTF8toUTF16(name, mName); |
michael@0 | 36 | CopyUTF8toUTF16(message, mMessage); |
michael@0 | 37 | |
michael@0 | 38 | SetIsDOMBinding(); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName) |
michael@0 | 42 | : mWindow(aWindow) |
michael@0 | 43 | , mName(aName) |
michael@0 | 44 | { |
michael@0 | 45 | SetIsDOMBinding(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName, |
michael@0 | 49 | const nsAString& aMessage) |
michael@0 | 50 | : mWindow(aWindow) |
michael@0 | 51 | , mName(aName) |
michael@0 | 52 | , mMessage(aMessage) |
michael@0 | 53 | { |
michael@0 | 54 | SetIsDOMBinding(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | DOMError::~DOMError() |
michael@0 | 58 | { |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | JSObject* |
michael@0 | 62 | DOMError::WrapObject(JSContext* aCx) |
michael@0 | 63 | { |
michael@0 | 64 | return DOMErrorBinding::Wrap(aCx, this); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | /* static */ already_AddRefed<DOMError> |
michael@0 | 68 | DOMError::Constructor(const GlobalObject& aGlobal, |
michael@0 | 69 | const nsAString& aName, const nsAString& aMessage, |
michael@0 | 70 | ErrorResult& aRv) |
michael@0 | 71 | { |
michael@0 | 72 | nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports()); |
michael@0 | 73 | |
michael@0 | 74 | // Window is null for chrome code. |
michael@0 | 75 | |
michael@0 | 76 | nsRefPtr<DOMError> ret = new DOMError(window, aName, aMessage); |
michael@0 | 77 | return ret.forget(); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | } // namespace dom |
michael@0 | 81 | } // namespace mozilla |