Index: third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp |
diff --git a/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp b/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp |
index c61c4fd9a6b425d5b5dad9a559e28296d4db28e3..98aafb77d566ddd548e000794381b109d381336d 100644 |
--- a/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp |
+++ b/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp |
@@ -35,6 +35,7 @@ LoadableTextTrack::LoadableTextTrack(HTMLTrackElement* track) |
: TextTrack(subtitlesKeyword(), emptyAtom, emptyAtom, emptyAtom, TrackElement) |
, m_trackElement(track) |
{ |
+ DCHECK(m_trackElement); |
} |
LoadableTextTrack::~LoadableTextTrack() |
@@ -43,7 +44,6 @@ LoadableTextTrack::~LoadableTextTrack() |
bool LoadableTextTrack::isDefault() const |
{ |
- ASSERT(m_trackElement); |
return m_trackElement->fastHasAttribute(HTMLNames::defaultAttr); |
} |
@@ -62,22 +62,16 @@ void LoadableTextTrack::addRegions(const HeapVector<Member<VTTRegion>>& newRegio |
} |
} |
-size_t LoadableTextTrack::trackElementIndex() |
+size_t LoadableTextTrack::trackElementIndex() const |
{ |
- ASSERT(m_trackElement); |
- ASSERT(m_trackElement->parentNode()); |
- |
+ // Count the number of preceding <track> elements (== the index.) |
size_t index = 0; |
- for (HTMLTrackElement* track = Traversal<HTMLTrackElement>::firstChild(*m_trackElement->parentNode()); track; track = Traversal<HTMLTrackElement>::nextSibling(*track)) { |
- if (!track->parentNode()) |
- continue; |
- if (track == m_trackElement) |
- return index; |
+ for (const HTMLTrackElement* track = Traversal<HTMLTrackElement>::previousSibling(*m_trackElement); |
+ track; |
+ track = Traversal<HTMLTrackElement>::previousSibling(*track)) |
++index; |
- } |
- ASSERT_NOT_REACHED(); |
- return 0; |
+ return index; |
} |
DEFINE_TRACE(LoadableTextTrack) |