diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/xpconnect/tests/unit/test_error_to_exception.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect/tests/unit/test_error_to_exception.js')
-rw-r--r-- | js/xpconnect/tests/unit/test_error_to_exception.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/js/xpconnect/tests/unit/test_error_to_exception.js b/js/xpconnect/tests/unit/test_error_to_exception.js new file mode 100644 index 0000000000..1330ecd0ae --- /dev/null +++ b/js/xpconnect/tests/unit/test_error_to_exception.js @@ -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); + } + } +}); |