@@ -22,8 +22,8 @@ function DBusBuffer (buffer, startPos, endian, options) {
2222}
2323
2424DBusBuffer . prototype . align = function ( power ) {
25- var allbits = ( 1 << power ) - 1 ;
26- var paddedOffset = ( ( this . pos + this . startPos + allbits ) >> power ) << power ;
25+ const allbits = ( 1 << power ) - 1 ;
26+ const paddedOffset = ( ( this . pos + this . startPos + allbits ) >> power ) << power ;
2727 this . pos = paddedOffset - this . startPos ;
2828} ;
2929
@@ -35,7 +35,7 @@ DBusBuffer.prototype.readInt8 = function () {
3535DBusBuffer . prototype . readSInt16 = function ( ) {
3636 this . align ( 1 ) ;
3737
38- var res = ( this . endian === LE
38+ const res = ( this . endian === LE
3939 ? this . buffer . readInt16LE ( this . pos )
4040 : this . buffer . readInt16BE ( this . pos ) ) ;
4141
@@ -46,7 +46,7 @@ DBusBuffer.prototype.readSInt16 = function () {
4646DBusBuffer . prototype . readInt16 = function ( ) {
4747 this . align ( 1 ) ;
4848
49- var res = ( this . endian === LE
49+ const res = ( this . endian === LE
5050 ? this . buffer . readUInt16LE ( this . pos )
5151 : this . buffer . readUInt16BE ( this . pos ) ) ;
5252
@@ -57,7 +57,7 @@ DBusBuffer.prototype.readInt16 = function () {
5757DBusBuffer . prototype . readSInt32 = function ( ) {
5858 this . align ( 2 ) ;
5959
60- var res = ( this . endian === LE
60+ const res = ( this . endian === LE
6161 ? this . buffer . readInt32LE ( this . pos )
6262 : this . buffer . readInt32BE ( this . pos ) ) ;
6363
@@ -68,7 +68,7 @@ DBusBuffer.prototype.readSInt32 = function () {
6868DBusBuffer . prototype . readInt32 = function ( ) {
6969 this . align ( 2 ) ;
7070
71- var res = ( this . endian === LE
71+ const res = ( this . endian === LE
7272 ? this . buffer . readUInt32LE ( this . pos )
7373 : this . buffer . readUInt32BE ( this . pos ) ) ;
7474
@@ -79,7 +79,7 @@ DBusBuffer.prototype.readInt32 = function () {
7979DBusBuffer . prototype . readDouble = function ( ) {
8080 this . align ( 3 ) ;
8181
82- var res = ( this . endian === LE
82+ const res = ( this . endian === LE
8383 ? this . buffer . readDoubleLE ( this . pos )
8484 : this . buffer . readDoubleBE ( this . pos ) ) ;
8585
@@ -92,7 +92,7 @@ DBusBuffer.prototype.readString = function (len) {
9292 this . pos ++ ;
9393 return '' ;
9494 }
95- var res = this . buffer . toString ( 'utf8' , this . pos , this . pos + len ) ;
95+ const res = this . buffer . toString ( 'utf8' , this . pos , this . pos + len ) ;
9696 this . pos += len + 1 ; // dbus strings are always zero-terminated ('s' and 'g' types)
9797 return res ;
9898} ;
@@ -105,9 +105,10 @@ DBusBuffer.prototype.readTree = function readTree (tree) {
105105 this . align ( 3 ) ;
106106 return this . readStruct ( tree . child ) ;
107107 case 'a' :
108- if ( ! tree . child || tree . child . length !== 1 ) { throw new Error ( 'Incorrect array element signature' ) ; }
109- var arrayBlobLength = this . readInt32 ( ) ;
110- return this . readArray ( tree . child [ 0 ] , arrayBlobLength ) ;
108+ if ( ! tree . child || tree . child . length !== 1 ) {
109+ throw new Error ( 'Incorrect array element signature' ) ;
110+ }
111+ return this . readArray ( tree . child [ 0 ] , this . readInt32 ( ) ) ;
111112 case 'v' :
112113 return this . readVariant ( ) ;
113114 default :
@@ -116,27 +117,27 @@ DBusBuffer.prototype.readTree = function readTree (tree) {
116117} ;
117118
118119DBusBuffer . prototype . read = function read ( signature ) {
119- var tree = parseSignature ( signature ) ;
120+ const tree = parseSignature ( signature ) ;
120121 return this . readStruct ( tree ) ;
121122} ;
122123
123124DBusBuffer . prototype . readVariant = function readVariant ( ) {
124- var signature = this . readSimpleType ( 'g' ) ;
125- var tree = parseSignature ( signature ) ;
125+ const signature = this . readSimpleType ( 'g' ) ;
126+ const tree = parseSignature ( signature ) ;
126127 return [ tree , this . readStruct ( tree ) ] ;
127128} ;
128129
129130DBusBuffer . prototype . readStruct = function readStruct ( struct ) {
130- var result = [ ] ;
131- for ( var i = 0 ; i < struct . length ; ++ i ) {
131+ const result = [ ] ;
132+ for ( let i = 0 ; i < struct . length ; ++ i ) {
132133 result . push ( this . readTree ( struct [ i ] ) ) ;
133134 }
134135 return result ;
135136} ;
136137
137138DBusBuffer . prototype . readArray = function readArray ( eleType , arrayBlobSize ) {
138- var result ;
139- var start = this . pos ;
139+ const result = [ ] ;
140+ const start = this . pos ;
140141
141142 // special case: treat ay as Buffer
142143 if ( eleType . type === 'y' && this . options . ayBuffer ) {
@@ -147,15 +148,18 @@ DBusBuffer.prototype.readArray = function readArray (eleType, arrayBlobSize) {
147148 // end of array is start of first element + array size
148149 // we need to add 4 bytes if not on 8-byte boundary
149150 // and array element needs 8 byte alignment
150- if ( [ 'x' , 't' , 'd' , '{' , '(' , 'r' ] . indexOf ( eleType . type ) !== - 1 ) { this . align ( 3 ) ; }
151- var end = this . pos + arrayBlobSize ;
152- result = [ ] ;
153- while ( this . pos < end ) result . push ( this . readTree ( eleType ) ) ;
151+ if ( [ 'x' , 't' , 'd' , '{' , '(' , 'r' ] . indexOf ( eleType . type ) !== - 1 ) {
152+ this . align ( 3 ) ;
153+ }
154+ const end = this . pos + arrayBlobSize ;
155+ while ( this . pos < end ) {
156+ result . push ( this . readTree ( eleType ) ) ;
157+ }
154158 return result ;
155159} ;
156160
157161DBusBuffer . prototype . readSimpleType = function readSimpleType ( t ) {
158- var len , word0 , word1 ;
162+ let len , word0 , word1 ;
159163 switch ( t ) {
160164 case 'y' :
161165 return this . readInt8 ( ) ;
0 commit comments