Closed Bug 1314026 Opened 8 years ago Closed 8 years ago

colspan and rowspan setters should not stealth-cast unsigned ints to ints

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla52
Tracking Status
firefox52 --- fixed

People

(Reporter: bzbarsky, Assigned: bzbarsky)

Details

Attachments

(1 file)

The call to SetHTMLIntAttr casts to int.  So if you do:

  td.colSpan = 2147483648;

you get "-2147483648" as the attribute value.  This is quite odd.
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
Comment on attachment 8805954 [details] [diff] [review]
Add a SetHTMLUIntAttr function that does the right thing with setters for unsigned long IDL attributes that reflect a content attribute

Review of attachment 8805954 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/html/nsGenericHTMLElement.h
@@ +979,5 @@
>  
>      SetHTMLAttr(aName, value, aError);
>    }
>  
> +  void SetHTMLUIntAttr(nsIAtom* aName, uint32_t aValue, mozilla::ErrorResult& aError)

This is fine, but we could remove some duplication if we use a template:

template <typename T>
void SetHTMLIntAttr(nsIAtom* aName, T aValue, mozilla::ErrorResult& aError)
{
  nsAutoString value;
  value.AppendInt(aValue);
  SetHTMLAttr(aName, value, aError);
}
Attachment #8805954 - Flags: review?(bkelly) → review+
That's true.  I wasn't quite sure whether it was better to do that or to make the caller's desire for int/uint be explicit....
Thoughts on the implicit vs explicit thing?
Flags: needinfo?(bkelly)
(In reply to Boris Zbarsky [:bz] (still a bit busy) from comment #4)
> Thoughts on the implicit vs explicit thing?

I don't feel super strong either way.  I think since we have AppendInt() that works for both signed and unsigned in our string API that there is precedent for not including the full type in the method name.
Flags: needinfo?(bkelly)
OK.  Thought about it some more, and calling the int overload with an unsigned value that doesn't fit in int makes no sense, and calling the uint overload with a negative-valued int would also be nonsense.  So I went ahead with the template approach.
Pushed by bzbarsky@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/933e7a735a80
Add a version of SetHTMLIntAttr that does the right thing with an unsigned argument, for use from setters for unsigned long IDL attributes that reflect a content attribute.  r=bkelly
https://hg.mozilla.org/mozilla-central/rev/933e7a735a80
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: