зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1492090
- Part 6: Use UTF-8 encoding for additional shell and testing functions. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D151450
This commit is contained in:
Родитель
0265a0f789
Коммит
abb2c5cc4f
|
@ -4191,17 +4191,27 @@ static bool DumpHeap(JSContext* cx, unsigned argc, Value* vp) {
|
|||
return false;
|
||||
}
|
||||
if (!fuzzingSafe) {
|
||||
UniqueChars fileNameBytes = JS_EncodeStringToLatin1(cx, str);
|
||||
UniqueChars fileNameBytes = JS_EncodeStringToUTF8(cx, str);
|
||||
if (!fileNameBytes) {
|
||||
return false;
|
||||
}
|
||||
dumpFile = fopen(fileNameBytes.get(), "w");
|
||||
#ifdef XP_WIN
|
||||
UniqueWideChars wideFileNameBytes =
|
||||
JS::EncodeUtf8ToWide(cx, fileNameBytes.get());
|
||||
if (!wideFileNameBytes) {
|
||||
return false;
|
||||
}
|
||||
dumpFile = _wfopen(wideFileNameBytes.get(), L"w");
|
||||
#else
|
||||
UniqueChars narrowFileNameBytes =
|
||||
JS::EncodeUtf8ToNarrow(cx, fileNameBytes.get());
|
||||
if (!narrowFileNameBytes) {
|
||||
return false;
|
||||
}
|
||||
dumpFile = fopen(narrowFileNameBytes.get(), "w");
|
||||
#endif
|
||||
if (!dumpFile) {
|
||||
fileNameBytes = JS_EncodeStringToLatin1(cx, str);
|
||||
if (!fileNameBytes) {
|
||||
return false;
|
||||
}
|
||||
JS_ReportErrorLatin1(cx, "can't open %s", fileNameBytes.get());
|
||||
JS_ReportErrorUTF8(cx, "can't open %s", fileNameBytes.get());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,16 +184,10 @@ JSObject* Library::Create(JSContext* cx, HandleValue path,
|
|||
PR_GetErrorText(error);
|
||||
}
|
||||
|
||||
if (JS::StringIsASCII(error)) {
|
||||
if (JS::UniqueChars pathCharsUTF8 = JS_EncodeStringToUTF8(cx, pathStr)) {
|
||||
JS_ReportErrorUTF8(cx, "couldn't open library %s: %s",
|
||||
pathCharsUTF8.get(), error);
|
||||
}
|
||||
} else {
|
||||
if (JS::UniqueChars pathCharsLatin1 =
|
||||
JS_EncodeStringToLatin1(cx, pathStr)) {
|
||||
JS_ReportErrorLatin1(cx, "couldn't open library %s: %s",
|
||||
pathCharsLatin1.get(), error);
|
||||
if (JS::UniqueChars errorUtf8 = JS::EncodeNarrowToUtf8(cx, error)) {
|
||||
if (JS::UniqueChars pathChars = JS_EncodeStringToUTF8(cx, pathStr)) {
|
||||
JS_ReportErrorUTF8(cx, "couldn't open library %s: %s", pathChars.get(),
|
||||
errorUtf8.get());
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -1026,17 +1026,35 @@ static bool os_system(JSContext* cx, unsigned argc, Value* vp) {
|
|||
return false;
|
||||
}
|
||||
|
||||
JSString* str = JS::ToString(cx, args[0]);
|
||||
Rooted<JSString*> str(cx, JS::ToString(cx, args[0]));
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UniqueChars command = JS_EncodeStringToLatin1(cx, str);
|
||||
UniqueChars command = JS_EncodeStringToUTF8(cx, str);
|
||||
if (!command) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int result = system(command.get());
|
||||
# ifdef XP_WIN
|
||||
UniqueWideChars wideCommand = JS::EncodeUtf8ToWide(cx, command.get());
|
||||
if (!wideCommand) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Existing streams must be explicitly flushed or closed before calling
|
||||
// the system() function on Windows.
|
||||
_flushall();
|
||||
|
||||
int result = _wsystem(wideCommand.get());
|
||||
# else
|
||||
UniqueChars narrowCommand = JS::EncodeUtf8ToNarrow(cx, command.get());
|
||||
if (!narrowCommand) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int result = system(narrowCommand.get());
|
||||
# endif
|
||||
if (result == -1) {
|
||||
ReportSysError(cx, "system call failed");
|
||||
return false;
|
||||
|
@ -1055,15 +1073,19 @@ static bool os_spawn(JSContext* cx, unsigned argc, Value* vp) {
|
|||
return false;
|
||||
}
|
||||
|
||||
JSString* str = JS::ToString(cx, args[0]);
|
||||
Rooted<JSString*> str(cx, JS::ToString(cx, args[0]));
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UniqueChars command = JS_EncodeStringToLatin1(cx, str);
|
||||
UniqueChars command = JS_EncodeStringToUTF8(cx, str);
|
||||
if (!command) {
|
||||
return false;
|
||||
}
|
||||
UniqueChars narrowCommand = JS::EncodeUtf8ToNarrow(cx, command.get());
|
||||
if (!narrowCommand) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t childPid = fork();
|
||||
if (childPid == -1) {
|
||||
|
@ -1079,7 +1101,7 @@ static bool os_spawn(JSContext* cx, unsigned argc, Value* vp) {
|
|||
// We are in the child
|
||||
|
||||
const char* cmd[] = {"sh", "-c", nullptr, nullptr};
|
||||
cmd[2] = command.get();
|
||||
cmd[2] = narrowCommand.get();
|
||||
|
||||
execvp("sh", (char* const*)cmd);
|
||||
exit(1);
|
||||
|
|
|
@ -10402,7 +10402,11 @@ static bool BindScriptArgs(JSContext* cx, OptionParser* op) {
|
|||
|
||||
for (size_t i = 0; !msr.empty(); msr.popFront(), ++i) {
|
||||
const char* scriptArg = msr.front();
|
||||
JS::RootedString str(cx, JS_NewStringCopyZ(cx, scriptArg));
|
||||
UniqueChars scriptArgUtf8 = JS::EncodeNarrowToUtf8(cx, scriptArg);
|
||||
if (!scriptArgUtf8) {
|
||||
return false;
|
||||
}
|
||||
RootedString str(cx, NewStringCopyUTF8(cx, scriptArgUtf8.get()));
|
||||
if (!str || !JS_DefineElement(cx, scriptArgs, i, str, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -10410,7 +10414,12 @@ static bool BindScriptArgs(JSContext* cx, OptionParser* op) {
|
|||
|
||||
RootedValue scriptPathValue(cx);
|
||||
if (const char* scriptPath = op->getStringArg("script")) {
|
||||
RootedString scriptPathString(cx, JS_NewStringCopyZ(cx, scriptPath));
|
||||
UniqueChars scriptPathUtf8 = JS::EncodeNarrowToUtf8(cx, scriptPath);
|
||||
if (!scriptPathUtf8) {
|
||||
return false;
|
||||
}
|
||||
RootedString scriptPathString(cx,
|
||||
NewStringCopyUTF8(cx, scriptPathUtf8.get()));
|
||||
if (!scriptPathString) {
|
||||
return false;
|
||||
}
|
||||
|
@ -10523,7 +10532,10 @@ auto minVal(T a, Ts... args) {
|
|||
}
|
||||
|
||||
if (ccArgno == minArgno) {
|
||||
const char* code = codeChunks.front();
|
||||
UniqueChars code = JS::EncodeNarrowToUtf8(cx, codeChunks.front());
|
||||
if (!code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Command line scripts are always parsed with full-parse to evaluate
|
||||
// conditions which might filter code coverage conditions.
|
||||
|
@ -10531,7 +10543,8 @@ auto minVal(T a, Ts... args) {
|
|||
opts.setFileAndLine("-e", 1).setForceFullParse();
|
||||
|
||||
JS::SourceText<Utf8Unit> srcBuf;
|
||||
if (!srcBuf.init(cx, code, strlen(code), JS::SourceOwnership::Borrowed)) {
|
||||
if (!srcBuf.init(cx, code.get(), strlen(code.get()),
|
||||
JS::SourceOwnership::Borrowed)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче