Re: convertToSpecifiedUnits and zero units

On Fri, Aug 26, 2011 at 6:36 PM, Dean Jackson <dino@apple.com> wrote:
> On 24/08/2011, at 10:49 PM, Øyvind Stenhaug wrote:
>> Units
>>
>> This doesn't seem to consider what happens if the unitType argument is a zero length, e.g. SVG_LENGTHTYPE_EMS when 1em=0px.
>>
>> <svg xmlns="http://www.w3.org/2000/svg" font-size="0">
>>   <rect width="100px"/>
>>   <script type="application/ecmascript">
>>      onload = function() {
>>         try {
>>            var width = document.querySelector('rect').width.baseVal;
>>            width.convertToSpecifiedUnits(width.SVG_LENGTHTYPE_EMS);
>>            alert(width.valueInSpecifiedUnits + ' ' + width.value);
>>         } catch(e) {
>>            alert(e);
>>         }
>>      }
>>   </script>
>> </svg>
>>
>> Gecko and Presto give "Infinity NaN", failing to "[p]reserve the same underlying stored value".
>>
>> WebKit throws NOT_SUPPORTED_ERR, although the spec only says it's "[r]aised if unitType is SVG_LENGTHTYPE_UNKNOWN or not a valid unit type constant (one of the other SVG_LENGTHTYPE_* constants defined on this interface)".
>>
>> (When trying to convert a zero value, Presto gives "0 0", Gecko "NaN NaN" and WebKit still throws.)
>
> The WebKit behaviour here is a bug which is easily fixed, but what values do you suggest we return?

I believe the specced behavior is buggy, and everyone should throw
when the original length is non-zero and the specified unit is
zero-length.  When the original length is zero, the new value should
be zero in the new unit.

If there's compat impact there, I suggest silently failing (as if you
attempted to specify an invalid value, which "Infinityem" is), but
throwing is preferable to me.

~TJ

Received on Saturday, 27 August 2011 01:54:24 UTC