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 · 4 comments
Open

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

p-bakker opened this issue Nov 2, 2024 · 4 comments

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...

@p-bakker
Copy link
Author

p-bakker commented Jan 3, 2025

@justjake Any idea? Is quite annoying having to make all .evalCode(...) calls to assign their result to some globalThis property and then making an additional call to get the value of that global variable

@p-bakker
Copy link
Author

p-bakker commented Jan 3, 2025

running yarn test yields a ton of failed tests for quickjs-ng RELEASE_SYNC and sometimes quickjs-ng DEBUG_SYNC as well

@p-bakker
Copy link
Author

p-bakker commented Jan 3, 2025

Seem that its an issue with determining the type? If I modify my call to .evalCode to explicitly send in {type: 'global'} as the 3rd param, then all of a sudden it starts to work properly...

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