-
Notifications
You must be signed in to change notification settings - Fork 50
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
vm里的对象实例, 外部call async method的的时候this指向不对 #55
Labels
bug
Something isn't working
Comments
lljxx1
changed the title
vm里的对象实例, 外部call metho的的时候this指向不对
vm里的对象实例, 外部call method的的时候this指向不对
Mar 13, 2020
更正一下,是async function会这样 |
const Sval = require('sval');
const options = {
// ECMA Version of the code (5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019)
ecmaVer: 2019,
// Whether the code runs in a sandbox
sandBox: true
};
const interpreter = new Sval(options);
const sanbox = {
console: console,
};
const code = `class A {
constructor(a) {
this.a = a;
}
print() {
return new Promise((resolve, rject) => {
resolve(this.a)
})
}
async printB() {
return this.a
}
}
exports.A = A`
interpreter.run(code);
const instance = new interpreter.exports.A('test');
console.log('instance', instance);
(async () => {
try {
console.log('print', await instance.print())
console.log('printB', await instance.printB())
} catch (e) {
console.log(e)
}
})(); |
看来qucik fix只能wrap个 new Promise,还好有热更新 |
lljxx1
changed the title
vm里的对象实例, 外部call method的的时候this指向不对
vm里的对象实例, 外部call async method的的时候this指向不对
Mar 13, 2020
@lljxx1 0.4.7已fix |
收到 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: