JS_DumpNamedRoots 编辑

Obsolete since JSAPI 19
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Enumerate all the named roots in a runtime.

Syntax

void
JS_DumpNamedRoots(JSRuntime *rt,
    void (*dump)(const char *name, void *rp, void *data),
    void *data);
NameTypeDescription
rtJSRuntime *Pointer to a JSRuntime from which to dump named roots.
dumpvoid (*)(const char *, void *, void *)Pointer to function that actually dumps the named roots. This may not be NULL.
datavoid *A pointer that is passed to dump each time it is called. The JavaScript engine does not read from or write to this pointer at all. It is passed to the dump function unchanged. It may be NULL.

Description

Each call to JS_AddNamedRoot creates a record in a table of named roots maintained by the garbage collector. JS_DumpNamedRoots provides a way for the application to access the contents of that table. It calls the dump function once for each named root in the given runtime rt. In pseudocode:

/* pseudocode explanation of what JS_DumpNamedRoots does */
void JS_DumpNamedRoots(JSRuntime *rt, DumpFn dump, void *data)
{
    for each (root in rt->namedRoots)
        dump(root.name, root.address, data);
}

Callback syntax

dump is a pointer to a function provided by the application. When JS_DumpNamedRoots calls it, it passes three arguments:

ArgumentTypeDescription
nameconst char *The name of the named root.
rpvoid *A pointer to the rooted variable, array element, or field. This is the pointer that the application passed to JS_AddNamedRoot. It points to a variable, array element, or field of type jsval, JSObject *, JSString *, or jsdouble *.
datavoid *The data argument that the application passed to JS_DumpNamedRoots.

Example

static void dumpRoot(const char *name, void *addr, void *data)
{
    /* The application may use `data` for anything.  In this
       example, we use it to pass the desired output file. */
    FILE *f = (FILE *) data;

    fprintf(f, "There is a root named '%s' at %p\n", name, addr);
}

int main()
{
    ...
    JS_DumpNamedRoots(rt, dumpRoot, stderr);
    ...
}

See Also

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

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

发布评论

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

词条统计

浏览:37 次

字数:4395

最后编辑:7年前

编辑次数:0 次

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