Bug 1415549: Use correct encoding when reporting an error with wasm module/field utf8 names; r?luke draft
authorBenjamin Bouvier <benj@benj.me>
Thu, 09 Nov 2017 14:57:50 +0100
changeset 697179 22aa8951c37e06c50774368cd2f4e9676ed747aa
parent 697178 0d54bbebadb2879bf73f492e9bf216a458e22878
child 740041 d8f8ddd94f3bbdfbef7b0b1375ac58d1903a34ad
push id88917
push userbbouvier@mozilla.com
push dateMon, 13 Nov 2017 14:36:35 +0000
reviewersluke
bugs1415549
milestone59.0a1
Bug 1415549: Use correct encoding when reporting an error with wasm module/field utf8 names; r?luke MozReview-Commit-ID: 8PcgvVfLa2V
js/src/jit-test/tests/wasm/utf8.js
js/src/jsapi.cpp
js/src/wasm/AsmJS.cpp
js/src/wasm/WasmBinaryToAST.cpp
js/src/wasm/WasmBuiltins.cpp
js/src/wasm/WasmInstance.cpp
js/src/wasm/WasmJS.cpp
js/src/wasm/WasmModule.cpp
--- a/js/src/jit-test/tests/wasm/utf8.js
+++ b/js/src/jit-test/tests/wasm/utf8.js
@@ -17,8 +17,20 @@ var ins = new WebAssembly.Instance(mod);
 assertEq(ins.exports.hello(37), 2*37);
 
 assertEq(bin[25], 0x65);	// the 'e' in 'hello'
 bin[25] = 0x85;			// bad UTF-8
 
 assertEq(WebAssembly.validate(bin), false);
 
 assertThrowsInstanceOf(() => new WebAssembly.Module(bin), WebAssembly.CompileError);
+
+assertThrowsInstanceOf(() => wasmEvalText(`(module (import "\u2603" "")) `, {}), TypeError);
+
+{
+    let i1 = wasmEvalText(` (module (func (export "\u2603")))`);
+    assertThrowsInstanceOf(() => wasmEvalText(`(module (import "" "\u2603" (result i32)))`,
+                                              { "": { "\u2603": i1.exports['\u2603'] } }),
+                           WebAssembly.LinkError);
+    assertThrowsInstanceOf(() => wasmEvalText(`(module (import "\u2603" "" (result i32)))`,
+                                              { "\u2603": { "": i1.exports['\u2603'] } }),
+                           WebAssembly.LinkError);
+}
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -6440,17 +6440,17 @@ JS_ReportErrorNumberLatin1VA(JSContext* 
 {
     AssertHeapIsIdle();
     ReportErrorNumberVA(cx, JSREPORT_ERROR, errorCallback, userRef,
                         errorNumber, ArgumentsAreLatin1, ap);
 }
 
 JS_PUBLIC_API(void)
 JS_ReportErrorNumberUTF8(JSContext* cx, JSErrorCallback errorCallback,
-                           void* userRef, const unsigned errorNumber, ...)
+                         void* userRef, const unsigned errorNumber, ...)
 {
     va_list ap;
     va_start(ap, errorNumber);
     JS_ReportErrorNumberUTF8VA(cx, errorCallback, userRef, errorNumber, ap);
     va_end(ap);
 }
 
 JS_PUBLIC_API(void)
--- a/js/src/wasm/AsmJS.cpp
+++ b/js/src/wasm/AsmJS.cpp
@@ -8900,19 +8900,19 @@ js::IsAsmJSFunction(JSContext* cx, unsig
 
 bool
 js::IsAsmJSModuleLoadedFromCache(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     JSFunction* fun = MaybeWrappedNativeFunction(args.get(0));
     if (!fun || !IsAsmJSModule(fun)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_USE_ASM_TYPE_FAIL,
-                                  "argument passed to isAsmJSModuleLoadedFromCache is not a "
-                                  "validated asm.js module");
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_USE_ASM_TYPE_FAIL,
+                                 "argument passed to isAsmJSModuleLoadedFromCache is not a "
+                                 "validated asm.js module");
         return false;
     }
 
     bool loadedFromCache =
         AsmJSModuleFunctionToModule(fun).metadata().asAsmJS().cacheResult == CacheResult::Hit;
 
     args.rval().set(BooleanValue(loadedFromCache));
     return true;
