| 1805 | |
| 1806 | == [Clamp](a,p) == #Clamp |
| 1807 | |
| 1808 | * [http://www.w3.org/TR/2012/CR-WebIDL-20120419/#Clamp The spec of Clamp] |
| 1809 | |
| 1810 | Summary: [Clamp] indicates that when an ECMAScript Number is converted to the IDL type, out of range values will be clamped to the range of valid values, |
| 1811 | rather than using the operators that use a modulo operation (ToInt32, ToUint32, etc.). |
| 1812 | |
| 1813 | Usage: The [Clamp] extended attribute MUST NOT appear on a read only attribute, or an attribute, operation argument or dictionary member |
| 1814 | that is not of an integer type. It also MUST NOT be used in conjunction with the [EnforceRange] extended attribute. |
| 1815 | |
| 1816 | [Clamp] can be specified on writable attributes: |
| 1817 | |
| 1818 | {{{ |
| 1819 | interface XXX { |
| 1820 | attribute [Clamp] unsigned short attributeName; |
| 1821 | }; |
| 1822 | }}} |
| 1823 | |
| 1824 | [Clamp] can be specified on extended attributes on methods arguments: |
| 1825 | |
| 1826 | {{{ |
| 1827 | interface GraphicsContext { |
| 1828 | void setColor(octet red, octet green, octet blue); |
| 1829 | void setColorClamped([Clamp] octet red, [Clamp] octet green, [Clamp] octet blue); |
| 1830 | }; |
| 1831 | }}} |
| 1832 | |
| 1833 | Calling the non-[Clamp] version of setColor() uses ToUint8 to coerce the Numbers to octets. |
| 1834 | Hence calling context.setColor(-1, 255, 257); // Is equivalent to calling setColor(255, 255, 1). |
| 1835 | |
| 1836 | Calling the [Clamp] version of setColor() uses clampTo() to coerce the Numbers to octets. |
| 1837 | Hence calling context.setColor(-1, 255, 257); // Is equivalent to calling setColorClamped(0, 255, 255). |