JSRuntime class
Abstract base class for a JavaScript runtime.
public abstract class JSRuntime
Public Members
Protected Members
name | description |
---|---|
JSRuntime() | The default constructor. |
Remarks
This is a mid-level API; it is lower level than JSValue and related types and methods, while it is higher level than the napi_* native functions. This middle layer serves two purposes: 1. It is used to implement all of the higher level APIs in the library, while encapsulating tedious concerns of dynamic function binding, memory pinning, string encoding, etc. 2. It allows swapping out the runtime implementation, either for testing with mocks or for using a JS runtime other than Node.js. (Other runtimes must implement the Node API.) Guidelines for this API: - Use .NET style method names, not napi_* function naming - Prefer strings, Span, and nint over pointers - Prefer ref and out over pointers, when practical - Use napi_value instead of JSValue, JSObject, JSArray, etc. - Do not throw exceptions; return status codes instead - Avoid overloads that are purely for convenience - GC handles should be managed at a higher layer; implementations of these APIs should not allocate or dereference GC handles The base methods all have default implementations that throw NotSupportedException. This makes it easier to create runtime classes (or test mocks) that implement only part of the API surface.