--- a/js/src/wasm/WasmBinaryToAST.cpp
+++ b/js/src/wasm/WasmBinaryToAST.cpp
@@ -1871,18 +1871,18 @@ wasm::BinaryToAst(JSContext* cx, const u
     Decoder d(bytes, bytes + length, 0, &error, /* resilient */ true);
     AstDecodeContext c(cx, lifo, d, *result, true);
 
     if (!AstDecodeEnvironment(c) ||
         !AstDecodeCodeSection(c) ||
         !AstDecodeModuleTail(c))
     {
         if (error) {
-            JS_ReportErrorNumberASCII(c.cx, GetErrorMessage, nullptr, JSMSG_WASM_COMPILE_ERROR,
-                                      error.get());
+            JS_ReportErrorNumberUTF8(c.cx, GetErrorMessage, nullptr, JSMSG_WASM_COMPILE_ERROR,
+                                     error.get());
             return false;
         }
         ReportOutOfMemory(c.cx);
         return false;
     }
 
     MOZ_ASSERT(!error, "unreported error in decoding");
 
--- a/js/src/wasm/WasmBuiltins.cpp
+++ b/js/src/wasm/WasmBuiltins.cpp
@@ -269,31 +269,31 @@ WasmReportTrap(int32_t trapIndex)
         break;
       case Trap::StackOverflow:
         errorNumber = JSMSG_OVER_RECURSED;
         break;
       default:
         MOZ_CRASH("unexpected trap");
     }
 
-    JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, errorNumber);
+    JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, errorNumber);
 }
 
 static void
 WasmReportOutOfBounds()
 {
     JSContext* cx = TlsContext.get();
-    JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_OUT_OF_BOUNDS);
+    JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_OUT_OF_BOUNDS);
 }
 
 static void
 WasmReportUnalignedAccess()
 {
     JSContext* cx = TlsContext.get();
-    JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_UNALIGNED_ACCESS);
+    JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_UNALIGNED_ACCESS);
 }
 
 static int32_t
 CoerceInPlace_ToInt32(Value* rawVal)
 {
     JSContext* cx = TlsContext.get();
 
     int32_t i32;
--- a/js/src/wasm/WasmInstance.cpp
+++ b/js/src/wasm/WasmInstance.cpp
@@ -145,17 +145,17 @@ Instance::callImport(JSContext* cx, uint
           case ValType::F32:
             args[i].set(JS::CanonicalizedDoubleValue(*(float*)&argv[i]));
             break;
           case ValType::F64:
             args[i].set(JS::CanonicalizedDoubleValue(*(double*)&argv[i]));
             break;
           case ValType::I64: {
             if (!JitOptions.wasmTestMode) {
-                JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_I64);
+                JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_I64);
                 return false;
             }
             RootedObject obj(cx, CreateI64Object(cx, *(int64_t*)&argv[i]));
             if (!obj)
                 return false;
             args[i].set(ObjectValue(*obj));
             hasI64Arg = true;
             break;
@@ -175,17 +175,17 @@ Instance::callImport(JSContext* cx, uint
     RootedFunction importFun(cx, &import.obj->as<JSFunction>());
     RootedValue fval(cx, ObjectValue(*import.obj));
     RootedValue thisv(cx, UndefinedValue());
     if (!Call(cx, fval, thisv, args, rval))
         return false;
 
     // Throw an error if returning i64 and not in test mode.
     if (!JitOptions.wasmTestMode && fi.sig().ret() == ExprType::I64) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_I64);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_I64);
         return false;
     }
 
     // Don't try to optimize if the function has at least one i64 arg or if
     // it returns an int64. GenerateJitExit relies on this, as does the
     // type inference code below in this function.
     if (hasI64Arg || fi.sig().ret() == ExprType::I64)
         return true;
