JS_NewUCString 编辑

Note: JS_NewString() was removed in SpiderMonkey 1.8.5. Use JS_NewStringCopyN and JS_NewUCStringCopyN instead.

Syntax

JSString *
JS_NewUCString(JSContext *cx, char16_t *chars, size_t length);

JSString *
JS_NewString(JSContext *cx, char *buf, size_t length); // Obsolete since JSAPI 1.8.5
NameTypeDescription
cxJSContext *The context in which to create the new string. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
bufchar * or char16_t *Pointer to a character array, allocated with JS_malloc, containing the characters for the JS string to create. The JavaScript engine adopts the buffer.
lengthsize_tNumber of characters in the text string.

Description

JS_NewString creates and returns a new string, using the memory starting at buf and ending at buf + length as the character storage. JS_NewUCString is the Unicode version of the function.

The character array, buf, must be allocated on the heap using JS_malloc. On success, the JavaScript engine adopts responsibility for memory management of this region. The application must not read, write, or free the buffer. This allows the JavaScript engine to avoid needless data copying.

On success, JS_NewString and JS_NewUCString return a pointer to the new string. On error or exception, they return NULL.

See Also

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

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

发布评论

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

词条统计

浏览:97 次

字数:5701

最后编辑:7年前

编辑次数:0 次

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