We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

JS NewStringCopyN

Create a new JS string.


JSString * JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);

JSString * JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
s const char * or const jschar * Pointer to the array of characters containing the text for the JS string to create.
n size_t Number of characters to copy from s into the new string.


JS_NewStringCopyN allocates space for a JavaScript string and its underlying storage, and copies n characters from a C character array, s, into the new JSString. JS_NewUCStringCopyN is the Unicode version of the function. The two functions differ only in the type of the character array s; both functions create ordinary JavaScript strings, and all JavaScript strings are made up of 16-bit characters.

If the array s contains more than n characters, the new string contains a truncated version of the original string. The string may contain null characters ('\0'). They are copied into the new string like any other character.

You can use JS_NewStringCopyN to copy binary data or to copy only a certain portion of a C string into a JavaScript string.

On success, JS_NewStringCopyN and JS_NewUCStringCopyN return a pointer to the new JS string. Otherwise they return NULL.

See Also

MXR ID Search for JS_NewStringCopyN
MXR ID Search for JS_NewUCStringCopyN

JS_GetEmptyStringValue, JS_NewString, JS_NewStringCopyZ, JS_ValueToString

Document Tags and Contributors

Last updated by: Jorend,