@@ -606,17 +606,17 @@ Instance::callExport(JSContext* cx, uint
         v = i < args.length() ? args[i] : UndefinedValue();
         switch (func.sig().arg(i)) {
           case ValType::I32:
             if (!ToInt32(cx, v, (int32_t*)&exportArgs[i]))
                 return false;
             break;
           case ValType::I64:
             if (!JitOptions.wasmTestMode) {
-                JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_I64);
+                JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_I64);
                 return false;
             }
             if (!ReadI64Object(cx, v, (int64_t*)&exportArgs[i]))
                 return false;
             break;
           case ValType::F32:
             if (JitOptions.wasmTestMode && v.isObject()) {
                 if (!ReadCustomFloat32NaNObject(cx, v, (uint32_t*)&exportArgs[i]))
@@ -717,17 +717,17 @@ Instance::callExport(JSContext* cx, uint
       case ExprType::Void:
         args.rval().set(UndefinedValue());
         break;
       case ExprType::I32:
         args.rval().set(Int32Value(*(int32_t*)retAddr));
         break;
       case ExprType::I64:
         if (!JitOptions.wasmTestMode) {
-            JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_I64);
+            JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_I64);
             return false;
         }
         retObj = CreateI64Object(cx, *(int64_t*)retAddr);
         if (!retObj)
             return false;
         break;
       case ExprType::F32:
         if (JitOptions.wasmTestMode && IsNaN(*(float*)retAddr)) {
--- a/js/src/wasm/WasmJS.cpp
+++ b/js/src/wasm/WasmJS.cpp
@@ -189,24 +189,24 @@ wasm::ReadI64Object(JSContext* cx, Handl
         return false;
 
     return true;
 }
 
 static bool
 ThrowBadImportArg(JSContext* cx)
 {
-    JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_ARG);
+    JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_ARG);
     return false;
 }
 
 static bool
 ThrowBadImportType(JSContext* cx, const char* field, const char* str)
 {
-    JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_TYPE, field, str);
+    JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_TYPE, field, str);
     return false;
 }
 
 static bool
 GetProperty(JSContext* cx, HandleObject obj, const char* chars, MutableHandleValue v)
 {
     JSAtom* atom = AtomizeUTF8Chars(cx, chars, strlen(chars));
     if (!atom)
@@ -234,18 +234,18 @@ GetImports(JSContext* cx,
     uint32_t globalIndex = 0;
     const GlobalDescVector& globals = metadata.globals;
     for (const Import& import : imports) {
         RootedValue v(cx);
         if (!GetProperty(cx, importObj, import.module.get(), &v))
             return false;
 
         if (!v.isObject()) {
-            JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_FIELD,
-                                      import.module.get());
+            JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_FIELD,
+                                     import.module.get());
             return false;
         }
 
         RootedObject obj(cx, &v.toObject());
         if (!GetProperty(cx, obj, import.field.get(), &v))
             return false;
 
         switch (import.kind) {
@@ -388,18 +388,18 @@ wasm::Eval(JSContext* cx, Handle<TypedAr
     MutableCompileArgs compileArgs = cx->new_<CompileArgs>();
     if (!compileArgs || !compileArgs->initFromContext(cx, Move(scriptedCaller)))
         return false;
 
     UniqueChars error;
     SharedModule module = CompileBuffer(*compileArgs, *bytecode, &error);
     if (!module) {
         if (error) {
-            JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_COMPILE_ERROR,
-                                      error.get());
+            JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_COMPILE_ERROR,
+                                     error.get());
             return false;
         }
         ReportOutOfMemory(cx);
         return false;
     }
 
     Rooted<FunctionVector> funcs(cx, FunctionVector(cx));
     RootedWasmTableObject table(cx);
@@ -418,17 +418,17 @@ static bool
 ToNonWrappingUint32(JSContext* cx, HandleValue v, uint32_t max, const char* kind, const char* noun,
                     uint32_t* u32)
 {
     double dbl;
     if (!ToInteger(cx, v, &dbl))
         return false;
 
     if (dbl < 0 || dbl > max) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_UINT32, kind, noun);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_UINT32, kind, noun);
         return false;
     }
 
     *u32 = uint32_t(dbl);
     MOZ_ASSERT(double(*u32) == dbl);
     return true;
 }
 
