forked from mirrors/gecko-dev
Bug 1847849 - Part 2: Use JSErrorBase::column instead of JSErrorReport::tokenOffset in nsXPCComponents_Utils::ReportError. r=mccr8,evilpie
Differential Revision: https://phabricator.services.mozilla.com/D198509
This commit is contained in:
parent
e118de53e5
commit
71a0ccd946
3 changed files with 61 additions and 3 deletions
|
|
@ -1412,8 +1412,6 @@ nsXPCComponents_Utils::ReportError(HandleValue error, HandleValue stack,
|
|||
nsAutoString fileUni;
|
||||
CopyUTF8toUTF16(mozilla::MakeStringSpan(err->filename.c_str()), fileUni);
|
||||
|
||||
uint32_t column = err->tokenOffset();
|
||||
|
||||
const char16_t* linebuf = err->linebuf();
|
||||
uint32_t flags = err->isWarning() ? nsIScriptError::warningFlag
|
||||
: nsIScriptError::errorFlag;
|
||||
|
|
@ -1424,7 +1422,8 @@ nsXPCComponents_Utils::ReportError(HandleValue error, HandleValue stack,
|
|||
fileUni,
|
||||
linebuf ? nsDependentString(linebuf, err->linebufLength())
|
||||
: EmptyString(),
|
||||
err->lineno, column, flags, "XPConnect JavaScript", innerWindowID,
|
||||
err->lineno, err->column.oneOriginValue(), flags,
|
||||
"XPConnect JavaScript", innerWindowID,
|
||||
innerWindowID == 0 ? true : false);
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
|
||||
|
|
|
|||
57
js/xpconnect/tests/unit/test_Cu_reportError_column.js
Normal file
57
js/xpconnect/tests/unit/test_Cu_reportError_column.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
add_task(async function() {
|
||||
// Passing an Error with JSErrorReport to Cu.reportError should preserve
|
||||
// the columnNumber.
|
||||
|
||||
const tests = [
|
||||
// Parser error.
|
||||
{
|
||||
throwError() {
|
||||
eval("a b");
|
||||
},
|
||||
messagePattern: /unexpected token/,
|
||||
lineNumber: 1,
|
||||
columnNumber: 3,
|
||||
},
|
||||
// Runtime error.
|
||||
{
|
||||
throwError() { // line = 21
|
||||
not_found();
|
||||
},
|
||||
messagePattern: /is not defined/,
|
||||
lineNumber: 22,
|
||||
columnNumber: 9,
|
||||
},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
const listener = {
|
||||
observe(msg) {
|
||||
if (msg instanceof Ci.nsIScriptError) {
|
||||
resolve(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
Services.console.registerListener(listener);
|
||||
|
||||
try {
|
||||
test.throwError();
|
||||
} catch (e) {
|
||||
Cu.reportError(e);
|
||||
}
|
||||
|
||||
const msg = await promise;
|
||||
Assert.stringMatches(msg.errorMessage, test.messagePattern);
|
||||
Assert.equal(msg.lineNumber, test.lineNumber);
|
||||
Assert.equal(msg.columnNumber, test.columnNumber);
|
||||
} finally {
|
||||
Services.console.unregisterListener(listener);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -70,6 +70,8 @@ support-files = [
|
|||
|
||||
["test_ComponentEnvironment.js"]
|
||||
|
||||
["test_Cu_reportError_column.js"]
|
||||
|
||||
["test_FrameScriptEnvironment.js"]
|
||||
|
||||
["test_ReadableStream_from.js"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue