From 13db67d14b2f581eb2d211f85362a349c9200709 Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Wed, 23 Apr 2014 13:59:47 +0800 Subject: [PATCH] Bug 929701 - Part 2: Implement DOMMMIError by C++. r=smaug --- dom/mobileconnection/src/DOMMMIError.cpp | 55 +++++++++++++++++++ dom/mobileconnection/src/DOMMMIError.h | 54 ++++++++++++++++++ dom/mobileconnection/src/moz.build | 2 + .../mochitest/general/test_interfaces.html | 2 +- 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 dom/mobileconnection/src/DOMMMIError.cpp create mode 100644 dom/mobileconnection/src/DOMMMIError.h diff --git a/dom/mobileconnection/src/DOMMMIError.cpp b/dom/mobileconnection/src/DOMMMIError.cpp new file mode 100644 index 000000000000..ced3ae191cbe --- /dev/null +++ b/dom/mobileconnection/src/DOMMMIError.cpp @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this file, +* You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "DOMMMIError.h" +#include "mozilla/dom/DOMMMIErrorBinding.h" + +using namespace mozilla::dom; + +NS_IMPL_CYCLE_COLLECTION_CLASS(DOMMMIError) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DOMMMIError, DOMError) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DOMMMIError, DOMError) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMMMIError) +NS_INTERFACE_MAP_END_INHERITING(DOMError) + +NS_IMPL_ADDREF_INHERITED(DOMMMIError, DOMError) +NS_IMPL_RELEASE_INHERITED(DOMMMIError, DOMError) + +DOMMMIError::DOMMMIError(nsPIDOMWindow* aWindow, const nsAString& aName, + const nsAString& aMessage, const nsAString& aServiceCode, + const Nullable& aInfo) + : DOMError(aWindow, aName, aMessage) + , mServiceCode(aServiceCode) + , mInfo(aInfo) +{ +} + +JSObject* +DOMMMIError::WrapObject(JSContext* aCx) +{ + return DOMMMIErrorBinding::Wrap(aCx, this); +} + +// WebIDL interface + +/* static */ already_AddRefed +DOMMMIError::Constructor(const GlobalObject& aGlobal, + const nsAString& aServiceCode, + const nsAString& aName, + const nsAString& aMessage, + const Nullable& aInfo, + ErrorResult& aRv) { + nsCOMPtr window = do_QueryInterface(aGlobal.GetAsSupports()); + nsRefPtr error = new DOMMMIError(window, aName, aMessage, + aServiceCode, aInfo); + + return error.forget(); +} diff --git a/dom/mobileconnection/src/DOMMMIError.h b/dom/mobileconnection/src/DOMMMIError.h new file mode 100644 index 000000000000..ed883f70cbbe --- /dev/null +++ b/dom/mobileconnection/src/DOMMMIError.h @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this file, +* You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_MmiError_h +#define mozilla_dom_MmiError_h + +#include "mozilla/dom/DOMError.h" + +namespace mozilla { +namespace dom { + +class DOMMMIError MOZ_FINAL : public DOMError +{ +public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMMMIError, DOMError) + + DOMMMIError(nsPIDOMWindow* aWindow, const nsAString& aName, + const nsAString& aMessage, const nsAString& aServiceCode, + const Nullable& aInfo); + + virtual JSObject* + WrapObject(JSContext* aCx) MOZ_OVERRIDE; + + // WebIDL interface + static already_AddRefed + Constructor(const GlobalObject& aGlobal, const nsAString& aServiceCode, + const nsAString& aName, const nsAString& aMessage, + const Nullable& aInfo, ErrorResult& aRv); + + void + GetServiceCode(nsString& aServiceCode) const + { + aServiceCode = mServiceCode; + } + + Nullable + GetAdditionalInformation() const + { + return mInfo; + } + +private: + nsString mServiceCode; + Nullable mInfo; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_MmiError_h diff --git a/dom/mobileconnection/src/moz.build b/dom/mobileconnection/src/moz.build index f6a3f5e9268d..e0ec2dbc0871 100644 --- a/dom/mobileconnection/src/moz.build +++ b/dom/mobileconnection/src/moz.build @@ -5,11 +5,13 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXPORTS.mozilla.dom += [ + 'DOMMMIError.h', 'MobileConnection.h', 'MobileConnectionArray.h', ] SOURCES += [ + 'DOMMMIError.cpp', 'MobileConnection.cpp', 'MobileConnectionArray.cpp', ] diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index f9ba81b15f99..82f220354e65 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -304,7 +304,7 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "DOMImplementation", // IMPORTANT: Do not change this list without review from a DOM peer! - "DOMMMIError", + {name: "DOMMMIError", b2g: true, pref: "dom.mobileconnection.enabled"}, // IMPORTANT: Do not change this list without review from a DOM peer! "DOMParser", // IMPORTANT: Do not change this list without review from a DOM peer!