@@ -462,18 +462,18 @@ GetLimits(JSContext* cx, HandleObject ob
         if (!GetProperty(cx, obj, obj, maximumId, &maxVal))
             return false;
 
         limits->maximum.emplace();
         if (!ToNonWrappingUint32(cx, maxVal, maxMaximum, kind, "maximum size", limits->maximum.ptr()))
             return false;
 
         if (limits->initial > *limits->maximum) {
-            JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_UINT32,
-                                      kind, "maximum size");
+            JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_UINT32,
+                                     kind, "maximum size");
             return false;
         }
     }
 
     return true;
 }
 
 // ============================================================================
@@ -532,17 +532,17 @@ IsModuleObject(JSObject* obj, Module** m
 
 static bool
 GetModuleArg(JSContext* cx, CallArgs args, const char* name, Module** module)
 {
     if (!args.requireAtLeast(cx, name, 1))
         return false;
 
     if (!args[0].isObject() || !IsModuleObject(&args[0].toObject(), module)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_MOD_ARG);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_MOD_ARG);
         return false;
     }
 
     return true;
 }
 
 struct KindNames
 {
@@ -833,17 +833,17 @@ GetBufferSource(JSContext* cx, JSObject*
     if (!*bytecode)
         return false;
 
     JSObject* unwrapped = CheckedUnwrap(obj);
 
     SharedMem<uint8_t*> dataPointer;
     size_t byteLength;
     if (!unwrapped || !IsBufferSource(unwrapped, &dataPointer, &byteLength)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, errorNumber);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, errorNumber);
         return false;
     }
 
     if (!(*bytecode)->append(dataPointer.unwrap(), byteLength)) {
         ReportOutOfMemory(cx);
         return false;
     }
 
@@ -874,34 +874,34 @@ WasmModuleObject::construct(JSContext* c
 
     if (!ThrowIfNotConstructing(cx, callArgs, "Module"))
         return false;
 
     if (!callArgs.requireAtLeast(cx, "WebAssembly.Module", 1))
         return false;
 
     if (!callArgs[0].isObject()) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_BUF_ARG);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_BUF_ARG);
         return false;
     }
 
     MutableBytes bytecode;
     if (!GetBufferSource(cx, &callArgs[0].toObject(), JSMSG_WASM_BAD_BUF_ARG, &bytecode))
         return false;
 
     SharedCompileArgs compileArgs = InitCompileArgs(cx);
     if (!compileArgs)
         return false;
 
     UniqueChars error;
     SharedModule module = CompileBuffer(*compileArgs, *bytecode, &error);
     if (!module) {
         if (error) {
-            JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_COMPILE_ERROR,
-                                      error.get());
+            JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_COMPILE_ERROR,
+                                     error.get());
             return false;
         }
         ReportOutOfMemory(cx);
         return false;
     }
 
     RootedObject proto(cx, &cx->global()->getPrototype(JSProto_WasmModule).toObject());
     RootedObject moduleObj(cx, WasmModuleObject::create(cx, *module, proto));
@@ -1102,17 +1102,17 @@ WasmInstanceObject::construct(JSContext*
     if (!ThrowIfNotConstructing(cx, args, "Instance"))
         return false;
 
     if (!args.requireAtLeast(cx, "WebAssembly.Instance", 1))
         return false;
 
     Module* module;
     if (!args[0].isObject() || !IsModuleObject(&args[0].toObject(), &module)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_MOD_ARG);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_MOD_ARG);
         return false;
     }
 
     RootedObject importObj(cx);
     if (!GetImportArg(cx, args, &importObj))
         return false;
 
     RootedWasmInstanceObject instanceObj(cx);
@@ -1350,17 +1350,17 @@ WasmMemoryObject::construct(JSContext* c
 
     if (!ThrowIfNotConstructing(cx, args, "Memory"))
         return false;
 
     if (!args.requireAtLeast(cx, "WebAssembly.Memory", 1))
         return false;
 
     if (!args.get(0).isObject()) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_DESC_ARG, "memory");
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_DESC_ARG, "memory");
         return false;
     }
 
     RootedObject obj(cx, &args[0].toObject());
     Limits limits;
     if (!GetLimits(cx, obj, MaxMemoryInitialPages, MaxMemoryMaximumPages, "Memory", &limits))
         return false;
 
