mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 19:06:35 +00:00
SpiderMonkey 38 upgrade: 32/35
JS_GetStringCharsAndLength was removed, use
JS_Get{Latin1,TwoByte}StringCharsAndLength instead.
Actually handle strings in both the Latin1 and TwoByte cases since we
need to.
This saves some space when serializing and also when running as they are
stored that way in the vm.
Also handle the error case.
Patch by leper.
For more information:
https://blog.mozilla.org/javascript/2014/07/21/slimmer-and-faster-javascript-strings-in-firefox/
Addresses https://bugzilla.mozilla.org/show_bug.cgi?id=1037869
This was SVN commit r18686.
This commit is contained in:
@@ -171,11 +171,27 @@ template<> bool ScriptInterface::FromJSVal<std::wstring>(JSContext* cx, JS::Hand
|
||||
JS::RootedString str(cx, JS::ToString(cx, v));
|
||||
if (!str)
|
||||
FAIL("Argument must be convertible to a string");
|
||||
size_t length;
|
||||
const char16_t* ch = JS_GetStringCharsAndLength(cx, str, &length);
|
||||
if (!ch)
|
||||
FAIL("JS_GetStringsCharsAndLength failed"); // out of memory
|
||||
out.assign(ch, ch + length);
|
||||
|
||||
if (JS_StringHasLatin1Chars(str))
|
||||
{
|
||||
size_t length;
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
const JS::Latin1Char* ch = JS_GetLatin1StringCharsAndLength(cx, nogc, str, &length);
|
||||
if (!ch)
|
||||
FAIL("JS_GetLatin1StringCharsAndLength failed");
|
||||
|
||||
out.assign(ch, ch + length);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t length;
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
const char16_t* ch = JS_GetTwoByteStringCharsAndLength(cx, nogc, str, &length);
|
||||
if (!ch)
|
||||
FAIL("JS_GetTwoByteStringsCharsAndLength failed"); // out of memory
|
||||
|
||||
out.assign(ch, ch + length);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user