Commit 8a11f123 authored by Mirko Brodesser's avatar Mirko Brodesser
Browse files

Bug 1623333: part 1) Throw error in Selection's webidl methods, when there's...

Bug 1623333: part 1) Throw error in Selection's webidl methods, when there's no `nsFrameSelection` instance. r=smaug

Alleviates the possibility to add calls which are unintentionally no-ops.

In practice, these errors should never be propagated to the web, and
signal to other callers (for copy&paste) that the calls are wrong.
Ideally, the other callers wouldn't see these methods, but that requires
a larger refactoring.

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

--HG--
extra : moz-landing-system : lando
parent 61cf3f6e
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -1793,7 +1793,11 @@ nsresult Selection::DoAutoScroll(nsIFrame* aFrame, nsPoint aPoint) {
}

void Selection::RemoveAllRanges(ErrorResult& aRv) {
  if (!mFrameSelection) return;  // nothing to do
  if (!mFrameSelection) {
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
    return;
  }

  RefPtr<nsPresContext> presContext = GetPresContext();
  nsresult result = Clear(presContext);
  if (NS_FAILED(result)) {
@@ -2882,7 +2886,7 @@ nsresult Selection::ScrollIntoView(SelectionRegion aRegion,
                                   ScrollAxis aVertical, ScrollAxis aHorizontal,
                                   int32_t aFlags) {
  if (!mFrameSelection) {
    return NS_OK;
    return NS_ERROR_NOT_INITIALIZED;
  }

  RefPtr<PresShell> presShell = mFrameSelection->GetPresShell();
@@ -3149,8 +3153,12 @@ void Selection::DeleteFromDocument(ErrorResult& aRv) {

void Selection::Modify(const nsAString& aAlter, const nsAString& aDirection,
                       const nsAString& aGranularity, ErrorResult& aRv) {
  // Silently exit if there's no selection or no focus node.
  if (!mFrameSelection || !GetAnchorFocusRange() || !GetFocusNode()) {
  if (!mFrameSelection) {
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
    return;
  }

  if (!GetAnchorFocusRange() || !GetFocusNode()) {
    return;
  }

@@ -3277,6 +3285,7 @@ void Selection::SetBaseAndExtentInternal(InLimiter aInLimiter,
                                         const RawRangeBoundary& aFocusRef,
                                         ErrorResult& aRv) {
  if (!mFrameSelection) {
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
    return;
  }

@@ -3368,7 +3377,9 @@ void Selection::SetStartAndEndInternal(InLimiter aInLimiter,
 * new language is left-to-right
 */
nsresult Selection::SelectionLanguageChange(bool aLangRTL) {
  if (!mFrameSelection) return NS_ERROR_NOT_INITIALIZED;  // Can't do selection
  if (!mFrameSelection) {
    return NS_ERROR_NOT_INITIALIZED;
  }

  RefPtr<nsFrameSelection> frameSelection = mFrameSelection;