@@ -1415,17 +1415,17 @@ WasmMemoryObject::growImpl(JSContext* cx
 
     uint32_t delta;
     if (!ToNonWrappingUint32(cx, args.get(0), UINT32_MAX, "Memory", "grow delta", &delta))
         return false;
 
     uint32_t ret = grow(memory, delta, cx);
 
     if (ret == uint32_t(-1)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_GROW, "memory");
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_GROW, "memory");
         return false;
     }
 
     args.rval().setInt32(ret);
     return true;
 }
 
 /* static */ bool
@@ -1636,42 +1636,42 @@ WasmTableObject::construct(JSContext* cx
 
     if (!ThrowIfNotConstructing(cx, args, "Table"))
         return false;
 
     if (!args.requireAtLeast(cx, "WebAssembly.Table", 1))
         return false;
 
     if (!args.get(0).isObject()) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_DESC_ARG, "table");
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_DESC_ARG, "table");
         return false;
     }
 
     RootedObject obj(cx, &args[0].toObject());
 
     JSAtom* elementAtom = Atomize(cx, "element", strlen("element"));
     if (!elementAtom)
         return false;
     RootedId elementId(cx, AtomToId(elementAtom));
 
     RootedValue elementVal(cx);
     if (!GetProperty(cx, obj, obj, elementId, &elementVal))
         return false;
 
     if (!elementVal.isString()) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_ELEMENT);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_ELEMENT);
         return false;
     }
 
     JSLinearString* elementStr = elementVal.toString()->ensureLinear(cx);
     if (!elementStr)
         return false;
 
     if (!StringEqualsAscii(elementStr, "anyfunc")) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_ELEMENT);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_ELEMENT);
         return false;
     }
 
     Limits limits;
     if (!GetLimits(cx, obj, MaxTableInitialLength, UINT32_MAX, "Table", &limits))
         return false;
 
     RootedWasmTableObject table(cx, WasmTableObject::create(cx, limits));
@@ -1754,17 +1754,17 @@ WasmTableObject::setImpl(JSContext* cx, 
         return false;
 
     uint32_t index;
     if (!ToNonWrappingUint32(cx, args.get(0), table.length() - 1, "Table", "set index", &index))
         return false;
 
     RootedFunction value(cx);
     if (!IsExportedFunction(args[1], &value) && !args[1].isNull()) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_TABLE_VALUE);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_TABLE_VALUE);
         return false;
     }
 
     if (value) {
         RootedWasmInstanceObject instanceObj(cx, ExportedFunctionToInstanceObject(value));
         uint32_t funcIndex = ExportedFunctionToFuncIndex(value);
 
 #ifdef DEBUG
@@ -1801,17 +1801,17 @@ WasmTableObject::growImpl(JSContext* cx,
 
     uint32_t delta;
     if (!ToNonWrappingUint32(cx, args.get(0), UINT32_MAX, "Table", "grow delta", &delta))
         return false;
 
     uint32_t ret = table->table().grow(delta, cx);
 
     if (ret == uint32_t(-1)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_GROW, "table");
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_GROW, "table");
         return false;
     }
 
     args.rval().setInt32(ret);
     return true;
 }
 
 /* static */ bool
@@ -1999,17 +1999,17 @@ EnsurePromiseSupport(JSContext* cx)
 
 static bool
 GetBufferSource(JSContext* cx, CallArgs callArgs, const char* name, MutableBytes* bytecode)
 {
     if (!callArgs.requireAtLeast(cx, name, 1))
         return false;
 
     if (!callArgs[0].isObject()) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_BUF_ARG);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_BUF_ARG);
         return false;
     }
 
     return GetBufferSource(cx, &callArgs[0].toObject(), JSMSG_WASM_BAD_BUF_ARG, bytecode);
 }
 
 static bool
 WebAssembly_compile(JSContext* cx, unsigned argc, Value* vp)
