RESOLVED FIXED 208114
Refactor TextTrackCue to use more traditional design patterns
https://bugs.webkit.org/show_bug.cgi?id=208114
Summary Refactor TextTrackCue to use more traditional design patterns
Darin Adler
Reported 2020-02-23 14:55:18 PST
Refactor TextTrackCue to use more traditional design patterns
Attachments
Patch (65.65 KB, patch)
2020-02-23 16:00 PST, Darin Adler
no flags
Patch (63.87 KB, patch)
2020-02-24 22:19 PST, Darin Adler
achristensen: review+
Darin Adler
Comment 1 2020-02-23 16:00:57 PST
Darin Adler
Comment 2 2020-02-24 22:10:15 PST
Wow, tests are failing because the special value of "-1" to mean invalid is apparently web-facing behavior! Who would have thought? I guess I will revert that part of the patch.
Darin Adler
Comment 3 2020-02-24 22:19:19 PST
Alex Christensen
Comment 4 2020-02-24 22:25:25 PST
Comment on attachment 391624 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=391624&action=review r=me, assuming this passes EWS. > Source/WebCore/html/track/TextTrackCueGeneric.cpp:159 > + return adoptRef(*new TextTrackCueGeneric(downcast<Document>(context), start, end, content)); How do we know this is a Document? > Source/WebCore/html/track/TextTrackCueGeneric.cpp:236 > + std::pair<double, double> thisPosition = getPositionCoordinates(); > + std::pair<double, double> thatPosition = downcast<TextTrackCueGeneric>(*that).getPositionCoordinates(); This looks like a good place for auto, FloatPoint, or structured bindings. > Source/WebCore/html/track/VTTCue.h:141 > enum WritingDirection { It would be nice to make these enum classes, but that kind of thing can explode the patch. > Source/WebCore/html/track/VTTCue.h:149 > enum CueAlignment { ditto.
Darin Adler
Comment 5 2020-02-24 22:55:05 PST
Comment on attachment 391624 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=391624&action=review >> Source/WebCore/html/track/TextTrackCueGeneric.cpp:159 >> + return adoptRef(*new TextTrackCueGeneric(downcast<Document>(context), start, end, content)); > > How do we know this is a Document? The practical answer to this is that this is derived from TextTrackCue, and the TextTrackCue constructor has this line of code in it: ASSERT(m_scriptExecutionContext.isDocument()); The more abstract answer is that these classes can only be used inside documents, not in workers, and ideally our DOM bindings would know that and pass a Document rather than a ScriptExecutionContext to all the create functions and such. Really all this ScriptExecutionContext when we know this is a Document is messy and worth cleaning up. Among other things the type name "Document" is much, much shorter. >> Source/WebCore/html/track/TextTrackCueGeneric.cpp:236 >> + std::pair<double, double> thatPosition = downcast<TextTrackCueGeneric>(*that).getPositionCoordinates(); > > This looks like a good place for auto, FloatPoint, or structured bindings. Not the kind of thing I was tempted to touch. Of those three, I think I’d go for auto, though. Related: too bad that the line below is not *quite* std::pair's > or < operator; it’s a mix of both. >> Source/WebCore/html/track/VTTCue.h:141 >> enum WritingDirection { > > It would be nice to make these enum classes, but that kind of thing can explode the patch. Agreed.
Darin Adler
Comment 6 2020-02-24 22:57:26 PST
Comment on attachment 391624 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=391624&action=review >>> Source/WebCore/html/track/TextTrackCueGeneric.cpp:159 >>> + return adoptRef(*new TextTrackCueGeneric(downcast<Document>(context), start, end, content)); >> >> How do we know this is a Document? > > The practical answer to this is that this is derived from TextTrackCue, and the TextTrackCue constructor has this line of code in it: > > ASSERT(m_scriptExecutionContext.isDocument()); > > The more abstract answer is that these classes can only be used inside documents, not in workers, and ideally our DOM bindings would know that and pass a Document rather than a ScriptExecutionContext to all the create functions and such. Really all this ScriptExecutionContext when we know this is a Document is messy and worth cleaning up. Among other things the type name "Document" is much, much shorter. Looks like I can change ConstructorCallWith=ScriptExecutionContext to ConstructorCallWith=Document and fix part of the messiness that way.
Darin Adler
Comment 7 2020-02-24 23:25:20 PST
Radar WebKit Bug Importer
Comment 8 2020-02-24 23:26:16 PST
Note You need to log in before you can comment on or make changes to this bug.