JSRuntime 编辑

In the JSAPI, JSRuntime is the top-level object that represents an instance of the JavaScript engine. A program typically has only one JSRuntime, even if it has many threads. The JSRuntime is the universe in which JavaScript objects live; they can't travel to other JSRuntimes.

All JavaScript code and most JSAPI calls run within a JSContext. 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.

Threads

Only one thread may use a JSContext or 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.

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:94 次

字数:3509

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文