-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
issue converting proxied v8 java array to java object #351
Comments
This is the expected behavior: Native JS array is always converted to |
@caoccao the object classes are of third party libs, so there is no way I can change from Array to List, isn't there any workaround? |
I think you may inject a JS function as follows.
|
That might be possible, and indirect. I'll investigate that later. Please stay in tune. |
Thank you, I guess this should be handled by JavetProxyPluginArray. |
Please check commit 1 and commit 2 out. By calling v8Runtime.getConverter().getConfig().setSealedEnabled(true);
assertArrayEquals(
new Object[]{1, 2},
v8Runtime.getExecutor("Object.seal([1,2])").executeObject());
assertArrayEquals(
new Object[]{"a", "b"},
v8Runtime.getExecutor("Object.seal(['a','b'])").executeObject());
assertArrayEquals(
new Object[]{},
v8Runtime.getExecutor("Object.seal([])").executeObject()); |
I tested out this feature, however I see the the java array field is not set.
output is However if I change appleColors type to Object[] its works. |
That is unfortunate. It's hard to cast
In this case, I suggest you implement your own proxy plugin. Please let me know if you have any questions. |
Proxied Java V8 object is manipulated in javascript to set array field but it doesn't set. However List works.
`
public class Apple {
private String[] appleColors;
}
//kotlin test
@test
fun testSamp() {
try {
val javetV8Engine = javetEngineV8Pool.getEngine()
val javetV8Runtime = javetV8Engine.v8Runtime
val javetBridgeConverter = JavetBridgeConverter()
javetBridgeConverter.config.setReflectionObjectFactory(JavetReflectionObjectFactory.instance);
javetV8Runtime.setConverter(javetBridgeConverter)
val apple = Apple()
javetV8Runtime.globalObject.set("apple", apple);
javetV8Runtime.getExecutor("""
apple.appleColors = ['a']
""".trimIndent()).executeVoid();
println(apple.appleColors)
javetV8Runtime.lowMemoryNotification()
} catch (javetException: JavetException) {
println(javetException)
}
}
Above test outputs
null
if the appleColors is changed to List<String> the output is
[a]
`
The text was updated successfully, but these errors were encountered: