Fix Java object conversion in ScriptEngine bindings - #2490
Conversation
|
Agreed -- I guess this can't be used all that much... The first one is clear -- get should do the conversion in the other direction. However, put is triggered when the JavaScript code sets a global that came from the context. But by calling jsToJava with Object.class as the target type, we end up with a converted Java object, which we might not always want. For example, imagine if we wanted to return the original JavaScript object, such as Undefined? This code would actually convert it to something else. I find the Java specs to be unhelpful on this, but do we want a conversion, or perhaps we want a different conversion? |
|
You’re right: I changed The updated head is |
|
This looks good now and it's a great catch. Thanks! |
After
engine.put("file", file)andengine.eval("var copy = file"),engine.get("copy")returns aNativeJavaObjectrather than the original Java object.BindingsObjectconverts values in the wrong direction when reading them.Convert Java values to JavaScript on reads. On writes, unwrap only
Wrappervalues so Java objects retain their identity while native JavaScript values, includingundefined, remain unchanged. Converting every write withjsToJava(Object.class)would turnundefinedinto a string.Regression tests cover Java object identity, global bindings, and native JavaScript values through direct/compiled evaluation in both execution modes. All 43 engine tests pass locally; the four new native-value cases fail on the preceding PR revision. Formatting and test compilation pass. Full Linux CI passes on revised head
39d05f2: Java 21, Java 25, debug, multithreaded, and Test262 jobs.The reversed conversions were also noted in #798; its separate const-scope issue remains outside this change. Please squash the commits when merging.