Skip to content

JSRuntimeContext class

Manages JavaScript interop context for the lifetime of the .NET Node API host.

C#
public sealed class JSRuntimeContext : IDisposable

Public Members

namedescription
static Current { get; }Gets the current runtime context.
GCHandleCount { get; }Gets the count of GC handles allocated in the current runtime context. Useful for detecting memory leaks related to .NET + JS interop.
ImportFunction { get; set; }Gets or sets the import() function, that supports asynchronously importing ES modules.
IsDisposed { get; }
RequireFunction { get; set; }Gets or sets the require() function, that supports synchronously importing CommonJS modules.
Runtime { get; }
SynchronizationContext { get; }
CreateStruct<T>()Creates a new (empty) JS instance for a struct.
Dispose()
GetOrCreateCollectionWrapper<T>(…)(8 methods)
GetOrCreateCollectionWrapper<TKey,TValue>(…)(2 methods)
GetOrCreateObjectWrapper<T>(…)Gets or creates a JS wrapper for an instance of a class.
Import(…)Imports a module or module property from JavaScript.
ImportAsync(…)Imports a module or module property from JavaScript.
const GlobalObjectNameName of a global object that may hold context specific to Node API .NET.
explicit operator(2 operators)

Remarks

A JSRuntimeContext instance is constructed when the .NET Node API managed host is loaded, and disposed when the host is unloaded. (For AOT there is no "host" component, so each AOT module has a context that matches the module lifetime.) The context tracks several kinds of JS references used internally by this assembly, so that the references can be re-used for the lifetime of the host and disposed when the context is disposed.

See Also

Released under the MIT license