Bug 1878465 - Change Android event error string from char8_t to char to fix C++20 build error. r=geckoview-reviewers,m_kato

When compiled with -std=c++17, `u8""` string literals have type `const char[]`. When compiled with -std=c++20, `u8""` strings have type `const char8_t[]`. `JS_ReportErrorUTF8()` has no override for `char8_t` strings, so `u8"Invalid event data property %s"` at https://searchfox.org/mozilla-central/rev/5eedf36dc46f1683af7478c7adaf308ceb42911b/widget/android/EventDispatcher.cpp#132 fails to compile. In this case, there's no reason for `"Invalid event data property %s"` to be a `u8` string because it contains no non-ASCII characters that would be encoded incorrectly. Plus, clang's default character encoding for .cpp files is UTF-8, so `u8` is redundant here.

widget/android/EventDispatcher.cpp:125:7: error: no matching function for call to 'JS_ReportErrorUTF8'
  125 |       JS_ReportErrorUTF8(
      |       ^~~~~~~~~~~~~~~~~~
obj-aarch64-unknown-linux-android/dist/include/js/ErrorReport.h:465:27: note: candidate function not viable: no known conversion from 'const char8_t[31]' to 'const char *' for 2nd argument
  465 | extern JS_PUBLIC_API void JS_ReportErrorUTF8(JSContext* cx, const char* format,
      |                           ^                                 ~~~~~~~~~~~~~~~~~~

Differential Revision: https://phabricator.services.mozilla.com/D200553
This commit is contained in:
Chris Peterson 2024-02-22 17:40:21 +00:00
parent 1e6f17a7b6
commit 0958fa945a

View file

@ -129,9 +129,9 @@ nsresult UnboxBundle(JSContext* aCx, const jni::Object::LocalRef& aData,
nsresult rv = UnboxValue(aCx, values->GetElement(i), &value); nsresult rv = UnboxValue(aCx, values->GetElement(i), &value);
if (rv == NS_ERROR_INVALID_ARG && !JS_IsExceptionPending(aCx)) { if (rv == NS_ERROR_INVALID_ARG && !JS_IsExceptionPending(aCx)) {
JS_ReportErrorUTF8( JS_ReportErrorUTF8(
aCx, u8"Invalid event data property %s", aCx, "Invalid event data property %s",
NS_ConvertUTF16toUTF8( NS_ConvertUTF16toUTF8(reinterpret_cast<const char16_t*>(keyChars),
nsString(reinterpret_cast<const char16_t*>(keyChars), keyLen)) keyLen)
.get()); .get());
} }
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);