Bug 966911 Part 4: Recreate the underlying nsAString when an an external string is passed back to C++ r=bholley

This commit is contained in:
Neil Rashbrook 2014-02-14 19:44:55 +00:00
parent d2cea95d46
commit 581a903d05
3 changed files with 24 additions and 1 deletions

View File

@ -516,6 +516,14 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
if (!str) {
ws->AssignLiteral(MOZ_UTF16("undefined"));
} else if (XPCStringConvert::IsDOMString(str)) {
// The characters represent an existing nsStringBuffer that
// was shared by XPCStringConvert::ReadableToJSVal.
nsStringBuffer::FromData((void *)chars)->ToString(length, *ws);
} else if (XPCStringConvert::IsLiteral(str)) {
// The characters represent a literal char16_t string constant
// compiled into libxul, such as the string "undefined" above.
ws->AssignLiteral(chars, length);
} else if (useAllocator && STRING_TO_JSVAL(str) == s) {
// The JS string will exist over the function call.
// We don't need to copy the characters in this case.

View File

@ -234,6 +234,18 @@ public:
static void FreeZoneCache(JS::Zone *zone);
static void ClearZoneCache(JS::Zone *zone);
static MOZ_ALWAYS_INLINE bool IsLiteral(JSString *str)
{
return JS_IsExternalString(str) &&
JS_GetExternalStringFinalizer(str) == &sLiteralFinalizer;
}
static MOZ_ALWAYS_INLINE bool IsDOMString(JSString *str)
{
return JS_IsExternalString(str) &&
JS_GetExternalStringFinalizer(str) == &sDOMStringFinalizer;
}
private:
static const JSStringFinalizer sLiteralFinalizer, sDOMStringFinalizer;

View File

@ -834,13 +834,16 @@ class nsTSubstring_CharT
mFlags = dataFlags | (mFlags & 0xFFFF0000);
}
void NS_FASTCALL AssignLiteral( const char_type* data, size_type length );
void NS_FASTCALL ReplaceLiteral( index_type cutStart, size_type cutLength, const char_type* data, size_type length );
static int AppendFunc( void* arg, const char* s, uint32_t len);
public:
// NOTE: this method is declared public _only_ for convenience for
// callers who don't have access to the original nsLiteralString_CharT.
void NS_FASTCALL AssignLiteral( const char_type* data, size_type length );
// mFlags is a bitwise combination of the following flags. the meaning
// and interpretation of these flags is an implementation detail.
//