From 6f85622c4f9b88e2131e40a5712c811974012981 Mon Sep 17 00:00:00 2001 From: Butkovits Atila Date: Mon, 3 Mar 2025 21:01:34 +0200 Subject: [PATCH] Backed out changeset 9820dd372dc5 (bug 1951364) for causing failures at browser_misused_characters_in_strings.js. CLOSED TREE --- dom/base/Selection.cpp | 20 +++++++++---------- dom/base/Selection.h | 8 +++++++- dom/locales/en-US/chrome/dom/dom.properties | 3 --- dom/webidl/Selection.webidl | 9 +++++++-- layout/base/AccessibleCaretManager.cpp | 3 ++- .../meta/selection/idlharness.window.js.ini | 3 +++ 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index 1038d55f920b..6d4f450a6fce 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -3967,7 +3967,7 @@ void Selection::DeleteFromDocument(ErrorResult& aRv) { } void Selection::Modify(const nsAString& aAlter, const nsAString& aDirection, - const nsAString& aGranularity) { + const nsAString& aGranularity, ErrorResult& aRv) { if (NeedsToLogSelectionAPI(*this)) { LogSelectionAPI(this, __FUNCTION__, "aAlter", aAlter, "aDirection", aDirection, "aGranularity", aGranularity); @@ -3975,6 +3975,7 @@ void Selection::Modify(const nsAString& aAlter, const nsAString& aDirection, } if (!mFrameSelection) { + aRv.Throw(NS_ERROR_NOT_INITIALIZED); return; } @@ -3984,6 +3985,8 @@ void Selection::Modify(const nsAString& aAlter, const nsAString& aDirection, if (!aAlter.LowerCaseEqualsLiteral("move") && !aAlter.LowerCaseEqualsLiteral("extend")) { + aRv.ThrowSyntaxError( + R"(The first argument must be one of: "move" or "extend")"); return; } @@ -3991,6 +3994,8 @@ void Selection::Modify(const nsAString& aAlter, const nsAString& aDirection, !aDirection.LowerCaseEqualsLiteral("backward") && !aDirection.LowerCaseEqualsLiteral("left") && !aDirection.LowerCaseEqualsLiteral("right")) { + aRv.ThrowSyntaxError( + R"(The direction argument must be one of: "forward", "backward", "left", or "right")"); return; } @@ -4023,17 +4028,11 @@ void Selection::Modify(const nsAString& aAlter, const nsAString& aDirection, aGranularity.LowerCaseEqualsLiteral("paragraph") || aGranularity.LowerCaseEqualsLiteral("paragraphboundary") || aGranularity.LowerCaseEqualsLiteral("documentboundary")) { - Document* document = GetParentObject(); - if (document) { - AutoTArray params; - params.AppendElement(aGranularity); - nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM"_ns, - document, nsContentUtils::eDOM_PROPERTIES, - "SelectionModifyGranualirtyUnsupported", - params); - } + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); return; } else { + aRv.ThrowSyntaxError( + R"(The granularity argument must be one of: "character", "word", "line", or "lineboundary")"); return; } @@ -4045,6 +4044,7 @@ void Selection::Modify(const nsAString& aAlter, const nsAString& aDirection, RefPtr focusNode = GetFocusNode(); // We should have checked earlier that there was a focus node. if (!focusNode) { + aRv.Throw(NS_ERROR_UNEXPECTED); return; } uint32_t focusOffset = FocusOffset(); diff --git a/dom/base/Selection.h b/dom/base/Selection.h index 4107320eaf31..f6ae61d3f396 100644 --- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -546,10 +546,16 @@ class Selection final : public nsSupportsWeakReference, * @param direction can be one of { "forward", "backward", "left", "right" } * @param granularity can be one of { "character", "word", * "line", "lineboundary" } + * + * @throws NS_ERROR_NOT_IMPLEMENTED if the granularity is "sentence", + * "sentenceboundary", "paragraph", "paragraphboundary", or + * "documentboundary". Throws NS_ERROR_INVALID_ARG if alter, direction, + * or granularity has an unrecognized value. */ MOZ_CAN_RUN_SCRIPT void Modify(const nsAString& aAlter, const nsAString& aDirection, - const nsAString& aGranularity); + const nsAString& aGranularity, + mozilla::ErrorResult& aRv); MOZ_CAN_RUN_SCRIPT void SetBaseAndExtentJS(nsINode& aAnchorNode, uint32_t aAnchorOffset, diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index 2da3c04aeed9..0e90fe1ac7c0 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -483,9 +483,6 @@ InvalidNamedFormControlUnfocusable=The invalid form control with name=ā€˜%S’ i # LOCALIZATION NOTE: Do not translate "h1" or "font-size" or "margin". %S is the "more information" url. SectioningH1WithNoFontSizeOrMargins=Found a sectioned h1 element with no specified font-size or margin properties. More information: %S -# LOCALIZATION NOTE: %1$S is the granularity string received as argument by Selection.modify(). -SelectionModifyGranualirtyUnsupported=Granularity "%1$S" is not supported yet for Selection.modify()" - # LOCALIZATION NOTE: Do not translate "afterscriptexecute". AfterScriptExecuteEventWarning=Adding a listener for afterscriptexecute events is deprecated and will be removed soon. # LOCALIZATION NOTE: Do not translate "beforescriptexecute". diff --git a/dom/webidl/Selection.webidl b/dom/webidl/Selection.webidl index 1b0f0a4b6792..259eb07d8c71 100644 --- a/dom/webidl/Selection.webidl +++ b/dom/webidl/Selection.webidl @@ -77,8 +77,6 @@ interface Selection { unsigned long focusOffset); [Throws, BinaryName="selectAllChildrenJS"] undefined selectAllChildren(Node node); - undefined modify(optional DOMString alter = "", optional DOMString direction = "", - optional DOMString granularity = ""); [CEReactions, Throws] undefined deleteFromDocument(); [Throws] @@ -87,6 +85,13 @@ interface Selection { stringifier DOMString (); }; +// Additional methods not currently in the spec +partial interface Selection { + [Throws] + undefined modify(DOMString alter, DOMString direction, + DOMString granularity); +}; + // Additional chrome-only methods. interface nsISelectionListener; partial interface Selection { diff --git a/layout/base/AccessibleCaretManager.cpp b/layout/base/AccessibleCaretManager.cpp index 1bbed0b2a788..54fc3695341a 100644 --- a/layout/base/AccessibleCaretManager.cpp +++ b/layout/base/AccessibleCaretManager.cpp @@ -978,7 +978,8 @@ void AccessibleCaretManager::ExtendPhoneNumberSelection( nsAutoString oldSelectedText = StringifiedSelection(); // Extend the selection by one char. - selection->Modify(u"extend"_ns, aDirection, u"character"_ns); + selection->Modify(u"extend"_ns, aDirection, u"character"_ns, + IgnoreErrors()); if (IsTerminated() == Terminated::Yes) { return; } diff --git a/testing/web-platform/meta/selection/idlharness.window.js.ini b/testing/web-platform/meta/selection/idlharness.window.js.ini index 5ff56e5f98e0..3d1908a6377f 100644 --- a/testing/web-platform/meta/selection/idlharness.window.js.ini +++ b/testing/web-platform/meta/selection/idlharness.window.js.ini @@ -1 +1,4 @@ prefs: [dom.shadowdom.selection_across_boundary.enabled:true] +[idlharness.window.html] + [Selection interface: operation modify(optional DOMString, optional DOMString, optional DOMString)] + expected: FAIL