Bug 1283803 - part3 : rename function parseSignature. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 19 Jul 2016 16:30:54 +0800
changeset 389452 3cbf04dbd22445f0900ce1ae0941ee6bf3f19c9a
parent 389451 5614ff3654265e06ceb68713b28777cf18fe8ed1
child 389453 a3d0814f0b4580b47991bd62610d38d2465b19eb
push id23406
push useralwu@mozilla.com
push dateTue, 19 Jul 2016 09:08:14 +0000
bugs1283803
milestone50.0a1
Bug 1283803 - part3 : rename function parseSignature. MozReview-Commit-ID: ImBH5Xq4sJX
dom/media/webvtt/vtt.jsm
--- a/dom/media/webvtt/vtt.jsm
+++ b/dom/media/webvtt/vtt.jsm
@@ -1360,21 +1360,24 @@ this.EXPORTED_SYMBOLS = ["WebVTT"];
           // reference it.
           self.regionList.push({
             id: settings.get("id"),
             region: region
           });
         }
       }
 
-      // WebVTT parser algorithm step1 - step9.
-      function parseSignature(input) {
+      // Parsing the WebVTT signature, it contains parsing algo step1 to step9.
+      // See spec, https://w3c.github.io/webvtt/#file-parsing
+      function parseSignatureMayThrow(input) {
         let signature = collectNextLine();
         if (!/^WEBVTT([ \t].*)?$/.test(signature)) {
           throw new ParsingError(ParsingError.Errors.BadSignature);
+        } else {
+          self.state = "HEADER";
         }
       }
 
       // Parsing the region and style information.
       // See spec, https://w3c.github.io/webvtt/#collect-a-webvtt-block
       //
       // There are sereval things would appear in header,
       //   1. Region or Style setting
@@ -1417,18 +1420,17 @@ this.EXPORTED_SYMBOLS = ["WebVTT"];
           line = null
         }
         return line;
       }
 
       // 5.1 WebVTT file parsing.
       try {
         if (self.state === "INITIAL") {
-          parseSignature();
-          self.state = "HEADER";
+          parseSignatureMayThrow();
         }
 
         var line;
         if (self.state === "HEADER") {
           line = parseHeader();
         }
 
         while (self.buffer) {