In the JSAPI,
JSRuntime, even if it has many threads. The
JSContext is a child of the
JSRuntime. A context can run scripts. It contains the global object and the execution stack. Exception handling, error reporting, and some language options are per-
JSContext. Once created, a context can be used any number of times for different scripts or JSAPI queries. For example, a browser might create a separate context for each HTML page; every script in the page could use the same context.
Objects may be shared among
JSContexts within a
JSRuntime. There's no fixed association between an object and the context in which it is created.
Sample code to set up and tear down a
JSRuntime and a
JSContext is at JSAPI User Guide.
Only one thread may use a
JSRuntime. Earlier versions allowed using
JS_ClearContextThread and other functions to move a
JSContext from one thread to another. This feature has since been removed.