Backed out changeset 348a4cebfe89 (bug 1283803)
authorIris Hsiao <ihsiao@mozilla.com>
Tue, 19 Jul 2016 16:34:49 +0800
changeset 305481 37cc0da01187534ea9f8d384c0c9c5c57eb67b56
parent 305480 be05774c859441eace4d4e3a8176a5e637fedaf9
child 305482 96c3ed67980c9160033a3cb35b10f9a4b0107a1e
child 305551 5a91e5b49be3c1ba401b057e90c92d7488e3647d
push id30682
push userihsiao@mozilla.com
push dateTue, 19 Jul 2016 08:35:21 +0000
treeherderautoland@37cc0da01187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1283803
milestone50.0a1
backs out348a4cebfe8900f703c9168b4f21d88bb4f38519
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 348a4cebfe89 (bug 1283803)
dom/media/webvtt/vtt.jsm
testing/web-platform/meta/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/001.html.ini
--- a/dom/media/webvtt/vtt.jsm
+++ b/dom/media/webvtt/vtt.jsm
@@ -1252,52 +1252,16 @@ this.EXPORTED_SYMBOLS = ["WebVTT"];
         }
         if (buffer[pos] === '\n') {
           ++pos;
         }
         self.buffer = buffer.substr(pos);
         return line;
       }
 
-      function createCueIfNeeded() {
-        if (!self.cue) {
-          self.cue = new self.window.VTTCue(0, 0, "");
-        }
-      }
-
-      // Parsing cue identifier and the identifier should be unique.
-      // Return true if the input is a cue identifier.
-      function parseCueIdentifier(input) {
-        if (maybeIsTimeStampFormat(line)) {
-          self.state = "CUE";
-          return false;
-        }
-
-        createCueIfNeeded();
-        // TODO : ensure the cue identifier is unique among all cue identifiers.
-        self.cue.id = containsTimeDirectionSymbol(input) ? "" : input;
-        self.state = "CUE";
-        return true;
-      }
-
-      // Parsing the timestamp and cue settings.
-      // See spec, https://w3c.github.io/webvtt/#collect-webvtt-cue-timings-and-settings
-      function parseCueMayThrow(input) {
-        try {
-          createCueIfNeeded();
-          parseCue(input, self.cue, self.regionList);
-          self.state = "CUETEXT";
-        } catch (e) {
-          self.reportOrThrowError(e);
-          // In case of an error ignore rest of the cue.
-          self.cue = null;
-          self.state = "BADCUE";
-        }
-      }
-
       // 3.4 WebVTT region and WebVTT region settings syntax
       function parseRegion(input) {
         var settings = new Settings();
 
         parseOptions(input, function (k, v) {
           switch (k) {
           case "id":
             settings.set(k, v);
@@ -1376,65 +1340,102 @@ this.EXPORTED_SYMBOLS = ["WebVTT"];
       // 5.1 WebVTT file parsing.
       try {
         if (self.state === "INITIAL") {
           parseSignature();
           self.state = "HEADER";
         }
 
         var line;
-        if (self.state === "HEADER") {
-          line = parseHeader();
-        }
+        var alreadyCollectedLine = false;
+        while (self.buffer) {
+          // We can't parse a line until we have the full line.
+          if (!/\r\n|\n/.test(self.buffer)) {
+            return this;
+          }
 
-        while (self.buffer) {
-          if (!line) {
+          if (!alreadyCollectedLine) {
             line = collectNextLine();
+          } else {
+            alreadyCollectedLine = false;
           }
 
           switch (self.state) {
+          case "HEADER":
+            // 13-18 - Allow a header (metadata) under the WEBVTT line.
+            if (/:/.test(line)) {
+              parseHeader(line);
+            } else if (!line) {
+              // An empty line terminates the header and starts the body (cues).
+              self.state = "ID";
+            }
+            continue;
+          case "NOTE":
+            // Ignore NOTE blocks.
+            if (!line) {
+              self.state = "ID";
+            }
+            continue;
           case "ID":
-            // Ignore NOTE and line terminator
-            if (/^NOTE($|[ \t])/.test(line) || !line) {
+            // Check for the start of NOTE blocks.
+            if (/^NOTE($|[ \t])/.test(line)) {
+              self.state = "NOTE";
               break;
             }
-            // If there is no cue identifier, keep the line and reuse this line
-            // in next iteration.
-            if (!parseCueIdentifier(line)) {
+            // 19-29 - Allow any number of line terminators, then initialize new cue values.
+            if (!line) {
+              continue;
+            }
+            self.cue = new self.window.VTTCue(0, 0, "");
+            self.state = "CUE";
+            // 30-39 - Check if self line contains an optional identifier or timing data.
+            if (line.indexOf("-->") === -1) {
+              self.cue.id = line;
               continue;
             }
-            break;
+            // Process line as start of a cue.
+            /*falls through*/
           case "CUE":
-            parseCueMayThrow(line);
-            break;
+            // 40 - Collect cue timings and settings.
+            try {
+              parseCue(line, self.cue, self.regionList);
+            } catch (e) {
+              self.reportOrThrowError(e);
+              // In case of an error ignore rest of the cue.
+              self.cue = null;
+              self.state = "BADCUE";
+              continue;
+            }
+            self.state = "CUETEXT";
+            continue;
           case "CUETEXT":
-            // Report the cue when (1) get an empty line (2) get the "-->""
-            if (!line || containsTimeDirectionSymbol(line)) {
+            var hasSubstring = line.indexOf("-->") !== -1;
+            // 34 - If we have an empty line then report the cue.
+            // 35 - If we have the special substring '-->' then report the cue,
+            // but do not collect the line as we need to process the current
+            // one as a new cue.
+            if (!line || hasSubstring && (alreadyCollectedLine = true)) {
               // We are done parsing self cue.
               self.oncue && self.oncue(self.cue);
               self.cue = null;
               self.state = "ID";
-              // Keep the line and reuse this line in next iteration.
               continue;
             }
             if (self.cue.text) {
               self.cue.text += "\n";
             }
             self.cue.text += line;
-            break;
+            continue;
           case "BADCUE": // BADCUE
             // 54-62 - Collect and discard the remaining cue.
             if (!line) {
               self.state = "ID";
             }
-            break;
+            continue;
           }
-          // The line was already parsed, empty it to ensure we can get the
-          // new line in next iteration.
-          line = null;
         }
       } catch (e) {
         self.reportOrThrowError(e);
 
         // If we are currently parsing a cue, report what we have.
         if (self.state === "CUETEXT" && self.cue && self.oncue) {
           self.oncue(self.cue);
         }
--- a/testing/web-platform/meta/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/001.html.ini
+++ b/testing/web-platform/meta/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/001.html.ini
@@ -1,4 +1,16 @@
 [001.html]
   type: testharness
   [WebVTT parser tests, nulls.vtt]
+    expected: FAIL
+
+  [WebVTT parser tests, header-timings.vtt]
+    expected: FAIL
+
+  [WebVTT parser tests, header-space.vtt]
+    expected: FAIL
+
+  [WebVTT parser tests, header-tab.vtt]
+    expected: FAIL
+
+  [WebVTT parser tests, arrows.vtt]
     expected: FAIL
\ No newline at end of file