static void
DOMStringFinalizer(JSContext *cx, JSString *str)
{
    jschar *chars = const_cast<jschar *>(JS_GetStringCharsZ(cx, str));
    NS_ASSERTION(chars, "How could this OOM if we allocated the memory?");
    nsStringBuffer::FromData(chars)->Release();
}
/* |callee| requires a usage string provided by JS_DefineFunctionsWithHelp. */
void
ReportUsageError(JSContext *cx, JSObject *callee, const char *msg)
{
    const char *usageStr = "usage";
    PropertyName *usageAtom = js_Atomize(cx, usageStr, strlen(usageStr))->asPropertyName();
    DebugOnly<Shape *> shape = callee->nativeLookup(cx, NameToId(usageAtom));
    JS_ASSERT(!shape->configurable());
    JS_ASSERT(!shape->writable());
    JS_ASSERT(shape->hasDefaultGetter());

    jsval usage;
    if (!JS_LookupProperty(cx, callee, "usage", &usage))
        return;

    if (JSVAL_IS_VOID(usage)) {
        JS_ReportError(cx, "%s", msg);
    } else {
        JSString *str = JSVAL_TO_STRING(usage);
        JS::Anchor<JSString *> a_str(str);
        const jschar *chars = JS_GetStringCharsZ(cx, str);
        if (!chars)
            return;
        JS_ReportError(cx, "%s. Usage: %hs", msg, chars);
    }
}
 void set(JSString* str, JSContext* cx) {
     this->cx = cx;
     string = str;
     // Not suppored in SpiderMonkey v19
     //buffer = JS_EncodeString(cx, string);
     
     const jschar *chars = JS_GetStringCharsZ(cx, string);
     size_t l = JS_GetStringLength(string);
     char* pUTF8Str = cc_utf16_to_utf8((const unsigned short*)chars, l, NULL, NULL);
     buffer = pUTF8Str;
 }