forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1847849 - Part 1: Use JSErrorBase::column instead of JSErrorRepor…
…t::tokenOffset in JSErrorToXPCException. r=mccr8,evilpie Differential Revision: https://phabricator.services.mozilla.com/D198508
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* 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() { | ||
// Throwing an error inside a JS callback in xpconnect 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 { | ||
const obs = Cc["@mozilla.org/observer-service;1"] | ||
.getService(Ci.nsIObserverService); | ||
obs.addObserver(test.throwError, "test-obs", false); | ||
obs.notifyObservers(null, "test-obs"); | ||
} catch {} | ||
|
||
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); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters