Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Private Member Functions
XPCStringConvert Class Reference

#include <xpcprivate.h>

List of all members.

Static Public Member Functions

static JSStringReadableToJSString (JSContext *cx, const nsAString &readable)
static XPCReadableJSStringWrapperJSStringToReadable (JSString *str)
static void ShutdownDOMStringFinalizer ()

Private Member Functions

 XPCStringConvert ()

Detailed Description

Definition at line 2497 of file xpcprivate.h.


Constructor & Destructor Documentation


Member Function Documentation

Definition at line 135 of file xpcstring.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

JSString * XPCStringConvert::ReadableToJSString ( JSContext cx,
const nsAString &  readable 
) [static]

Definition at line 79 of file xpcstring.cpp.

{
    JSString *str;

    PRUint32 length = readable.Length();

    nsStringBuffer *buf = nsStringBuffer::FromString(readable);
    if (buf)
    {
        // yay, we can share the string's buffer!

        if (sDOMStringFinalizerIndex == -1)
        {
            sDOMStringFinalizerIndex =
                    JS_AddExternalStringFinalizer(DOMStringFinalizer);
            if (sDOMStringFinalizerIndex == -1)
                return NULL;
        }

        str = JS_NewExternalString(cx, 
                                   NS_REINTERPRET_CAST(jschar *, buf->Data()),
                                   length, sDOMStringFinalizerIndex);

        if (str)
            buf->AddRef();
    }
    else
    {
        // blech, have to copy.

        jschar *chars = NS_REINTERPRET_CAST(jschar *,
                                            JS_malloc(cx, (length + 1) *
                                                      sizeof(jschar)));
        if (!chars)
            return NULL;

        if (length && !CopyUnicodeTo(readable, 0,
                                     NS_REINTERPRET_CAST(PRUnichar *, chars),
                                     length))
        {
            JS_free(cx, chars);
            return NULL;
        }

        chars[length] = 0;

        str = JS_NewUCString(cx, chars, length);
        if (!str)
            JS_free(cx, chars);
    }
    return str;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 67 of file xpcstring.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: