@@ -61,6 +61,8 @@ const ParameterType = {
6161 PARAMETER_DOUBLE_ARRAY : 8 ,
6262 /** @member {number} */
6363 PARAMETER_STRING_ARRAY : 9 ,
64+ /** @member {number} */
65+ PARAMETER_BYTE : 10 ,
6466} ;
6567
6668/**
@@ -125,7 +127,9 @@ class Parameter {
125127 constructor ( name , type , value ) {
126128 this . _name = name ;
127129 this . _type = type ;
128- this . _value = value ;
130+ // Convert to bigint if it's type of integer.
131+ this . _value =
132+ this . _type == ParameterType . PARAMETER_INTEGER ? BigInt ( value ) : value ;
129133 this . _isDirty = true ;
130134
131135 this . validate ( ) ;
@@ -240,10 +244,10 @@ class Parameter {
240244 msg . double_array_value = this . value ;
241245 break ;
242246 case ParameterType . PARAMETER_INTEGER :
243- msg . integer_value = Math . trunc ( this . value ) ;
247+ msg . integer_value = this . value ;
244248 break ;
245249 case ParameterType . PARAMETER_INTEGER_ARRAY :
246- msg . integer_array_value = this . value . map ( ( val ) => Math . trunc ( val ) ) ;
250+ msg . integer_array_value = this . value ;
247251 break ;
248252 case ParameterType . PARAMETER_STRING :
249253 msg . string_value = this . value ;
@@ -540,7 +544,7 @@ class Range {
540544 * A TypeError is thrown when value is not a number.
541545 * Subclasses should override and call this method for basic type checking.
542546 *
543- * @param {number } value - The number to check.
547+ * @param {number|bigint } value - The number or bigint to check.
544548 * @return {boolean } - True if value satisfies the range; false otherwise.
545549 */
546550 inRange ( value ) {
@@ -550,8 +554,8 @@ class Range {
550554 ( inRange , val ) => inRange && this . inRange ( val ) ,
551555 true
552556 ) ;
553- } else if ( typeof value !== 'number' ) {
554- throw new TypeError ( 'Value must be a number' ) ;
557+ } else if ( typeof value !== 'number' && typeof value !== 'bigint' ) {
558+ throw new TypeError ( 'Value must be a number or bigint ' ) ;
555559 }
556560
557561 return true ;
@@ -652,27 +656,16 @@ class FloatingPointRange extends Range {
652656 * Defines a range for integer values.
653657 * @class
654658 */
655- class IntegerRange extends FloatingPointRange {
659+ class IntegerRange extends Range {
656660 /**
657661 * Create a new instance.
658662 * @constructor
659- * @param {number } fromValue - The lowest inclusive value in range
660- * @param {number } toValue - The highest inclusive value in range
661- * @param {number } step - The internal unit size.
662- * @param {number } tolerance - The plus/minus tolerance for number equivalence.
663+ * @param {bigint } fromValue - The lowest inclusive value in range
664+ * @param {bigint } toValue - The highest inclusive value in range
665+ * @param {bigint } step - The internal unit size.
663666 */
664- constructor (
665- fromValue ,
666- toValue ,
667- step = 1 ,
668- tolerance = DEFAULT_NUMERIC_RANGE_TOLERANCE
669- ) {
670- super (
671- Math . trunc ( fromValue ) ,
672- Math . trunc ( toValue ) ,
673- Math . trunc ( step ) ,
674- tolerance
675- ) ;
667+ constructor ( fromValue , toValue , step = 1n ) {
668+ super ( fromValue , toValue , step ) ;
676669 }
677670
678671 /**
@@ -689,6 +682,19 @@ class IntegerRange extends FloatingPointRange {
689682 parameterType === ParameterType . PARAMETER_INTEGER_ARRAY ;
690683 return result ;
691684 }
685+
686+ inRange ( value ) {
687+ const min = this . fromValue ;
688+ const max = this . toValue ;
689+ if ( value < min || value > max ) {
690+ return false ;
691+ }
692+
693+ if ( this . step != 0n && ( value - min ) % this . step !== 0n ) {
694+ return false ;
695+ }
696+ return true ;
697+ }
692698}
693699
694700/**
@@ -763,10 +769,13 @@ function validValue(value, type) {
763769 case ParameterType . PARAMETER_STRING :
764770 result = typeof value === 'string' ;
765771 break ;
766- case ParameterType . PARAMETER_INTEGER :
767772 case ParameterType . PARAMETER_DOUBLE :
773+ case ParameterType . PARAMETER_BYTE :
768774 result = typeof value === 'number' ;
769775 break ;
776+ case ParameterType . PARAMETER_INTEGER :
777+ result = typeof value === 'bigint' ;
778+ break ;
770779 case ParameterType . PARAMETER_BOOL_ARRAY :
771780 case ParameterType . PARAMETER_BYTE_ARRAY :
772781 case ParameterType . PARAMETER_INTEGER_ARRAY :
@@ -789,7 +798,7 @@ function _validArray(values, type) {
789798 if ( type === ParameterType . PARAMETER_BOOL_ARRAY ) {
790799 arrayElementType = ParameterType . PARAMETER_BOOL ;
791800 } else if ( type === ParameterType . PARAMETER_BYTE_ARRAY ) {
792- arrayElementType = ParameterType . PARAMETER_INTEGER ;
801+ arrayElementType = ParameterType . PARAMETER_BYTE ;
793802 }
794803 if ( type === ParameterType . PARAMETER_INTEGER_ARRAY ) {
795804 arrayElementType = ParameterType . PARAMETER_INTEGER ;
0 commit comments