quickjs-emscripten-sync icon indicating copy to clipboard operation
quickjs-emscripten-sync copied to clipboard

Possible to synchronize vm -> host -> vm?

Open emilmuller opened this issue 3 years ago • 2 comments

Hi

I'm trying to compare objects which crosses from VM -> host -> VM. This seems to fail. See the example below. Is it possible to add support for this? :)

Kind regards, Emil

(async () => {
    const vm = (await getQuickJS()).createVm();
    const arena = new Arena(vm, { isMarshalable: true });

    function test(obj) {
        return obj;
    }

    arena.expose({ test });
    console.log(arena.evalCode(`let foo = {}; foo === test(foo)`)); // I want this to log 'true', but it logs 'false'

    arena.dispose();
    vm.dispose();
})();

Also, thanks for this great library! :)

emilmuller avatar Oct 11 '21 08:10 emilmuller

Interestingly, a slight modification of the above code produces an error:

(async () => {
    const vm = (await getQuickJS()).createVm();
    const arena = new Arena(vm, { isMarshalable: true });

    function test(obj) {
        return obj;
    }

    arena.expose({ test });
    console.log(arena.evalCode(`let foo = test({}); foo === test(foo)`)); // Modified let foo = test({});

    arena.dispose();
    vm.dispose();
})();

image

Occurs at vm.dispose()

Some handle not disposed? Memory leak?

emilmuller avatar Oct 11 '21 11:10 emilmuller

Thank you for reporting. It seems a bug and should be fixed.

rot1024 avatar Oct 26 '21 04:10 rot1024