I've been working on https://github.com/faceless2/quickjs-java (itself derived heavily from https://github.com/StefanRichterHuber/quickjs-wasm-java) to run JS from within Java - I'm aware of https://github.com/roastedroot/quickjs4j, but wanted something with good support for Promises and that was Thread-safe, so have gone a different direction.
It's currently running on Chicory but it looks like the direction of travel is with Endive, so I expect we'll migrate.
To my question: one of the things I wanted to add was a mapping between JS ArrayBuffer and Java ByteBuffer, both with shared access to the same block of memory. I've just had a PR for this which looks like it will work, but because run.endive.runtime.Memory doesn't include any methods for direct acces to an underlying block, the PR includes a rewrite of ByteArrayBufferMemory with that functionality added.
My concern is this approach is going to age badly as the memory model in Endive evolves.
It feels like shared access to a range of Memory is going to be important for wide range of applications. Would you consider adding a method to Memory that returns a ByteBuffer which is a r/w view of a block in the underlying memory? Or is there another approach you'd recommend?
EDIT: I'm aware that due to the way ByteBuffer works in Java this would be impossible if the allocation spanned two pages, but we can deal with that later - it would be OK for the method to fail if this was the case.
I've been working on https://github.com/faceless2/quickjs-java (itself derived heavily from https://github.com/StefanRichterHuber/quickjs-wasm-java) to run JS from within Java - I'm aware of https://github.com/roastedroot/quickjs4j, but wanted something with good support for Promises and that was Thread-safe, so have gone a different direction.
It's currently running on Chicory but it looks like the direction of travel is with Endive, so I expect we'll migrate.
To my question: one of the things I wanted to add was a mapping between JS
ArrayBufferand JavaByteBuffer, both with shared access to the same block of memory. I've just had a PR for this which looks like it will work, but becauserun.endive.runtime.Memorydoesn't include any methods for direct acces to an underlying block, the PR includes a rewrite ofByteArrayBufferMemorywith that functionality added.My concern is this approach is going to age badly as the memory model in Endive evolves.
It feels like shared access to a range of Memory is going to be important for wide range of applications. Would you consider adding a method to
Memorythat returns aByteBufferwhich is a r/w view of a block in the underlying memory? Or is there another approach you'd recommend?EDIT: I'm aware that due to the way
ByteBufferworks in Java this would be impossible if the allocation spanned two pages, but we can deal with that later - it would be OK for the method to fail if this was the case.