lib/types/Octet.js
/**
     * The result of converting an IDL octet value to an ECMAScript value
     * is a Number that represents
     * the same numeric value as the IDL octet value. The Number value will
     * be an integer in the range [0, 255].
     * @param {any} V - the value to convert.
     */
The result of converting an IDL octet value to an ECMAScript value
is a Number that represents
the same numeric value as the IDL octet value. The Number value will
be an integer in the range [0, 255].
@param {any} V - the value to convert.
The result of converting an IDL octet value to an ECMAScript value is a Number that represents the same numeric value as the IDL octet value . The Number value will be an integer in the range [ 0 255 ] . @param { any } V - the value to convert .
function converter(V, extendedAttr) {
        var x = Number(V),
            n;
        function isNegative0(x) {
            if (x !== 0) return false;
            var obj = Object.freeze({
                z: -0
            });
            try {
                Object.defineProperty(obj, 'z', {
                    value: x
                });
            } catch (e) {
                return false;
            }
            return true;
        }
        if (extendedAttr === 'EnforceRange') {
            if (isNaN(x) || x === +Infinity || x === -Infinity) {
                throw new TypeError();
            }
            x = ((x > 0) ? 1 : -1) * Math.floor(Math.abs(x));
            if (x < 0 || x > (Math.pow(2, 8) - 1)) {
                throw new TypeError();
            }
            return x;
        }
        if (!(isNaN(x)) && extendedAttr === 'Clamp') {
            x = Math.min(Math.max(x, 0), Math.pow(2, 8) - 1);
            x = Math.abs(x - Math.round(x)) === 0.5 ? (((Math.round(x) % 2) === 0) ? Math.round(x) : Math.floor(x)) : Math.round(x);
            x = (x === 0 && isNegative0(x)) ? +0 : x;
            return x;
        }
        if (isNaN(x) || x === 0 || x === +Infinity || x === -Infinity) {
            return 0;
        }
        x = ((x > 0) ? 1 : -1) * Math.floor(Math.abs(x));
        n = Math.pow(2, 8);
        x = ((x % n) + n) % n; 
        return x;
    }
function converter ( V , extendedAttr ) { var x = Number ( V ) , n ; function isNegative0 ( x ) { if ( x !== 0 ) return false ; var obj = Object . freeze ( { z : - 0 } ) ; try { Object . defineProperty ( obj , 'z' , { value : x } ) ; } catch ( e ) { return false ; } return true ; } if ( extendedAttr === 'EnforceRange' ) { if ( isNaN ( x ) || x === + Infinity || x === - Infinity ) { throw new TypeError ( ) ; } x = ( ( x > 0 ) ? 1 : - 1 ) * Math . floor ( Math . abs ( x ) ) ; if ( x < 0 || x > ( Math . pow ( 2 , 8 ) - 1 ) ) { throw new TypeError ( ) ; } return x ; } if ( ! ( isNaN ( x ) ) && extendedAttr === 'Clamp' ) { x = Math . min ( Math . max ( x , 0 ) , Math . pow ( 2 , 8 ) - 1 ) ; x = Math . abs ( x - Math . round ( x ) ) === 0.5 ? ( ( ( Math . round ( x ) % 2 ) === 0 ) ? Math . round ( x ) : Math . floor ( x ) ) : Math . round ( x ) ; x = ( x === 0 && isNegative0 ( x ) ) ? + 0 : x ; return x ; } if ( isNaN ( x ) || x === 0 || x === + Infinity || x === - Infinity ) { return 0 ; } x = ( ( x > 0 ) ? 1 : - 1 ) * Math . floor ( Math . abs ( x ) ) ; n = Math . pow ( 2 , 8 ) ; x = ( ( x % n ) + n ) % n ; return x ; }
The result of converting an IDL octet value to an ECMAScript value
 is a Number that represents
 the same numeric value as the IDL octet value.
The result of converting an IDL octet value to an ECMAScript value is a Number that represents the same numeric value as the IDL octet value .
//Initialize x to ToNumber(V). //If the conversion to an IDL value is being performed due to any of the following: //V is being assigned to an attribute annotated with the [EnforceRange] extended attribute, //V is being passed as an operation argument annotated with the [EnforceRange] extended attribute, or //V is being used as the value of dictionary member annotated with the [EnforceRange] extended attribute, //then: //If x is NaN, +∞, or −∞, then throw a TypeError. //Set x to sign(x) * floor(abs(x)). //If x < 0 or x > 28 − 1, then throw a TypeError. //Return the IDL octet value that represents the same numeric value as x. //If x is not NaN and the conversion to an IDL value is being performed due to any of the following: //V is being assigned to an attribute annotated with the //[Clamp] extended attribute, //V is being passed as an operation argument annotated //with the [Clamp] extended attribute, or //V is being used as the value of dictionary member //annotated with the [Clamp] extended attribute, //then: //Set x to min(max(x, 0), 28 − 1). //Round x to the nearest integer, choosing the even integer if it lies halfway between two. //and choosing +0 rather than −0. //Return the IDL octet value that represents the same numeric value as x. //If x is NaN, +0, −0, +∞, or −∞, then return the IDL octet value that represents 0. //Set x to sign(x) * floor(abs(x)). //Set x to x modulo 28. //x % Math.pow(2, 8); //Return the IDL octet value that represents the same numeric value as x.