From 5ea7d22a433b07b0b338866a2ea1643f231f88ae Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Tue, 16 Dec 2008 12:26:42 +0100 Subject: [PATCH] Add a few missing null-checks. Return error code from GetRuleLine() when it fails. b=462787 r+sr=dbaron --- layout/Makefile.in | 3 + layout/inspector/src/inDOMUtils.cpp | 28 ++++---- layout/inspector/tests/Makefile.in | 52 ++++++++++++++ layout/inspector/tests/test_bug462787.html | 81 ++++++++++++++++++++++ 4 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 layout/inspector/tests/Makefile.in create mode 100644 layout/inspector/tests/test_bug462787.html diff --git a/layout/Makefile.in b/layout/Makefile.in index b7388940a9b..bb083c23648 100644 --- a/layout/Makefile.in +++ b/layout/Makefile.in @@ -71,6 +71,9 @@ endif ifndef MOZ_NO_INSPECTOR_APIS PARALLEL_DIRS += inspector/public inspector/src +ifdef ENABLE_TESTS +PARALLEL_DIRS += inspector/tests +endif endif DIRS += build diff --git a/layout/inspector/src/inDOMUtils.cpp b/layout/inspector/src/inDOMUtils.cpp index 74e2815157b..ccf63db7ebc 100644 --- a/layout/inspector/src/inDOMUtils.cpp +++ b/layout/inspector/src/inDOMUtils.cpp @@ -73,9 +73,10 @@ NS_IMETHODIMP inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode, PRBool *aReturn) { - NS_PRECONDITION(aDataNode, "Must have a character data node"); NS_PRECONDITION(aReturn, "Must have an out parameter"); + NS_ENSURE_ARG_POINTER(aDataNode); + *aReturn = PR_FALSE; nsCOMPtr content = do_QueryInterface(aDataNode); @@ -119,7 +120,9 @@ inDOMUtils::GetParentForNode(nsIDOMNode* aNode, PRBool aShowingAnonymousContent, nsIDOMNode** aParent) { - // First do the special cases -- document nodes and anonymous content + NS_ENSURE_ARG_POINTER(aNode); + + // First do the special cases -- document nodes and anonymous content nsCOMPtr doc(do_QueryInterface(aNode)); nsCOMPtr parent; @@ -151,7 +154,7 @@ NS_IMETHODIMP inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement, nsISupportsArray **_retval) { - if (!aElement) return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aElement); *_retval = nsnull; @@ -194,27 +197,29 @@ NS_IMETHODIMP inDOMUtils::GetRuleLine(nsIDOMCSSStyleRule *aRule, PRUint32 *_retval) { *_retval = 0; - if (!aRule) - return NS_OK; + + NS_ENSURE_ARG_POINTER(aRule); + nsCOMPtr rule = do_QueryInterface(aRule); nsCOMPtr cssrule; - rule->GetCSSStyleRule(getter_AddRefs(cssrule)); - if (cssrule) - *_retval = cssrule->GetLineNumber(); + nsresult rv = rule->GetCSSStyleRule(getter_AddRefs(cssrule)); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(cssrule != nsnull, NS_ERROR_FAILURE); + *_retval = cssrule->GetLineNumber(); return NS_OK; } NS_IMETHODIMP inDOMUtils::GetBindingURLs(nsIDOMElement *aElement, nsIArray **_retval) { + NS_ENSURE_ARG_POINTER(aElement); return mCSSUtils->GetBindingURLs(aElement, _retval); } NS_IMETHODIMP inDOMUtils::SetContentState(nsIDOMElement *aElement, PRInt32 aState) { - if (!aElement) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aElement); nsCOMPtr esm = inLayoutUtils::GetEventStateManagerFor(aElement); if (esm) { @@ -232,8 +237,7 @@ inDOMUtils::GetContentState(nsIDOMElement *aElement, PRInt32* aState) { *aState = 0; - if (!aElement) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aElement); nsCOMPtr esm = inLayoutUtils::GetEventStateManagerFor(aElement); if (esm) { diff --git a/layout/inspector/tests/Makefile.in b/layout/inspector/tests/Makefile.in new file mode 100644 index 00000000000..eb2ac6ebf9d --- /dev/null +++ b/layout/inspector/tests/Makefile.in @@ -0,0 +1,52 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is +# Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2008 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either of the GNU General Public License Version 2 or later (the "GPL"), +# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ +relativesrcdir = layout/inspector/tests + +include $(DEPTH)/config/autoconf.mk +include $(topsrcdir)/config/rules.mk + +_TEST_FILES =\ + test_bug462787.html \ + $(NULL) + +libs:: $(_TEST_FILES) + $(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) diff --git a/layout/inspector/tests/test_bug462787.html b/layout/inspector/tests/test_bug462787.html new file mode 100644 index 00000000000..0027f6a097f --- /dev/null +++ b/layout/inspector/tests/test_bug462787.html @@ -0,0 +1,81 @@ + + + + + Test for Bug 462787 + + + + + +Mozilla Bug 462787 +

+ +
+
+
+ +