Javet looks fantastic! I tried assigning properties to a bound object that contains complex objects, and the result left me a bit confused. I went through almost all the documentation, but I’m still not sure what’s happening or how I should proceed. Could you help clarify this for me?
public static void main(String[] args) throws JavetException {
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime()) {
JavetStandardConsoleInterceptor javetStandardConsoleInterceptor = new JavetStandardConsoleInterceptor(v8Runtime);
javetStandardConsoleInterceptor.register(v8Runtime.getGlobalObject());
User me = new User();
try (V8ValueObject v8ValueObject = v8Runtime.createV8ValueObject()) {
v8Runtime.getGlobalObject().set("me", v8ValueObject);
v8ValueObject.bind(me);
}
Password password = new Password();
try (V8ValueObject v8ValueObject = v8Runtime.createV8ValueObject()) {
v8Runtime.getGlobalObject().set("password", v8ValueObject);
v8ValueObject.bind(password);
}
password.setHashedPassword("${plain}12345");
password.setHashMethod("plain");
//me.setPassword(password);
// Commenting out the line above will print -> "me.password is initially null."
// Uncomment out the line above will set password value in java and print -> "me.password is initially undefined."
v8Runtime.getExecutor("console.log(`me.password is initially ${me.password}.`);").executeVoid();
v8Runtime.getExecutor("console.log(`password is initially ${JSON.stringify(password)}.`);").executeVoid();
// set password in js will throw exception
// Caused by: com.caoccao.javet.exceptions.JavetException:
// Callback signature mismatches:
// expected parameter type is class me.wangheng.javet.Password,
// actual parameter type is class java.util.HashMap
v8Runtime.getExecutor("me.password = password;").executeVoid();
v8Runtime.getExecutor("console.log(`me.password is initially ${me.password}.`);").executeVoid();
}
}
Javet looks fantastic! I tried assigning properties to a bound object that contains complex objects, and the result left me a bit confused. I went through almost all the documentation, but I’m still not sure what’s happening or how I should proceed. Could you help clarify this for me?