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

执行assert 断言出错 assert.equal is not a function #47

Open
tiyunchen opened this issue Jan 14, 2022 · 1 comment
Open

执行assert 断言出错 assert.equal is not a function #47

tiyunchen opened this issue Jan 14, 2022 · 1 comment

Comments

@tiyunchen
Copy link

tiyunchen commented Jan 14, 2022

const assert = require('assert')

const {default: Safeify} = require("safeify");
async function sandboxFn(context, script) {
    // 创建 safeify 实例
    const safeVm = new Safeify({
        timeout: 3000,
        asyncTimeout: 60000
    })

    // 执行动态代码
    const result = await safeVm.run(script, context)

    // 释放资源
    safeVm.destroy()
    return result
}

const context = {
    a: 1,
    b: 2,
    c:1,
    add(a, b) {
        return a + b;
    },
    assert: assert
};
sandboxFn(context,`return  assert.equal(a, c)`).then(res=>{
    console.log('result',res);
}).catch(err=>{
    console.log(err)
})



image

node version: 14.17

safeify version: 5.0.5

@tiyunchen
Copy link
Author

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