Closed Bug 232417 Opened 21 years ago Closed 21 years ago

deCOMtaminate nsIHTMLDocument

Categories

(Core :: DOM: Core & HTML, defect)

x86
All
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: pratik.solanki, Assigned: pratik.solanki)

Details

Attachments

(1 file, 2 obsolete files)

We need to deCOMtaminate nsIHTMLDocument. I'll post a patch soon.
Status: NEW → ASSIGNED
Attached patch Patch, v1 (obsolete) — Splinter Review
Here's the patch. Works on Linux.
Attached patch Path, v2 (obsolete) — Splinter Review
New patch. Addresses biesi's comments on IRC. Callers of GetImageMap now do an
addRef after calling it since I got rid of the addRef from GetImageMap().
Attachment #140379 - Attachment is obsolete: true
Attachment #140420 - Flags: review?(jst)
Comment on attachment 140420 [details] [diff] [review]
Path, v2

- In nsHTMLImageAccessible.cpp:

-      htmlDoc->GetImageMap(mapElementName, getter_AddRefs(mMapElement));      
+      mMapElement = htmlDoc->GetImageMap(mapElementName);
+      NS_ADDREF(mMapElement);

mMapElement is an nsCOMPtr, no need to (and you can't) addref it.

- In content/base/src/nsContentUtils.cpp:

-	   htmlDocument->GetNumFormsSynchronous(&index);
+	   index = htmlDocument->GetNumFormsSynchronous();
	   index--;

How about just:

+	   index = htmlDocument->GetNumFormsSynchronous() - 1;

and avoiding index--?

- In content/base/src/nsRange.cpp:

-	 nsCompatibility compatMode;
-	 htmlDoc->GetCompatibilityMode(compatMode);
+	 nsCompatibility compatMode = htmlDoc->GetCompatibilityMode();
	 switch (compatMode) {

Do we need compatMode here? You can probably just switch on
htmlDoc->GetCompatibilityMode().

- In nsHTMLDocument::RemoveImageMap():

+  if (nsnull != aMap) {
   mImageMaps.RemoveObject(aMap);

Is that null check needed? Seems like it'd be safe to call
mImageMpas.RemoveObject(aMap) even if aMap is null.

- In nsHTMLDocument::GetFormControlElements():

   elements = new nsContentList(this, MatchFormControls, nsString());
-  NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY);
+  //NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY);

Just remove this check, and document in nsIHTMLDocument that this method
returns null only when out of memory (and thus it's up to the callers to check
if they care). You should also make the nsContentUtils code that calls this
method return NS_ERROR_OUT_OF_MEMORY if this method returns null.

- In nsHTMLValue.cpp:

-      nsCompatibility mode;
-      doc->GetCompatibilityMode(mode);
+      nsCompatibility mode = doc->GetCompatibilityMode();
       inNavQuirksMode = (mode == eCompatibility_NavQuirks);

No need for the local variable mode here.

- In nsImageMapUtils.cpp:

-    htmlDoc->GetImageMap(usemap, aMap);
+    *aMap = htmlDoc->GetImageMap(usemap);
+    NS_ADDREF(*aMap);

Shouldn't that be an NS_IF_ADDREF()?

Fix those minor issues and this should be good to go in!
Attachment #140420 - Flags: review?(jst) → review-
Attached patch patch, v3Splinter Review
New patch. Addresses jst's comments. Also, I noticed that I wasn't doing a
NS_ADDREF after calling GetFormControlElements() (which used to do an AddRef
before). Fixed that.
Attachment #140420 - Attachment is obsolete: true
Attachment #140514 - Flags: review?(jst)
Comment on attachment 140514 [details] [diff] [review]
patch, v3

- In nsContentUtils.cpp:

+    nsIDOMNodeList *formControls = htmlDocument->GetFormControlElements();
+    NS_ENSURE_TRUE(formControls, NS_ERROR_OUT_OF_MEMORY);
+    NS_ADDREF(formControls);

Sorry, I mislead you here. This will cause a leak, see comment below.

- In nsHTMLDocument::GetFormControlElements():

-  nsContentList* elements = nsnull;
-  elements = new nsContentList(this, MatchFormControls, nsString());
-  NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY);
-
-  *aReturn = elements;
-  NS_ADDREF(*aReturn);
-
-  return NS_OK;
+  return new nsContentList(this, MatchFormControls, nsString());

I didn't realize that this call always returned a new list, and since that's
the case we need to make this call return a strong reference to keep the
ownership model clean. I made this return already_AddRefed<nsIDOMNodeList> and
made this method addref the new list that it's passing back. That way it's
clear that the caller needs to release it, and when it does, the list will go
away.

Thanks for the patch! I'll fix that above issue and check this in for you.
Attachment #140514 - Flags: superreview+
Attachment #140514 - Flags: review?(jst)
Attachment #140514 - Flags: review+
Fix checked in, keep up the good work!
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Flags: in-testsuite-
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: