michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/DOMError.h" michael@0: #include "mozilla/dom/DOMErrorBinding.h" michael@0: #include "mozilla/dom/DOMException.h" michael@0: #include "nsPIDOMWindow.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMError, mWindow) michael@0: NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMError) michael@0: NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMError) michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMError) michael@0: NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY michael@0: NS_INTERFACE_MAP_ENTRY(nsISupports) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: DOMError::DOMError(nsPIDOMWindow* aWindow) michael@0: : mWindow(aWindow) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: DOMError::DOMError(nsPIDOMWindow* aWindow, nsresult aValue) michael@0: : mWindow(aWindow) michael@0: { michael@0: nsCString name, message; michael@0: NS_GetNameAndMessageForDOMNSResult(aValue, name, message); michael@0: michael@0: CopyUTF8toUTF16(name, mName); michael@0: CopyUTF8toUTF16(message, mMessage); michael@0: michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName) michael@0: : mWindow(aWindow) michael@0: , mName(aName) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName, michael@0: const nsAString& aMessage) michael@0: : mWindow(aWindow) michael@0: , mName(aName) michael@0: , mMessage(aMessage) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: DOMError::~DOMError() michael@0: { michael@0: } michael@0: michael@0: JSObject* michael@0: DOMError::WrapObject(JSContext* aCx) michael@0: { michael@0: return DOMErrorBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: /* static */ already_AddRefed michael@0: DOMError::Constructor(const GlobalObject& aGlobal, michael@0: const nsAString& aName, const nsAString& aMessage, michael@0: ErrorResult& aRv) michael@0: { michael@0: nsCOMPtr window = do_QueryInterface(aGlobal.GetAsSupports()); michael@0: michael@0: // Window is null for chrome code. michael@0: michael@0: nsRefPtr ret = new DOMError(window, aName, aMessage); michael@0: return ret.forget(); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla