Bug 1025875 part 7 - Make Sprinter::putString work with Latin1 strings. r=njn

This commit is contained in:
Jan de Mooij 2014-06-17 15:18:21 +02:00
parent c4cc1b7253
commit 97e23847a2
2 changed files with 33 additions and 8 deletions

View File

@ -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);
}

View File

@ -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;
}