Skip to content

Commit

Permalink
Bug 1359397 - Don't allow Selection in nodes not in the document; r=m…
Browse files Browse the repository at this point in the history
…asayuki

This matches the spec and Chrome, and seems to bring us closer to Edge
and WebKit as well.  It also matches our own behavior for addRange(),
which was changed in bug 1341137.

For collapse and selectAllChildren, we match the tests and browsers, but
the spec is incorrect at the time of this writing:
w3c/selection-api#86

The removeAllRanges test hadn't been updated for the spec change.

MozReview-Commit-ID: DTK8283k5IP

UltraBlame original commit: 0bda6393453ef6ca289a37aa723f87f91160c66f
  • Loading branch information
marco-c committed Oct 1, 2019
1 parent 3dfadb5 commit 6980262
Show file tree
Hide file tree
Showing 30 changed files with 271 additions and 1,298,307 deletions.
202 changes: 202 additions & 0 deletions dom/base/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14860,6 +14860,70 @@ selection
return
;
}
if
(
aContainer
.
NodeType
(
)
=
=
nsIDOMNode
:
:
DOCUMENT_TYPE_NODE
)
{
aRv
.
Throw
(
NS_ERROR_DOM_INVALID_NODE_TYPE_ERR
)
;
return
;
}
if
(
aOffset
>
aContainer
.
Length
(
)
)
{
aRv
.
Throw
(
NS_ERROR_DOM_INDEX_SIZE_ERR
)
;
return
;
}
if
(
!
HasSameRoot
(
aContainer
)
)
{
/
/
Return
with
no
error
return
;
}
nsCOMPtr
<
nsINode
Expand Down Expand Up @@ -16938,6 +17002,24 @@ selection
return
;
}
if
(
!
HasSameRoot
(
aContainer
)
)
{
/
/
Return
with
no
error
return
;
}
nsresult
res
;
Expand Down Expand Up @@ -18829,6 +18911,49 @@ aRv
{
if
(
aNode
.
NodeType
(
)
=
=
nsIDOMNode
:
:
DOCUMENT_TYPE_NODE
)
{
aRv
.
Throw
(
NS_ERROR_DOM_INVALID_NODE_TYPE_ERR
)
;
return
;
}
if
(
!
HasSameRoot
(
aNode
)
)
{
/
/
Return
with
no
error
return
;
}
if
(
mFrameSelection
)
{
Expand Down Expand Up @@ -23041,6 +23166,31 @@ mFrameSelection
return
;
}
if
(
!
HasSameRoot
(
aAnchorNode
)
|
|
!
HasSameRoot
(
aFocusNode
)
)
{
/
/
Return
with
no
error
return
;
}
SelectionBatcher
batch
(
Expand Down Expand Up @@ -24341,3 +24491,55 @@ nullptr
)
{
}
bool
Selection
:
:
HasSameRoot
(
nsINode
&
aNode
)
{
nsINode
*
root
=
aNode
.
SubtreeRoot
(
)
;
nsIDocument
*
doc
=
GetParentObject
(
)
;
return
doc
=
=
root
|
|
(
root
&
&
doc
=
=
root
-
>
GetComposedDoc
(
)
)
;
}
24 changes: 24 additions & 0 deletions dom/base/Selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,30 @@ aPoint
;
/
/
We
are
not
allowed
to
be
in
nodes
whose
root
is
not
our
document
bool
HasSameRoot
(
nsINode
&
aNode
)
;
/
/
XXX
Please
don
Expand Down
7 changes: 0 additions & 7 deletions editor/libeditor/tests/test_bug537046.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,6 @@
/
SimpleTest
.
expectAssertions
(
1
)
;
SimpleTest
.
waitForExplicitFinish
(
)
Expand Down
Loading

0 comments on commit 6980262

Please sign in to comment.