Creates a new JSString whose characters are stored in external memory, i.e., memory allocated by the application, not the JavaScript engine. Since the program allocated the memory, it will need to free it; this happens in an external string finalizer indicated by the type parameter.
JSString * JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type);
| 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.)
|
chars |
jschar * |
Pointer to an array of jschars. This array is used as the character buffer of the JSString to be created. The array must be populated with the desired character data before JS_NewExternalString is called, and the array must remain in memory, with its contents unchanged, for as long as the JavaScript engine needs to hold on to it. (Ultimately, the string will be garbage collected, and the JavaScript engine will call the string finalizer callback, allowing the application to free the array.)
The array does not need to be zero-terminated. |
length |
size_t |
The number of characters in the array chars. |
type |
intN |
Indicates which string finalizer callback the JavaScript engine should use (later) to free the string buffer chars. This must be an id number previously returned by a successful call to JS_AddExternalStringFinalizer. |
Page last modified 20:11, 21 Aug 2008 by Jorend