diff --git a/dom/browser-element/mochitest/browserElement_ExecuteScript.js b/dom/browser-element/mochitest/browserElement_ExecuteScript.js index 3b217816b5df..334a4f8791cd 100644 --- a/dom/browser-element/mochitest/browserElement_ExecuteScript.js +++ b/dom/browser-element/mochitest/browserElement_ExecuteScript.js @@ -91,7 +91,7 @@ function runTest() { ok(c(rv, 'YQ=='), `scriptId: ${scriptId++}`); return iframe.executeScript('window.wrappedJSObject.btoa("a")', {url}) }, bail).then(bail, (error) => { - is(error.message, `TypeError: window.wrappedJSObject is undefined, can't access its "btoa" property`, `scriptId: ${scriptId++}`); + is(error.message, `TypeError: window.wrappedJSObject is undefined, can't access property "btoa" of it`, `scriptId: ${scriptId++}`); return iframe.executeScript('42', {}) }).then(bail, error => { is(error.name, 'InvalidAccessError', `scriptId: ${scriptId++}`); diff --git a/js/src/jit-test/tests/basic/bug827104.js b/js/src/jit-test/tests/basic/bug827104.js index a506f5ff7412..343fcebcd596 100644 --- a/js/src/jit-test/tests/basic/bug827104.js +++ b/js/src/jit-test/tests/basic/bug827104.js @@ -10,4 +10,4 @@ var e; try { f(); } catch (error) {e = error;} -assertEq(e.toString(), `TypeError: a[i] is undefined; can't access element at index 0`); +assertEq(e.toString(), `TypeError: a[i] is undefined, can't access property 0 of it`); diff --git a/js/src/jit-test/tests/basic/expression-autopsy.js b/js/src/jit-test/tests/basic/expression-autopsy.js index 06a7e0c3bc33..c3a145827ff1 100644 --- a/js/src/jit-test/tests/basic/expression-autopsy.js +++ b/js/src/jit-test/tests/basic/expression-autopsy.js @@ -18,7 +18,7 @@ function check_one(expected, f, err) { ieval = eval; function check(expr, expected=expr, testStrict=true) { var end, err; - for ([end, err] of [[".random_prop", ` is undefined; can't access its "random_prop" property`], ["()", " is not a function"]]) { + for ([end, err] of [[".random_prop", ` is undefined, can't access property \"random_prop" of it`], ["()", " is not a function"]]) { var statement = "o = {};" + expr + end, f; var cases = [ // Global scope @@ -102,7 +102,7 @@ check_one("6", (function () { 6() }), " is not a function"); check_one("4", (function() { (4||eval)(); }), " is not a function"); check_one("0", (function () { Array.prototype.reverse.call('123'); }), " is read-only"); check_one("[...][Symbol.iterator](...).next(...).value", - function () { ieval("{ let x; var [a, b, [c0, c1]] = [x, x, x]; }") }, " is undefined; can't access its Symbol.iterator property"); + function () { ieval("{ let x; var [a, b, [c0, c1]] = [x, x, x]; }") }, " is undefined, can't access property Symbol.iterator of it"); check_one("(void 1)", function() { (void 1)(); }, " is not a function"); check_one("(void o[1])", function() { var o = []; (void o[1])() }, " is not a function"); diff --git a/js/src/jit-test/tests/basic/iterable-error-messages.js b/js/src/jit-test/tests/basic/iterable-error-messages.js index b32b27e9c9b2..d783d15900c3 100644 --- a/js/src/jit-test/tests/basic/iterable-error-messages.js +++ b/js/src/jit-test/tests/basic/iterable-error-messages.js @@ -15,7 +15,7 @@ function testForOf(val) { for (v of [{}, Math, new Proxy({}, {})]) { assertThrowsMsg(() => testForOf(v), "val is not iterable"); } -assertThrowsMsg(() => testForOf(null), "val is null; can't access its Symbol.iterator property"); +assertThrowsMsg(() => testForOf(null), "val is null, can't access property Symbol.iterator of it"); assertThrowsMsg(() => { for (var x of () => 1) {}}, "() => 1 is not iterable"); // Destructuring @@ -25,7 +25,7 @@ function testDestr(val) { for (v of [{}, Math, new Proxy({}, {})]) { assertThrowsMsg(() => testDestr(v), "val is not iterable"); } -assertThrowsMsg(() => testDestr(null), "val is null; can't access its Symbol.iterator property"); +assertThrowsMsg(() => testDestr(null), "val is null, can't access property Symbol.iterator of it"); assertThrowsMsg(() => { [a, b] = () => 1; }, "() => 1 is not iterable"); // Spread @@ -35,5 +35,5 @@ function testSpread(val) { for (v of [{}, Math, new Proxy({}, {})]) { assertThrowsMsg(() => testSpread(v), "val is not iterable"); } -assertThrowsMsg(() => testSpread(null), "val is null; can't access its Symbol.iterator property"); +assertThrowsMsg(() => testSpread(null), "val is null, can't access property Symbol.iterator of it"); assertThrowsMsg(() => { [...() => 1]; }, "() => 1 is not iterable"); diff --git a/js/src/jit-test/tests/basic/testBug604210.js b/js/src/jit-test/tests/basic/testBug604210.js index f4119f016947..bb96e7c4963f 100644 --- a/js/src/jit-test/tests/basic/testBug604210.js +++ b/js/src/jit-test/tests/basic/testBug604210.js @@ -6,6 +6,6 @@ function f() { } catch (e) { msg = '' + e; } - assertEq(msg, `TypeError: x is undefined; can't access its "foo" property`); + assertEq(msg, `TypeError: x is undefined, can't access property "foo" of it`); } f(); diff --git a/js/src/jit-test/tests/debug/bug1275001.js b/js/src/jit-test/tests/debug/bug1275001.js index 84d5a7013db1..868a7bda2cf5 100644 --- a/js/src/jit-test/tests/debug/bug1275001.js +++ b/js/src/jit-test/tests/debug/bug1275001.js @@ -17,13 +17,13 @@ function check_one(expected, f, err) { ieval = eval function check(expr, expected = expr) { var end, err - for ([end, err] of [[".random_prop", ` is undefined, can't access its "random_prop" property`]]) + for ([end, err] of[[".random_prop", ` is undefined, can't access property \"random_prop" of it` ]]) statement = "o = {};" + expr + end; cases = [ function() { return ieval("var undef;" + statement); }, Function(statement) ] - for (f of cases) + for (f of cases) check_one(expected, f, err) } check("undef"); diff --git a/js/src/jit-test/tests/ion/bug913749.js b/js/src/jit-test/tests/ion/bug913749.js index 068086e362d4..bece1e07d37c 100644 --- a/js/src/jit-test/tests/ion/bug913749.js +++ b/js/src/jit-test/tests/ion/bug913749.js @@ -15,7 +15,7 @@ for (var i = 0; i < 3; i++) { x.toString(); assertEq(0, 1); } catch (e) { - assertEq(e.message === `y is undefined; can't access its "length" property` || + assertEq(e.message === `y is undefined, can't access property "length" of it` || e.message === "undefined has no properties", true); } } diff --git a/js/src/js.msg b/js/src/js.msg index 2158cc6f7662..92e5d4d0d9f7 100644 --- a/js/src/js.msg +++ b/js/src/js.msg @@ -9,22 +9,21 @@ * * The format for each JS error message is: * - * MSG_DEF(, , , - * ) + * MSG_DEF(, , , + * ) * - * where: + * where ; + * is a legal C identifer that will be used in the + * JS engine source. * - * is a legal C identifer that will be used in the - * JS engine source. + * is an integer literal specifying the total number of + * replaceable arguments in the following format string. * - * is an integer literal specifying the total number of - * replaceable arguments in the following format string. + * is an enum JSExnType value, defined in jsapi.h. * - * is an enum JSExnType value, defined in jsapi.h. - * - * is a string literal, optionally containing sequences - * {X} where X is an integer representing the argument number that will - * be replaced with a string value when the error is reported. + * is a string literal, optionally containing sequences + * {X} where X is an integer representing the argument number that will + * be replaced with a string value when the error is reported. * * e.g. * @@ -56,8 +55,7 @@ MSG_DEF(JSMSG_TOPRIMITIVE_NOT_CALLABLE, 2, JSEXN_TYPEERR, "can't convert {0} to MSG_DEF(JSMSG_TOPRIMITIVE_RETURNED_OBJECT, 2, JSEXN_TYPEERR, "can't convert {0} to {1}: its [Symbol.toPrimitive] method returned an object") MSG_DEF(JSMSG_NO_PROPERTIES, 1, JSEXN_TYPEERR, "{0} has no properties") MSG_DEF(JSMSG_PROPERTY_FAIL, 2, JSEXN_TYPEERR, "can't access property {0} of {1}") -MSG_DEF(JSMSG_PROPERTY_FAIL_EXPR, 3, JSEXN_TYPEERR, "{0} is {1}; can't access its {2} property") -MSG_DEF(JSMSG_ELEMENT_FAIL_EXPR, 3, JSEXN_TYPEERR, "{0} is {1}; can't access element at index {2}") +MSG_DEF(JSMSG_PROPERTY_FAIL_EXPR, 3, JSEXN_TYPEERR, "{0} is {1}, can't access property {2} of it") MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") MSG_DEF(JSMSG_INVALID_DATA_VIEW_LENGTH, 0, JSEXN_RANGEERR, "invalid data view length") MSG_DEF(JSMSG_OFFSET_LARGER_THAN_FILESIZE, 0, JSEXN_RANGEERR, "offset is larger than filesize") diff --git a/js/src/jsapi-tests/testErrorInterceptor.cpp b/js/src/jsapi-tests/testErrorInterceptor.cpp index e347a226e636..ab88abdfa233 100644 --- a/js/src/jsapi-tests/testErrorInterceptor.cpp +++ b/js/src/jsapi-tests/testErrorInterceptor.cpp @@ -34,25 +34,25 @@ BEGIN_TEST(testErrorInterceptor) { // Run the following snippets. const char* SAMPLES[] = { - "throw new Error('I am an Error')", - "throw new TypeError('I am a TypeError')", - "throw new ReferenceError('I am a ReferenceError')", - "throw new SyntaxError('I am a SyntaxError')", - "throw 5", - "undefined[0]", - "foo[0]", - "b[", + "throw new Error('I am an Error')\0", + "throw new TypeError('I am a TypeError')\0", + "throw new ReferenceError('I am a ReferenceError')\0", + "throw new SyntaxError('I am a SyntaxError')\0", + "throw 5\0", + "undefined[0]\0", + "foo[0]\0", + "b[\0", }; // With the simpleInterceptor, we should end up with the following error: const char* TO_STRING[] = { - "Error: I am an Error", - "TypeError: I am a TypeError", - "ReferenceError: I am a ReferenceError", - "SyntaxError: I am a SyntaxError", - "5", - "TypeError: can't access property 0 of undefined", - "ReferenceError: foo is not defined", - "SyntaxError: expected expression, got end of script", + "Error: I am an Error\0", + "TypeError: I am a TypeError\0", + "ReferenceError: I am a ReferenceError\0", + "SyntaxError: I am a SyntaxError\0", + "5\0", + "TypeError: can't access property 0 of undefined\0", + "ReferenceError: foo is not defined\0", + "SyntaxError: expected expression, got end of script\0", }; MOZ_ASSERT(mozilla::ArrayLength(SAMPLES) == mozilla::ArrayLength(TO_STRING)); diff --git a/js/src/tests/non262/extensions/regress-353116.js b/js/src/tests/non262/extensions/regress-353116.js index 2debc2604587..0ec70e977b78 100644 --- a/js/src/tests/non262/extensions/regress-353116.js +++ b/js/src/tests/non262/extensions/regress-353116.js @@ -45,7 +45,7 @@ function test() } reportCompare(expect, actual, summary); - expect = `TypeError: x is undefined; can't access its "y" property`; + expect = `TypeError: x is undefined, can't access property "y" of it`; actual = 'No Error'; try @@ -59,7 +59,7 @@ function test() } reportCompare(expect, actual, summary); - expect = `TypeError: x is null; can't access its "y" property`; + expect = `TypeError: x is null, can't access property "y" of it`; actual = 'No Error'; try diff --git a/js/src/tests/non262/regress/regress-469625-03.js b/js/src/tests/non262/regress/regress-469625-03.js index f814ef0b8bc5..a210b0625b11 100644 --- a/js/src/tests/non262/regress/regress-469625-03.js +++ b/js/src/tests/non262/regress/regress-469625-03.js @@ -25,7 +25,7 @@ function test() var [a, b, [c0, c1]] = [x, x, x]; } - expect = `TypeError: [...][Symbol.iterator](...).next(...).value is null; can't access its Symbol.iterator property`; + expect = `TypeError: [...][Symbol.iterator](...).next(...).value is null, can't access property Symbol.iterator of it`; actual = 'No Error'; try { diff --git a/js/src/tests/non262/regress/regress-469758.js b/js/src/tests/non262/regress/regress-469758.js index 2cc892e74478..9fe08149d781 100644 --- a/js/src/tests/non262/regress/regress-469758.js +++ b/js/src/tests/non262/regress/regress-469758.js @@ -9,6 +9,6 @@ try { err = e; } assertEq(err instanceof TypeError, true); -assertEq(err.message, "[][j] is undefined; can't access element at index 2"); +assertEq(err.message, "[][j] is undefined, can't access property 2 of it"); reportCompare(0, 0, 'ok'); diff --git a/js/src/vm/JSContext.cpp b/js/src/vm/JSContext.cpp index f32d43eb0c72..d3a37f1a4373 100644 --- a/js/src/vm/JSContext.cpp +++ b/js/src/vm/JSContext.cpp @@ -953,15 +953,13 @@ js::ReportIsNullOrUndefinedForPropertyAccess(JSContext* cx, HandleValue v, Handl if (strcmp(bytes.get(), js_undefined_str) == 0 || strcmp(bytes.get(), js_null_str) == 0) { JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_PROPERTY_FAIL, keyBytes.get(), bytes.get()); + } else if (v.isUndefined()) { + JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_PROPERTY_FAIL_EXPR, + bytes.get(), js_undefined_str, keyBytes.get()); } else { - const char* actual = v.isUndefined() ? js_undefined_str : js_null_str; - if (JSID_IS_INT(key)) { - JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_ELEMENT_FAIL_EXPR, - bytes.get(), actual, keyBytes.get()); - } else { - JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_PROPERTY_FAIL_EXPR, - bytes.get(), actual, keyBytes.get()); - } + MOZ_ASSERT(v.isNull()); + JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_PROPERTY_FAIL_EXPR, + bytes.get(), js_null_str, keyBytes.get()); } } diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_create_iframe.js b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_create_iframe.js index c4593d105140..bd53c5e8896c 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_create_iframe.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_create_iframe.js @@ -125,7 +125,7 @@ add_task(async function test_contentscript_create_iframe() { Assert.ok(!manifest, "manifest should be undefined"); Assert.equal(String(manifestException), - `TypeError: win.browser.runtime is undefined, can't access its "getManifest" property`, + `TypeError: win.browser.runtime is undefined, can't access property "getManifest" of it`, "expected exception received"); let getManifestException = win.testGetManifestException();