Backed out changeset 9820dd372dc5 (bug 1951364) for causing failures at browser_misused_characters_in_strings.js. CLOSED TREE

This commit is contained in:
Butkovits Atila
2025-03-03 21:01:34 +02:00
parent 187eb94796
commit 6f85622c4f
6 changed files with 29 additions and 17 deletions

View File

@@ -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<nsString, 1> 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<nsINode> 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();

View File

@@ -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,

View File

@@ -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".

View File

@@ -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 {

View File

@@ -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;
}

View File

@@ -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