psla314 3 Posted July 14, 2022 Hi Does anyone know if you are able to instantiate Objects in free pascal code compiled to Webassembly using https://wiki.freepascal.org/WebAssembly/Compiler We managed to get a wasm running in a browser but as soon as we try to create an object like dummy := TDummy.Create, it gets a memory access violation in the browser console log. I am not even sure creating objects is supported yet, but they do say in the roadmap that Classes are working, so i would have thought it would be working. https://wiki.freepascal.org/WebAssembly/Roadmap We are not passing objects to javascript, we are just wanting to create and use them within the wasm module and pass back standing data types like int real etc. Thanks Peter Share this post Link to post
Fr0sT.Brutal 900 Posted July 14, 2022 I guess you won't get too much help here as it's mostly Delphi forum and your question is too specific. Share this post Link to post
Renaud GHIA 22 Posted July 14, 2022 I confirm you that the webassembly target of freepascal begin to be very robust if you work with the main branch of FPC. All main features of pascal object are supported.Today the compatibility with delphi code is awesome and far superior than with pas2js (where compatibily was already awesome). I already have many delphi units that also compile under freepascal with webassembly target. 1 Share this post Link to post
yatsyk 0 Posted July 16, 2022 Hello Peter, I’ve got similar problem. I’ve found that any heap memory allocation leads to program termination. So even GetMem(1) crashes wasm code. I plan to resume research when I have more time but now I have following ideas for further investigations: May be app compiled for wrong target (WASI but runtime expects embedded or vice versa) Problem related to memory allocation, so may be implement custom memory manager and install it with SetMemoryManager before memory allocations. Conspiracy theory 🙂 May be heap memory allocation doesn’t work on wasm target (contrary to claims on freepascal site). Wasm example code I’ve found on the internets works without issues if I compile it with my compiler and run it in browser. Share this post Link to post