You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The object passed in to the js UDF is a com.google.gson.JsonArray, which is a mostly-opaque type to javascript. Calling JSON.stringify on it returns the "own properties" of the argument, which is empty, hence the empty object as the output.
Currently, the only exposed interface for com.google.gson.* is string conversion, with complex types then requiring deserialization.
function test(arrayOfObject){
let myArray = JSON.parse(new String(arrayOfObject))
MapTool.chat.broadcast(JSON.stringify(myArray));
return myArray;
}
MTScript.registerMacro("test",test);
Until a week or so ago, I was under the impression that MapTool kept json data internally as strings, so I did not handle gson data coming in to js UDFs. I will see if I can adjust the GraalVM-js security policy to allow full access to gson data. Or failing that, handle converting gson data to graalvm-js data automatically.
I think converting between gson and graalvm-js is best way to go, I would hate to get into the position where a upgrade to gson (or change to some other library) would break people's macros.
Describe the Bug
if you have a js UDF which takes a json it will receive a empty object instead of whatever argument you give it
To Reproduce
[r:js.evalURI("test","lib://test/macro/test")]
commandExpected Behaviour
arguments that the js UDF receives should be the ones i use, and not always an empty object
Screenshots
No response
MapTool Info
1.11.0
Desktop
arch linux
Additional Context
No response
The text was updated successfully, but these errors were encountered: