1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/DOMError.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "mozilla/dom/DOMError.h" 1.11 +#include "mozilla/dom/DOMErrorBinding.h" 1.12 +#include "mozilla/dom/DOMException.h" 1.13 +#include "nsPIDOMWindow.h" 1.14 + 1.15 +namespace mozilla { 1.16 +namespace dom { 1.17 + 1.18 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMError, mWindow) 1.19 +NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMError) 1.20 +NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMError) 1.21 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMError) 1.22 + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 1.23 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.24 +NS_INTERFACE_MAP_END 1.25 + 1.26 +DOMError::DOMError(nsPIDOMWindow* aWindow) 1.27 + : mWindow(aWindow) 1.28 +{ 1.29 + SetIsDOMBinding(); 1.30 +} 1.31 + 1.32 +DOMError::DOMError(nsPIDOMWindow* aWindow, nsresult aValue) 1.33 + : mWindow(aWindow) 1.34 +{ 1.35 + nsCString name, message; 1.36 + NS_GetNameAndMessageForDOMNSResult(aValue, name, message); 1.37 + 1.38 + CopyUTF8toUTF16(name, mName); 1.39 + CopyUTF8toUTF16(message, mMessage); 1.40 + 1.41 + SetIsDOMBinding(); 1.42 +} 1.43 + 1.44 +DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName) 1.45 + : mWindow(aWindow) 1.46 + , mName(aName) 1.47 +{ 1.48 + SetIsDOMBinding(); 1.49 +} 1.50 + 1.51 +DOMError::DOMError(nsPIDOMWindow* aWindow, const nsAString& aName, 1.52 + const nsAString& aMessage) 1.53 + : mWindow(aWindow) 1.54 + , mName(aName) 1.55 + , mMessage(aMessage) 1.56 +{ 1.57 + SetIsDOMBinding(); 1.58 +} 1.59 + 1.60 +DOMError::~DOMError() 1.61 +{ 1.62 +} 1.63 + 1.64 +JSObject* 1.65 +DOMError::WrapObject(JSContext* aCx) 1.66 +{ 1.67 + return DOMErrorBinding::Wrap(aCx, this); 1.68 +} 1.69 + 1.70 +/* static */ already_AddRefed<DOMError> 1.71 +DOMError::Constructor(const GlobalObject& aGlobal, 1.72 + const nsAString& aName, const nsAString& aMessage, 1.73 + ErrorResult& aRv) 1.74 +{ 1.75 + nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports()); 1.76 + 1.77 + // Window is null for chrome code. 1.78 + 1.79 + nsRefPtr<DOMError> ret = new DOMError(window, aName, aMessage); 1.80 + return ret.forget(); 1.81 +} 1.82 + 1.83 +} // namespace dom 1.84 +} // namespace mozilla