Exchanging values
editThe pages of this group cover what crosses the boundary between .NET and JavaScript. Nothing is converted automatically: the engine uses no reflection, so a .NET object becomes visible to the scripts only through the objects and functions you create for it. Helpers convert the common types, such as collections and JSON: see Converting .NET values.
A few rules hold for all of them:
- Every JavaScript value is a JsValue:
undefined,null, a boolean, a number, a string, a symbol, a BigInt or an object. The numbers, the strings and the booleans of .NET convert to it implicitly. - The objects are JsObject instances, created by the factories of the realm (CreateObject, CreateArray, CreateFunction...) or by the scripts.
- Reading and writing properties happens inside
engine.Enter(), or inside a .NET function called by a script. See The scope of an engine. - An object belongs to its realm, and its realm to its engine.
Pages of this group
- Values: read the kind of a value, convert it, create values, and exchange dates.
- Objects and arrays: create objects and arrays, read the objects of a script, define read-only and lazy properties, exchange data as JSON.
- Functions: expose .NET functions, read their arguments, call JavaScript functions and constructors from .NET.
- Exposing .NET objects: expose a .NET class with a constructor and a prototype, or implement an object whose properties come from .NET.
- Binary data: share a .NET buffer with the scripts, read their typed arrays, share memory between engines.
- Console, timers and other host APIs: give the scripts
console,setTimeout,queueMicrotaskand the other globals of the browsers and of Node.js. - Converting .NET values: convert .NET values, collections and JSON, and expose typed delegates.