@@ -298,20 +298,22 @@ export class Arr extends Value {
298
298
299
299
export class Obj extends Value {
300
300
_obj : Map < string , Value > ;
301
- keys : Array < string > ;
302
301
303
302
constructor ( ) {
304
303
super ( ) ;
305
304
this . _obj = new Map ( ) ;
306
- this . keys = new Array ( ) ;
307
305
}
308
306
309
307
toString ( ) : string {
310
- const objs : string [ ] = new Array < string > ( this . keys . length ) ;
311
- for ( let i : i32 = 0 ; i < this . keys . length ; i ++ ) {
312
- const key = this . keys [ i ] ;
313
- const value = this . _obj . get ( key ) || Value . Null ( ) ;
314
- objs [ i ] = `"${ key } ":${ value } ` ;
308
+ const keys = this . _obj . keys ( ) ;
309
+ const objs : string [ ] = new Array < string > ( keys . length ) ;
310
+ for ( let i : i32 = 0 ; i < keys . length ; i ++ ) {
311
+ const key = keys [ i ] ;
312
+ const value = this . _obj . get ( key ) ;
313
+ // Currently must get the string value before interpolation
314
+ // see: https://github.com/AssemblyScript/assemblyscript/issues/1944
315
+ const valStr = value . toString ( ) ;
316
+ objs [ i ] = `"${ key } ":${ valStr } ` ;
315
317
}
316
318
317
319
return `{${ objs . join ( "," ) } }` ;
@@ -321,21 +323,14 @@ export class Obj extends Value {
321
323
return this . _obj ;
322
324
}
323
325
324
-
325
326
set < T > ( key : string , value : T ) : void {
326
327
if ( isReference < T > ( value ) ) {
327
328
if ( value instanceof Value ) {
328
- this . _set ( key , < Value > value ) ;
329
+ this . _obj . set ( key , < Value > value ) ;
329
330
return ;
330
331
}
331
332
}
332
- this . _set ( key , from < T > ( value ) ) ;
333
- }
334
- private _set ( key : string , value : Value ) : void {
335
- if ( ! this . _obj . has ( key ) ) {
336
- this . keys . push ( key ) ;
337
- }
338
- this . _obj . set ( key , value ) ;
333
+ this . _obj . set ( key , from < T > ( value ) ) ;
339
334
}
340
335
341
336
has ( key : string ) : bool {
0 commit comments