fix: add support for exposing functions that return objects #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been experimenting with this library and ran into a problem which is best illustrated with this simple test:
While attempting to call
evalCode
, aLifetime not alive
error is thrown. I traced the issue to an instance whereVMMap::_mapSet
was attempting to be called in the VM but was not alive.I believe the
_mapSet
instance was no longer alive because the originalVMMap
used to marshal the return value was created ephemerally here:quickjs-emscripten-sync/src/index.ts
Lines 196 to 197 in 21a7fd8
Then, it is merged with the
Arena::map
instance again before it is disposed via.dispose()
, here:quickjs-emscripten-sync/src/index.ts
Lines 219 to 221 in 21a7fd8
Then, some time after the ephemeral map is disposed of, a callback passed to
.consume
must be executed and at this point_mapSet
has already been disposed:quickjs-emscripten-sync/src/vmmap.ts
Lines 87 to 102 in 203f8ae
To get around this, I'm avoiding the creation of the ephemeral map entirely, and instead I'm pointing directly to the
Arena::map
instance.This fixed the issue and didn't appear to cause any new test failures, but I'm not certain this change is actually safe and would love to know what you think.
Thank you for your help, and for sharing your hard work - your library has been a pleasure to work with. 🙇♂️