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

Uncaught TypeError: Bot.log is not a function #37

Open
Jobians opened this issue Feb 19, 2024 · 4 comments
Open

Uncaught TypeError: Bot.log is not a function #37

Jobians opened this issue Feb 19, 2024 · 4 comments

Comments

@Jobians
Copy link

Jobians commented Feb 19, 2024

const { Sandbox } = require('v8-sandbox');
const path = require('path');

const socketPath = path.join(__dirname, '');

class Bot {
  log(message) {
    console.log(message);
  }
}

const ContextObjects = {
    Bot: new Bot(),
    version: "1.0.0"
};

async function runSandboxedCode() {
  const sandbox = new Sandbox({ socketPath });
  const code = `
  Bot.log("Hi");
  console.log(version);
  `;

  try {
    const { error, value } = await sandbox.execute({ code, timeout: 3000, globals: ContextObjects });
    await sandbox.shutdown();
    
    if (error) {
      console.log(error);
    }
    console.log(value);
  } catch (e) {
    console.log(e);
  }
}

runSandboxedCode();
@zhm
Copy link
Member

zhm commented Feb 19, 2024

@Jobians
Copy link
Author

Jobians commented Feb 20, 2024

Check out the docs on host functions:

https://github.com/fulcrumapp/v8-sandbox/tree/main?tab=readme-ov-file#host-functions

Please can you give me example to expose class

@photoongit
Copy link

You can't expose functions to the host because all that is passed is JSON, what you can try is defining such a complex name to your normal host functions and creating a class inside template calling them

@Jobians
Copy link
Author

Jobians commented Nov 20, 2024

No solution?

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

3 participants