@@ -136,7 +136,7 @@ export namespace Message {
136136 export function updateModule ( wasm : string ) : Request < Ack > {
137137 function payload ( binary : Buffer ) : string {
138138 const w = new Uint8Array ( binary ) ;
139- const sizeHex : string = WASM . leb128 ( w . length ) ;
139+ const sizeHex : string = WASM . leb128 ( BigInt ( w . length ) ) ;
140140 const sizeBuffer = Buffer . allocUnsafe ( 4 ) ;
141141 sizeBuffer . writeUint32BE ( w . length ) ;
142142 const wasmHex = Buffer . from ( w ) . toString ( 'hex' ) ;
@@ -162,7 +162,7 @@ export namespace Message {
162162 }
163163 }
164164
165- export function invoke ( func : string , args : Value [ ] ) : Request < WASM . Value | Exception > {
165+ export function invoke ( func : string , args : Value < bigint | number > [ ] ) : Request < WASM . Value < bigint | number > | Exception > {
166166 function fidx ( map : SourceMap . Mapping , func : string ) : number {
167167 const fidx : number | void = map . functions . find ( ( closure : SourceMap . Closure ) => closure . name === func ) ?. index ;
168168 if ( fidx === undefined ) {
@@ -171,14 +171,14 @@ export namespace Message {
171171 return fidx ! ;
172172 }
173173
174- function convert ( args : Value [ ] ) {
174+ function convert ( args : Value < bigint | number > [ ] ) {
175175 let payload : string = '' ;
176- args . forEach ( ( arg : Value ) => {
176+ args . forEach ( ( arg : Value < bigint | number > ) => {
177177 if ( arg . type === Type . i32 || arg . type === Type . i64 ) {
178178 payload += WASM . leb128 ( arg . value ) ;
179179 } else {
180180 const buff = Buffer . alloc ( arg . type === Type . f32 ? 4 : 8 ) ;
181- write ( buff , arg . value , 0 , true , arg . type === Type . f32 ? 23 : 52 , buff . length ) ;
181+ write ( buff , Number ( arg . value ) , 0 , true , arg . type === Type . f32 ? 23 : 52 , buff . length ) ; // todo fix precision loss
182182 payload += buff . toString ( 'hex' ) ;
183183 }
184184 } ) ;
@@ -187,7 +187,7 @@ export namespace Message {
187187
188188 return {
189189 type : Interrupt . invoke ,
190- payload : ( map : SourceMap . Mapping ) => `${ WASM . leb128 ( fidx ( map , func ) ) } ${ convert ( args ) } ` ,
190+ payload : ( map : SourceMap . Mapping ) => `${ WASM . leb128 ( BigInt ( fidx ( map , func ) ) ) } ${ convert ( args ) } ` ,
191191 parser : invokeParser
192192 }
193193 }
0 commit comments