/** * Return an XPCLocaleCallbacks out of |cx|. Callers must know that * |cx| has an XPCLocaleCallbacks; i.e., the checks in MaybeThis() * would be pointless to run from the calling context. * * NB: If the returned XPCLocaleCallbacks hasn't yet been bound to a * thread, then a side effect of calling This() is to bind it to the * calling thread. */ static XPCLocaleCallbacks* This(JSContext* cx) { XPCLocaleCallbacks* ths = static_cast<XPCLocaleCallbacks*>(JS_GetLocaleCallbacks(cx)); ths->AssertThreadSafety(); return ths; }
/** * Return the XPCLocaleCallbacks that's hidden away in |cx|, or null * if there isn't one. (This impl uses the locale callbacks struct * to store away its per-context data.) * * NB: If the returned XPCLocaleCallbacks hasn't yet been bound to a * thread, then a side effect of calling MaybeThis() is to bind it * to the calling thread. */ static XPCLocaleCallbacks* MaybeThis(JSContext* cx) { JSLocaleCallbacks* lc = JS_GetLocaleCallbacks(cx); return (lc && lc->localeToUpperCase == LocaleToUpperCase && lc->localeToLowerCase == LocaleToLowerCase && lc->localeCompare == LocaleCompare && lc->localeToUnicode == LocaleToUnicode) ? This(cx) : nsnull; }
/** * Return the XPCLocaleCallbacks that's hidden away in |rt|. (This impl uses * the locale callbacks struct to store away its per-runtime data.) */ static XPCLocaleCallbacks* This(JSRuntime *rt) { // Locale information for |rt| was associated using xpc_LocalizeRuntime; // assert and double-check this. JSLocaleCallbacks* lc = JS_GetLocaleCallbacks(rt); MOZ_ASSERT(lc); MOZ_ASSERT(lc->localeToUpperCase == LocaleToUpperCase); MOZ_ASSERT(lc->localeToLowerCase == LocaleToLowerCase); MOZ_ASSERT(lc->localeCompare == LocaleCompare); MOZ_ASSERT(lc->localeToUnicode == LocaleToUnicode); XPCLocaleCallbacks* ths = static_cast<XPCLocaleCallbacks*>(lc); ths->AssertThreadSafety(); return ths; }