Bug 1311319 - Part 2: Use Latin1 variant of error reporting if OS error is not ASCII. r=jwalden
authorTooru Fujisawa <arai_a@mac.com>
Sun, 23 Oct 2016 01:46:34 +0900
changeset 319040 5cd94a51349c104067c7dbd7b7f76d90c95fda0b
parent 319039 1be47494e723521e96f5541d985c63a77dd225ef
child 319041 4c77ff67311dd0cf52bc211ce0cb1d118000f3d4
push id30858
push userryanvm@gmail.com
push dateSun, 23 Oct 2016 17:17:41 +0000
treeherdermozilla-central@a9a41b69f3f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1311319
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1311319 - Part 2: Use Latin1 variant of error reporting if OS error is not ASCII. r=jwalden
js/src/ctypes/Library.cpp
--- a/js/src/ctypes/Library.cpp
+++ b/js/src/ctypes/Library.cpp
@@ -157,19 +157,25 @@ Library::Create(JSContext* cx, HandleVal
   if (!library) {
 #define MAX_ERROR_LEN 1024
     char error[MAX_ERROR_LEN] = "Cannot get error from NSPR.";
     uint32_t errorLen = PR_GetErrorTextLength();
     if (errorLen && errorLen < MAX_ERROR_LEN)
       PR_GetErrorText(error);
 #undef MAX_ERROR_LEN
 
-    JSAutoByteString pathCharsUTF8;
-    if (pathCharsUTF8.encodeUtf8(cx, pathStr))
-      JS_ReportErrorUTF8(cx, "couldn't open library %s: %s", pathCharsUTF8.ptr(), error);
+    if (JS::StringIsASCII(error)) {
+      JSAutoByteString pathCharsUTF8;
+      if (pathCharsUTF8.encodeUtf8(cx, pathStr))
+        JS_ReportErrorUTF8(cx, "couldn't open library %s: %s", pathCharsUTF8.ptr(), error);
+    } else {
+      JSAutoByteString pathCharsLatin1;
+      if (pathCharsLatin1.encodeLatin1(cx, pathStr))
+        JS_ReportErrorLatin1(cx, "couldn't open library %s: %s", pathCharsLatin1.ptr(), error);
+    }
     return nullptr;
   }
 
   // stash the library
   JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(library));
 
   return libraryObj;
 }