Question about marshalling of certain types #239
-
Hello! I am thinking of using ClearScript in one of my projects, and I have a few questions about how certain types are marshalled to and from Javascript. I couldn't find the answers in the tutorial or FAQ, so I apologize if they had already been answered elsewhere.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @phosphene47, Thanks for your question! ClearScript generally prefers not to convert between host and script data types, especially if the conversion is lossy, unless the lack of this conversion makes using ClearScript exceptionally painful. To that end, it provides automatic conversion of fundamental data types only – numbers, strings, Booleans, etc. – and optional automatic conversion of nontrivial but commonly used data types such as date-times and tasks/promises. Everything else is marshaled by proxy; that is, the recipient gets a local object that represents something on the other side of the host-script boundary. The proxy holds a strong reference and provides access to its remote target. For proxy marshaling to work, the target must be capable of durable reference. For .NET that means it must be on the managed heap – either a reference object or a boxed value. That rules out pointers and ref structs. Everything else you asked about – simple arrays, multidimensional arrays, conventional structs, and enums – are all marshaled by proxy without conversion. Enums and some other immutable values are also canonicalized, meaning that script code receives a consistent reference for each distinct value, enabling meaningful by-reference comparison. Good luck! |
Beta Was this translation helpful? Give feedback.
Hello @phosphene47,
Thanks for your question!
ClearScript generally prefers not to convert between host and script data types, especially if the conversion is lossy, unless the lack of this conversion makes using ClearScript exceptionally painful.
To that end, it provides automatic conversion of fundamental data types only – numbers, strings, Booleans, etc. – and optional automatic conversion of nontrivial but commonly used data types such as date-times and tasks/promises. Everything else is marshaled by proxy; that is, the recipient gets a local object that represents something on the other side of the host-script boundary. The proxy holds a strong reference and provides access to its re…