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

TypeError: #<Promise> could not be cloned. #467

Open
justinmann opened this issue Apr 24, 2024 · 1 comment
Open

TypeError: #<Promise> could not be cloned. #467

justinmann opened this issue Apr 24, 2024 · 1 comment

Comments

@justinmann
Copy link

I am trying to create an async function in unsafe JS that can invoke an async function and return a value.

This code can call the async function "test" from the unsafe script, but when it try to return it produces the error "TypeError: # could not be cloned."

Node.js v18.19.0
isolated-vm v4.7.2

const context = await isolate.createContext();
 await context.global.set(
   'test',
   new ivm.Callback(
     async (a: string) => {
       console.log(a);
       return a;
     },
     { async: true },
   ),
 );

 const script = `async function execute(a) { await test(a) }`;
 const fn = await isolate.compileScript(script);
 await fn.run(context);
 const fnReference = await context.global.get('execute', { reference: true });
 const result = await fnReference.apply(undefined, ['FOO'], {
   result: { promise: true },
 });
 console.log(result);
@siddharthvp
Copy link

It can be done by using a Reference instead of a Callback. See #322 (comment). Also, you appear to be missing a return in the execute function.

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

2 participants