Bug 1823208 - Use lossy conversion in getBacktrace testing function. r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D173262
This commit is contained in:
Tooru Fujisawa 2023-03-28 07:41:58 +00:00
parent 19819b17d0
commit 01d4f3c0ba
2 changed files with 19 additions and 2 deletions

View File

@ -5683,8 +5683,15 @@ static bool GetBacktrace(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
JS::ConstUTF8CharsZ utf8chars(buf.get(), strlen(buf.get()));
JSString* str = NewStringCopyUTF8Z(cx, utf8chars);
size_t len;
UniqueTwoByteChars ucbuf(JS::LossyUTF8CharsToNewTwoByteCharsZ(
cx, JS::UTF8Chars(buf.get(), strlen(buf.get())),
&len, js::MallocArena)
.get());
if (!ucbuf) {
return false;
}
JSString* str = JS_NewUCStringCopyN(cx, ucbuf.get(), len);
if (!str) {
return false;
}

View File

@ -0,0 +1,10 @@
// Some filename handling code still uses latin1, and some characters are
// replaced with REPLACEMENT CHARACTER (U+FFFD).
//
// FIXME: bug 1492090
const backtrace = evaluate(`
this.getBacktrace(this);
`, { fileName: "\u86D9" });
assertEq(backtrace.includes(`["\uFFFD":2:5]`), true);