tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 2b92c4f86d82faa200e4e6f7e7f04f08302b7f67
parent 88016633b31bbc3fa5e7c1b17dcf27fc961a3496
Author: Zijie Zhao <zijie4@illinois.edu>
Date:   Thu, 30 Oct 2025 22:55:14 +0000

Bug 1997216 - Fix Exception::ColumnNumber to return actual column number. r=arai,emilio

Differential Revision: https://phabricator.services.mozilla.com/D270636

Diffstat:
Mdom/base/DOMException.cpp | 8+++++++-
Mdom/base/DOMException.h | 2+-
Mdom/bindings/Bindings.conf | 4++--
Mdom/bindings/test/mochitest.toml | 2++
Adom/bindings/test/test_exception_line_column.html | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Mjs/xpconnect/src/ExecutionTracerIntegration.cpp | 2+-
Mjs/xpconnect/src/nsXPConnect.cpp | 2+-
7 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/dom/base/DOMException.cpp b/dom/base/DOMException.cpp @@ -289,7 +289,13 @@ uint32_t Exception::LineNumber(JSContext* aCx) const { return 0; } -uint32_t Exception::ColumnNumber() const { return 0; } +uint32_t Exception::ColumnNumber(JSContext* aCx) const { + if (mLocation) { + return mLocation->GetColumnNumber(aCx); + } + + return 0; +} already_AddRefed<nsIStackFrame> Exception::GetLocation() const { nsCOMPtr<nsIStackFrame> location = mLocation; diff --git a/dom/base/DOMException.h b/dom/base/DOMException.h @@ -89,7 +89,7 @@ class Exception : public nsIException, public nsWrapperCache { uint32_t LineNumber(JSContext* aCx) const; - uint32_t ColumnNumber() const; + uint32_t ColumnNumber(JSContext* aCx) const; already_AddRefed<nsIStackFrame> GetLocation() const; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf @@ -219,7 +219,7 @@ DOMInterfaces = { }, 'DOMException': { - 'implicitJSContext': [ 'filename', 'lineNumber', 'stack' ], + 'implicitJSContext': [ 'filename', 'lineNumber', 'columnNumber', 'stack' ], }, 'DOMMatrixReadOnly': { @@ -260,7 +260,7 @@ DOMInterfaces = { 'Exception': { 'headerFile': 'mozilla/dom/DOMException.h', - 'implicitJSContext': [ '__stringifier', 'filename', 'lineNumber', 'stack' ], + 'implicitJSContext': [ '__stringifier', 'filename', 'lineNumber', 'columnNumber', 'stack' ], }, 'ExtendableEvent': { diff --git a/dom/bindings/test/mochitest.toml b/dom/bindings/test/mochitest.toml @@ -96,6 +96,8 @@ skip-if = ["!debug"] ["test_exceptionThrowing.html"] +["test_exception_line_column.html"] + ["test_exception_messages.html"] ["test_exception_options_from_jsimplemented.html"] diff --git a/dom/bindings/test/test_exception_line_column.html b/dom/bindings/test/test_exception_line_column.html @@ -0,0 +1,52 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1997216 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1997216</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript"> + + /** Test for Bug 1997216 */ + + // Test 1: DOMException from querySelector + try { + document.querySelector('###INVALID_SELECTOR###'); + ok(false, "Should have thrown"); + } catch (e) { + is(e.lineNumber, 17, "querySelector exception should be on line 17"); + is(e.columnNumber, 14, "querySelector exception should be on column 14"); + } + + // Test 2: Manually created DOMException + try { + throw new DOMException('Test exception', 'NotFoundError'); + } catch (e) { + is(e.lineNumber, 26, "Manual DOMException should be on line 26"); + is(e.columnNumber, 11, "Manual DOMException should be on column 11"); + } + + // Test 3: DOMException from invalid appendChild + try { + document.documentElement.appendChild(null); + ok(false, "Should have thrown"); + } catch (e) { + is(e.lineNumber, 35, "appendChild exception should be on line 35"); + is(e.columnNumber, 30, "appendChild exception should be on column 30"); + } + + </script> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1997216">Mozilla Bug 1997216</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +</pre> +</body> +</html> diff --git a/js/xpconnect/src/ExecutionTracerIntegration.cpp b/js/xpconnect/src/ExecutionTracerIntegration.cpp @@ -168,7 +168,7 @@ bool ExecutionTracerIntegration::WriteExceptionSummary( uint32_t line = exception->LineNumber(aCx); aWriter->writeUint32(line); - uint32_t column = exception->ColumnNumber(); + uint32_t column = exception->ColumnNumber(aCx); aWriter->writeUint32(column); nsCOMPtr<nsIStackFrame> stack = exception->GetLocation(); diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp @@ -253,7 +253,7 @@ void xpc::ErrorReport::Init(JSContext* aCx, mozilla::dom::Exception* aException, } mSourceId = aException->SourceId(aCx); mLineNumber = aException->LineNumber(aCx); - mColumn = aException->ColumnNumber(); + mColumn = aException->ColumnNumber(aCx); } static LazyLogModule gJSDiagnostics("JSDiagnostics");