| 330 | == [Clamp](a,p) == #Clamp |
| 331 | |
| 332 | * [http://www.w3.org/TR/2012/CR-WebIDL-20120419/#Clamp The spec of Clamp] |
| 333 | |
| 334 | 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, |
| 335 | rather than using the operators that use a modulo operation (ToInt32, ToUint32, etc.). |
| 336 | |
| 337 | Usage: The [Clamp] extended attribute MUST NOT appear on a read only attribute, or an attribute, operation argument or dictionary member |
| 338 | that is not of an integer type. |
| 339 | |
| 340 | [Clamp] can be specified on writable attributes: |
| 341 | |
| 342 | {{{ |
| 343 | interface XXX { |
| 344 | attribute [Clamp] unsigned short attributeName; |
| 345 | }; |
| 346 | }}} |
| 347 | |
| 348 | [Clamp] can be specified on extended attributes on methods arguments: |
| 349 | |
| 350 | {{{ |
| 351 | interface GraphicsContext { |
| 352 | void setColor(octet red, octet green, octet blue); |
| 353 | void setColorClamped([Clamp] octet red, [Clamp] octet green, [Clamp] octet blue); |
| 354 | }; |
| 355 | }}} |
| 356 | |
| 357 | Calling the non-[Clamp] version of setColor() uses ToUint8 to coerce the Numbers to octets. |
| 358 | Hence calling context.setColor(-1, 255, 257) is equivalent to calling setColor(255, 255, 1). |
| 359 | |
| 360 | Calling the [Clamp] version of setColor() uses clampTo() to coerce the Numbers to octets. |
| 361 | Hence calling context.setColor(-1, 255, 257) is equivalent to calling setColorClamped(0, 255, 255). |
| 362 | |
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). |