autojs的v8引擎插件
这个插件基于Javet项目,Javet提供了v8引擎与java交互的能力
let v8plugin = $plugins.load("com.aiselp.autojs.v8plugin");
let v8 = v8plugin.createV8Engine();
events.on('exit', () => {
v8.destroy()
})
//注入一个java对象给v8引擎使用
v8.inject('console', runtime.console);
let t = {
f: 6
}
v8.inject('val', t)
v8.execJsString(`
val.c = 0;
console.log(val);
`)
sleep(1000);
//性能测试
let jscode = `
var a = 0;
console.log("测试开始")
console.log("当前引擎:"+
(typeof id=='function'?'Rhino':'V8'))
var time = Date.now();
while (a < 5000 * 1000) {
a++
}
console.log("测试结束,耗时:"+(Date.now()-time)+"ms");
`
v8.execJsString(jscode)
//sleep(1000)
eval(jscode)