diff --git a/js/src/asmjs/WasmJS.cpp b/js/src/asmjs/WasmJS.cpp index 36564fac31d94..ed1def1a4b5b2 100644 --- a/js/src/asmjs/WasmJS.cpp +++ b/js/src/asmjs/WasmJS.cpp @@ -193,9 +193,9 @@ ThrowBadImportArg(JSContext* cx) } static bool -ThrowBadImportField(JSContext* cx, const char* str) +ThrowBadImportField(JSContext* cx, const char* field, const char* str) { - JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_FIELD, str); + JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMPORT_FIELD, field, str); return false; } @@ -233,7 +233,7 @@ GetImports(JSContext* cx, return false; if (!v.isObject()) - return ThrowBadImportField(cx, "an Object"); + return ThrowBadImportField(cx, import.module.get(), "an Object"); RootedObject obj(cx, &v.toObject()); if (!GetProperty(cx, obj, import.field.get(), &v)) @@ -242,7 +242,7 @@ GetImports(JSContext* cx, switch (import.kind) { case DefinitionKind::Function: if (!IsFunctionObject(v)) - return ThrowBadImportField(cx, "a Function"); + return ThrowBadImportField(cx, import.field.get(), "a Function"); if (!funcImports.append(&v.toObject().as())) return false; @@ -250,14 +250,14 @@ GetImports(JSContext* cx, break; case DefinitionKind::Table: if (!v.isObject() || !v.toObject().is()) - return ThrowBadImportField(cx, "a Table"); + return ThrowBadImportField(cx, import.field.get(), "a Table"); MOZ_ASSERT(!tableImport); tableImport.set(&v.toObject().as()); break; case DefinitionKind::Memory: if (!v.isObject() || !v.toObject().is()) - return ThrowBadImportField(cx, "a Memory"); + return ThrowBadImportField(cx, import.field.get(), "a Memory"); MOZ_ASSERT(!memoryImport); memoryImport.set(&v.toObject().as()); @@ -271,7 +271,7 @@ GetImports(JSContext* cx, switch (global.type()) { case ValType::I32: { if (!v.isNumber()) - return ThrowBadImportField(cx, "a number"); + return ThrowBadImportField(cx, import.field.get(), "a number"); int32_t i32; if (!ToInt32(cx, v, &i32)) return false; @@ -295,7 +295,7 @@ GetImports(JSContext* cx, break; } if (!v.isNumber()) - return ThrowBadImportField(cx, "a number"); + return ThrowBadImportField(cx, import.field.get(), "a number"); double d; if (!ToNumber(cx, v, &d)) return false; @@ -311,7 +311,7 @@ GetImports(JSContext* cx, break; } if (!v.isNumber()) - return ThrowBadImportField(cx, "a number"); + return ThrowBadImportField(cx, import.field.get(), "a number"); double d; if (!ToNumber(cx, v, &d)) return false; diff --git a/js/src/jit-test/tests/wasm/basic.js b/js/src/jit-test/tests/wasm/basic.js index 41bff35216abb..dabab2d61e8b7 100644 --- a/js/src/jit-test/tests/wasm/basic.js +++ b/js/src/jit-test/tests/wasm/basic.js @@ -93,8 +93,8 @@ const noImportObj = "second argument must be an object"; assertErrorMessage(() => wasmEvalText('(module (import "a" "b"))', 1), TypeError, noImportObj); assertErrorMessage(() => wasmEvalText('(module (import "a" "b"))', null), TypeError, noImportObj); -const notObject = /import object field is not an Object/; -const notFunction = /import object field is not a Function/; +const notObject = /import object field '\w*' is not an Object/; +const notFunction = /import object field '\w*' is not a Function/; var code = '(module (import "a" "b"))'; assertErrorMessage(() => wasmEvalText(code), TypeError, noImportObj); diff --git a/js/src/jit-test/tests/wasm/import-export.js b/js/src/jit-test/tests/wasm/import-export.js index 9b22541634131..d6bcd4fbd9914 100644 --- a/js/src/jit-test/tests/wasm/import-export.js +++ b/js/src/jit-test/tests/wasm/import-export.js @@ -25,16 +25,16 @@ assertErrorMessage(() => new Memory({initial:2, maximum:1}), RangeError, /bad Me const m1 = new Module(wasmTextToBinary('(module (import "foo" "bar") (import "baz" "quux"))')); assertErrorMessage(() => new Instance(m1), TypeError, /second argument must be an object/); -assertErrorMessage(() => new Instance(m1, {foo:null}), TypeError, /import object field is not an Object/); -assertErrorMessage(() => new Instance(m1, {foo:{bar:{}}}), TypeError, /import object field is not a Function/); -assertErrorMessage(() => new Instance(m1, {foo:{bar:()=>{}}, baz:null}), TypeError, /import object field is not an Object/); -assertErrorMessage(() => new Instance(m1, {foo:{bar:()=>{}}, baz:{}}), TypeError, /import object field is not a Function/); +assertErrorMessage(() => new Instance(m1, {foo:null}), TypeError, /import object field 'foo' is not an Object/); +assertErrorMessage(() => new Instance(m1, {foo:{bar:{}}}), TypeError, /import object field 'bar' is not a Function/); +assertErrorMessage(() => new Instance(m1, {foo:{bar:()=>{}}, baz:null}), TypeError, /import object field 'baz' is not an Object/); +assertErrorMessage(() => new Instance(m1, {foo:{bar:()=>{}}, baz:{}}), TypeError, /import object field 'quux' is not a Function/); assertEq(new Instance(m1, {foo:{bar:()=>{}}, baz:{quux:()=>{}}}) instanceof Instance, true); const m2 = new Module(wasmTextToBinary('(module (import "x" "y" (memory 2 3)))')); assertErrorMessage(() => new Instance(m2), TypeError, /second argument must be an object/); -assertErrorMessage(() => new Instance(m2, {x:null}), TypeError, /import object field is not an Object/); -assertErrorMessage(() => new Instance(m2, {x:{y:{}}}), TypeError, /import object field is not a Memory/); +assertErrorMessage(() => new Instance(m2, {x:null}), TypeError, /import object field 'x' is not an Object/); +assertErrorMessage(() => new Instance(m2, {x:{y:{}}}), TypeError, /import object field 'y' is not a Memory/); assertErrorMessage(() => new Instance(m2, {x:{y:mem1Page}}), TypeError, /imported Memory with incompatible size/); assertErrorMessage(() => new Instance(m2, {x:{y:mem1PageMax1}}), TypeError, /imported Memory with incompatible size/); assertErrorMessage(() => new Instance(m2, {x:{y:mem4Page}}), TypeError, /imported Memory with incompatible size/); @@ -48,19 +48,19 @@ assertErrorMessage(() => new Instance(m2, {x:{y:mem2PageMax4}}), TypeError, /imp const m3 = new Module(wasmTextToBinary('(module (import "foo" "bar" (memory 1 1)) (import "baz" "quux"))')); assertErrorMessage(() => new Instance(m3), TypeError, /second argument must be an object/); -assertErrorMessage(() => new Instance(m3, {foo:null}), TypeError, /import object field is not an Object/); -assertErrorMessage(() => new Instance(m3, {foo:{bar:{}}}), TypeError, /import object field is not a Memory/); -assertErrorMessage(() => new Instance(m3, {foo:{bar:mem1Page}, baz:null}), TypeError, /import object field is not an Object/); -assertErrorMessage(() => new Instance(m3, {foo:{bar:mem1Page}, baz:{quux:mem1Page}}), TypeError, /import object field is not a Function/); +assertErrorMessage(() => new Instance(m3, {foo:null}), TypeError, /import object field 'foo' is not an Object/); +assertErrorMessage(() => new Instance(m3, {foo:{bar:{}}}), TypeError, /import object field 'bar' is not a Memory/); +assertErrorMessage(() => new Instance(m3, {foo:{bar:mem1Page}, baz:null}), TypeError, /import object field 'baz' is not an Object/); +assertErrorMessage(() => new Instance(m3, {foo:{bar:mem1Page}, baz:{quux:mem1Page}}), TypeError, /import object field 'quux' is not a Function/); assertErrorMessage(() => new Instance(m3, {foo:{bar:mem1Page}, baz:{quux:()=>{}}}), TypeError, /imported Memory with incompatible maximum size/); assertEq(new Instance(m3, {foo:{bar:mem1PageMax1}, baz:{quux:()=>{}}}) instanceof Instance, true); const m4 = new Module(wasmTextToBinary('(module (import "baz" "quux") (import "foo" "bar" (memory 1 1)))')); assertErrorMessage(() => new Instance(m4), TypeError, /second argument must be an object/); -assertErrorMessage(() => new Instance(m4, {baz:null}), TypeError, /import object field is not an Object/); -assertErrorMessage(() => new Instance(m4, {baz:{quux:{}}}), TypeError, /import object field is not a Function/); -assertErrorMessage(() => new Instance(m4, {baz:{quux:()=>{}}, foo:null}), TypeError, /import object field is not an Object/); -assertErrorMessage(() => new Instance(m4, {baz:{quux:()=>{}}, foo:{bar:()=>{}}}), TypeError, /import object field is not a Memory/); +assertErrorMessage(() => new Instance(m4, {baz:null}), TypeError, /import object field 'baz' is not an Object/); +assertErrorMessage(() => new Instance(m4, {baz:{quux:{}}}), TypeError, /import object field 'quux' is not a Function/); +assertErrorMessage(() => new Instance(m4, {baz:{quux:()=>{}}, foo:null}), TypeError, /import object field 'foo' is not an Object/); +assertErrorMessage(() => new Instance(m4, {baz:{quux:()=>{}}, foo:{bar:()=>{}}}), TypeError, /import object field 'bar' is not a Memory/); assertErrorMessage(() => new Instance(m4, {baz:{quux:()=>{}}, foo:{bar:mem1Page}}), TypeError, /imported Memory with incompatible maximum size/); assertEq(new Instance(m3, {baz:{quux:()=>{}}, foo:{bar:mem1PageMax1}}) instanceof Instance, true); @@ -104,7 +104,7 @@ var importObj = { get foo() { arr.push("foo") }, get baz() { arr.push("bad") }, }; -assertErrorMessage(() => new Instance(m1, importObj), TypeError, /import object field is not an Object/); +assertErrorMessage(() => new Instance(m1, importObj), TypeError, /import object field 'foo' is not an Object/); assertEq(arr.join(), "foo"); var arr = []; @@ -115,7 +115,7 @@ var importObj = { }, get baz() { arr.push("bad") }, }; -assertErrorMessage(() => new Instance(m1, importObj), TypeError, /import object field is not a Function/); +assertErrorMessage(() => new Instance(m1, importObj), TypeError, /import object field 'bar' is not a Function/); assertEq(arr.join(), "foo,bar"); var arr = []; diff --git a/js/src/js.msg b/js/src/js.msg index 2973de2b700df..57eba82f6524c 100644 --- a/js/src/js.msg +++ b/js/src/js.msg @@ -365,7 +365,7 @@ MSG_DEF(JSMSG_WASM_BAD_IMP_SIZE, 1, JSEXN_TYPEERR, "imported {0} with MSG_DEF(JSMSG_WASM_BAD_IMP_MAX, 1, JSEXN_TYPEERR, "imported {0} with incompatible maximum size") MSG_DEF(JSMSG_WASM_BAD_ELEMENT, 0, JSEXN_TYPEERR, "\"element\" property of table descriptor must be \"anyfunc\"") MSG_DEF(JSMSG_WASM_BAD_IMPORT_ARG, 0, JSEXN_TYPEERR, "second argument must be an object") -MSG_DEF(JSMSG_WASM_BAD_IMPORT_FIELD, 1, JSEXN_TYPEERR, "import object field is not {0}") +MSG_DEF(JSMSG_WASM_BAD_IMPORT_FIELD, 2, JSEXN_TYPEERR, "import object field '{0}' is not {1}") MSG_DEF(JSMSG_WASM_BAD_IMPORT_SIG, 0, JSEXN_TYPEERR, "imported function signature mismatch") MSG_DEF(JSMSG_WASM_BAD_TABLE_VALUE, 0, JSEXN_TYPEERR, "can only assign WebAssembly exported functions to Table") MSG_DEF(JSMSG_WASM_BAD_I64, 0, JSEXN_TYPEERR, "cannot pass i64 to or from JS")