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
Name | Type | Description |
---|---|---|
cx | JSContext * | 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 . |
buf | char * 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. |
length | size_t | Number 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论