зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1025875 part 7 - Make Sprinter::putString work with Latin1 strings. r=njn
This commit is contained in:
Родитель
47d88e43bd
Коммит
9b77aa3e2d
|
@ -0,0 +1,22 @@
|
|||
var s = toLatin1("someName");
|
||||
|
||||
// Latin1
|
||||
function f(someName) {
|
||||
someName();
|
||||
}
|
||||
try {
|
||||
f(3);
|
||||
} catch(e) {
|
||||
assertEq(e.message.contains("someName"), true);
|
||||
}
|
||||
|
||||
// TwoByte
|
||||
function g(someName\u1200) {
|
||||
someName\u1200();
|
||||
}
|
||||
try {
|
||||
g(3);
|
||||
} catch(e) {
|
||||
// Note: string is deflated; don't check for the \u1200.
|
||||
assertEq(e.message.contains("someName"), true);
|
||||
}
|
|
@ -1198,21 +1198,24 @@ Sprinter::putString(JSString *s)
|
|||
InvariantChecker ic(this);
|
||||
|
||||
size_t length = s->length();
|
||||
const jschar *chars = s->getChars(context);
|
||||
if (!chars)
|
||||
return -1;
|
||||
|
||||
size_t size = length;
|
||||
if (size == (size_t) -1)
|
||||
return -1;
|
||||
|
||||
ptrdiff_t oldOffset = offset;
|
||||
char *buffer = reserve(size);
|
||||
if (!buffer)
|
||||
return -1;
|
||||
DeflateStringToBuffer(nullptr, chars, length, buffer, &size);
|
||||
buffer[size] = 0;
|
||||
|
||||
JSLinearString *linear = s->ensureLinear(context);
|
||||
if (!linear)
|
||||
return -1;
|
||||
|
||||
AutoCheckCannotGC nogc;
|
||||
if (linear->hasLatin1Chars())
|
||||
mozilla::PodCopy(reinterpret_cast<Latin1Char*>(buffer), linear->latin1Chars(nogc), length);
|
||||
else
|
||||
DeflateStringToBuffer(nullptr, linear->twoByteChars(nogc), length, buffer, &size);
|
||||
|
||||
buffer[size] = 0;
|
||||
return oldOffset;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче