JairusSW / as-json

The only JSON library you'll need for AssemblyScript. SIMD enabled
MIT License
79 stars 15 forks source link

Json serialization for map throwing error #80

Closed spino17 closed 4 months ago

spino17 commented 5 months ago

I am trying to compile and run below code:


import { JSON } from "json-as/assembly";

@json
class Inner {
  name: string;

  constructor(name: string) {
    this.name = name;
  }
}

@json
class Outer {
  name: string;
  m: Map<string, Inner>;

  constructor(name: string) {
    this.name = name;
    this.m = new Map();
  }
}

export function init(): void {
  let serializedState = JSON.stringify<Outer>(new Outer("bhavya"));
}

command: npm run asbuild runs fine. When I am running it using the release.js wrapped function, it is throwing below error:

wasm://wasm/0001a6ba:1

RuntimeError: memory access out of bounds
    at wasm://wasm/0001a6ba:wasm-function[25]:0x159f
    at wasm://wasm/0001a6ba:wasm-function[26]:0x5905
    at wasm://wasm/0001a6ba:wasm-function[27]:0x5ce2
    at file:///<BASE-FILE-PATH>/tests/index.js:2:13

. And if I replace Inner with u64 like below:


@json
class Outer {
  name: string;
  m: Map<string, u64>;

  constructor(name: string) {
    this.name = name;
    this.m = new Map();
  }
}

It is working fine.

JairusSW commented 4 months ago

Thanks, taking a look in a moment

spino17 commented 4 months ago

Thanks @JairusSW for the response. Let me know if you need more information about the system on which I am running the example.

JairusSW commented 4 months ago

Just checking, but your using v0.9.8 (latest) I presume?

spino17 commented 4 months ago

No, I am using ^0.8.8 and visitor-as with ^0.11.4

JairusSW commented 4 months ago

Empty maps threw an out of bounds exception. Now they are properly handled and return {}

Fixed as of json-as@0.9.8a

spino17 commented 4 months ago

Thanks @JairusSW for mentioning this! It's working fine with this version.