Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickJS-NG: Cannot call method on Object returned by evalCode #214

Open
p-bakker opened this issue Nov 2, 2024 · 1 comment
Open

QuickJS-NG: Cannot call method on Object returned by evalCode #214

p-bakker opened this issue Nov 2, 2024 · 1 comment

Comments

@p-bakker
Copy link

p-bakker commented Nov 2, 2024

When using the QuickJS-NG variant, the return value is always an Object ({})

When using the regular quickjs variant, you get back the actual value returned by .evalCode

import { getQuickJS } from 'quickjs-emscripten';
import { newQuickJSWASMModuleFromVariant } from 'quickjs-emscripten-core';
import qjsNgSync from '@jitl/quickjs-ng-wasmfile-release-sync';
import qjsSync from '@jitl/quickjs-wasmfile-release-sync';

// Passes
describe('Test getQuickJS', () => {
  it('basic execute of function', async () => {
    const QuickJS = await getQuickJS();
    const vm = QuickJS.newContext();

    const result = vm.evalCode(`"Hello!"`);

    if (result.error) {
      console.log("Execution failed:", vm.dump(result.error));
      result.error.dispose();
    } else {
      const retVal = vm.dump(result.value);
      console.log("Success:", retVal);

      expect(retVal).to.be.eqls('Hello!');
      result.value.dispose();
    }

    vm.dispose();
  })
});

// Fails
describe('Test qjsNgSync Variant', () => {
  it('basic execute of function', async () => {
    const QuickJS = await newQuickJSWASMModuleFromVariant(qjsNgSync);
    const vm = QuickJS.newContext();

    const result = vm.evalCode(`"Hello!"`);

    if (result.error) {
      console.log("Execution failed:", vm.dump(result.error));
      result.error.dispose();
    } else {
      const retVal = vm.dump(result.value);
      console.log("Success:", retVal);

      expect(retVal).to.be.eqls('Hello!');
      result.value.dispose();
    }

    vm.dispose();
  })
});

// Passes
describe('Test qjsSync Variant', () => {
  it('basic execute of function', async () => {
    const QuickJS = await newQuickJSWASMModuleFromVariant(qjsSync);
    const vm = QuickJS.newContext();

    const result = vm.evalCode(`"Hello!"`);

    if (result.error) {
      console.log("Execution failed:", vm.dump(result.error));
      result.error.dispose();
    } else {
      const retVal = vm.dump(result.value);
      console.log("Success:", retVal);

      expect(retVal).to.be.eqls('Hello!');
      result.value.dispose();
    }

    vm.dispose();
  })
});
@p-bakker p-bakker changed the title Cannot call method on Object returned by evalCode QuickJS-NG: Cannot call method on Object returned by evalCode Nov 20, 2024
@p-bakker
Copy link
Author

@justjake Any thoughts about this one? Tried to see if I could figure it out, but no dice so far...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant