Handling out of range integer values

Hi all,

Consider the following code:

var node = SomeAudioNode();
node.channelCount = 5000000000;

Currently, according to the spec, channelCount is an unsigned long, which
means that a Web IDL conforming implementation must convert the value being
passed in to a 32-bit unsigned integer using the algorithm in [1], which is
basically using the modulo operation.

This means that the implementation of the channelCount setter will see a
value which is sort of unexpected -- definitely not what the author wants.

I think it makes sense for us to go through the spec and use either [Clamp]
[2] or [EnforceRange] [3] on our unsigned long and similar numeric types.
I prefer [EnforceRange] myself because I think exceptions are better than
silently clamping these values.

What do others think?

[1] http://www.w3.org/TR/WebIDL/#es-unsigned-long
[2] http://www.w3.org/TR/WebIDL/#Clamp
[3] http://www.w3.org/TR/WebIDL/#EnforceRange

--
Ehsan
<http://ehsanakhgari.org/>

Received on Tuesday, 28 May 2013 15:38:25 UTC