@@ -2040,17 +2040,17 @@ WebAssembly_compile(JSContext* cx, unsig
 static bool
 GetInstantiateArgs(JSContext* cx, CallArgs callArgs, MutableHandleObject firstArg,
                    MutableHandleObject importObj)
 {
     if (!callArgs.requireAtLeast(cx, "WebAssembly.instantiate", 1))
         return false;
 
     if (!callArgs[0].isObject()) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_BUF_MOD_ARG);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_BUF_MOD_ARG);
         return false;
     }
 
     firstArg.set(&callArgs[0].toObject());
 
     return GetImportArg(cx, callArgs, importObj);
 }
 
@@ -2137,17 +2137,17 @@ EnsureStreamSupport(JSContext* cx)
     }
 
     return true;
 }
 
 static bool
 RejectWithErrorNumber(JSContext* cx, uint32_t errorNumber, Handle<PromiseObject*> promise)
 {
-    JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, errorNumber);
+    JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, errorNumber);
     return RejectWithPendingException(cx, promise);
 }
 
 class CompileStreamTask : public PromiseHelperTask, public JS::StreamConsumer
 {
     enum StreamState { Env, Code, Tail, Closed };
     typedef ExclusiveWaitableData<StreamState> ExclusiveStreamState;
 
--- a/js/src/wasm/WasmModule.cpp
+++ b/js/src/wasm/WasmModule.cpp
@@ -724,30 +724,30 @@ Module::initSegments(JSContext* cx,
 
     for (const ElemSegment& seg : elemSegments_) {
         uint32_t numElems = seg.elemCodeRangeIndices(tier).length();
 
         uint32_t tableLength = tables[seg.tableIndex]->length();
         uint32_t offset = EvaluateInitExpr(globalImports, seg.offset);
 
         if (offset > tableLength || tableLength - offset < numElems) {
-            JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_FIT,
-                                      "elem", "table");
+            JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_FIT,
+                                     "elem", "table");
             return false;
         }
     }
 
     if (memoryObj) {
         for (const DataSegment& seg : dataSegments_) {
             uint32_t memoryLength = memoryObj->buffer().byteLength();
             uint32_t offset = EvaluateInitExpr(globalImports, seg.offset);
 
             if (offset > memoryLength || memoryLength - offset < seg.length) {
-                JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_FIT,
-                                          "data", "memory");
+                JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_FIT,
+                                         "data", "memory");
                 return false;
             }
         }
     } else {
         MOZ_ASSERT(dataSegments_.empty());
     }
 
     // Now that initialization can't fail partway through, write data/elem
@@ -827,18 +827,18 @@ Module::instantiateFunctions(JSContext* 
             continue;
 
         uint32_t funcIndex = ExportedFunctionToFuncIndex(f);
         Instance& instance = ExportedFunctionToInstance(f);
         const FuncExport& funcExport = instance.metadata(tier).lookupFuncExport(funcIndex);
 
         if (funcExport.sig() != metadata(tier).funcImports[i].sig()) {
             const Import& import = FindImportForFuncImport(imports_, i);
-            JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_SIG,
-                                      import.module.get(), import.field.get());
+            JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_SIG,
+                                     import.module.get(), import.field.get());
             return false;
         }
     }
 
     return true;
 }
 
 static bool
@@ -848,22 +848,22 @@ CheckLimits(JSContext* cx, uint32_t decl
     if (isAsmJS) {
         MOZ_ASSERT(actualLength >= declaredMin);
         MOZ_ASSERT(!declaredMax);
         MOZ_ASSERT(actualLength == actualMax.value());
         return true;
     }
 
     if (actualLength < declaredMin || actualLength > declaredMax.valueOr(UINT32_MAX)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMP_SIZE, kind);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMP_SIZE, kind);
         return false;
     }
 
     if ((actualMax && declaredMax && *actualMax > *declaredMax) || (!actualMax && declaredMax)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMP_MAX, kind);
+        JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMP_MAX, kind);
         return false;
     }
 
     return true;
 }
 
 // asm.js module instantiation supplies its own buffer, but for wasm, create and
 // initialize the buffer if one is requested. Either way, the buffer is wrapped