Files
shaka-player/lib/util/xml_utils.js
T
Joey Parrish 78e996d090 Fix issues found by the newest Closure compiler
Fixes the following issues:
=====

lib/player.js:106: ERROR - Property id never defined on TextTrack

lib/util/xml_utils.js:42: ERROR - inconsistent return type
found   : (Node|null)
required: (Element|null)

lib/dash/content_protection.js:256: ERROR - Parameter must have JSDoc.
      function(element) {

lib/dash/content_protection.js:284: ERROR - Parameter must have JSDoc.
      function(elem) {

lib/media/drm_engine.js:47: ERROR - Private property configuration_ is never read

lib/polyfill/patchedmediakeys_20140218.js:269: ERROR - Private property keySystem_ is never read

lib/polyfill/patchedmediakeys_20140218.js:389: ERROR - Private property type_ is never read

lib/util/language_utils.js:84: ERROR - The value 0.0 is duplicated in this enum.
  MIN: 0, MAX: 2

lib/util/language_utils.js:84: ERROR - The value 2.0 is duplicated in this enum.
  MIN: 0, MAX: 2

demo/assets.js:171: ERROR - Value assigned to local variable headers is never read

lib/dash/content_protection.js:188: ERROR - Value assigned to local variable repUnknown is never read

lib/dash/dash_parser.js:400: ERROR - Value assigned to local variable suggestedDelay is never read

lib/dash/segment_base.js:41: ERROR - Value assigned to local variable SegmentBase is never read

lib/dash/segment_template.js:291: ERROR - Value assigned to local variable periodStart is never read

lib/media/drm_engine.js:172: ERROR - Value assigned to local variable onEncrypted is never read

test/dash_parser_live_unit.js:358: ERROR - Value assigned to local variable manifest is never read

test/drm_engine_unit.js:383: ERROR - Value assigned to local variable cert1 is never read

test/drm_engine_unit.js:384: ERROR - Value assigned to local variable cert2 is never read

test/media_source_engine_unit.js:24: ERROR - Value assigned to local variable dummyData is never read

test/media_source_engine_unit.js:504: ERROR - Value assigned to local variable p2 is never read

test/media_source_engine_unit.js:505: ERROR - Value assigned to local variable p3 is never read

test/media_source_engine_unit.js:506: ERROR - Value assigned to local variable p4 is never read

test/media_source_engine_unit.js:535: ERROR - Value assigned to local variable p2 is never read

test/media_source_engine_unit.js:601: ERROR - Value assigned to local variable p2 is never read

test/media_source_engine_unit.js:602: ERROR - Value assigned to local variable p3 is never read

test/media_source_engine_unit.js:603: ERROR - Value assigned to local variable p4 is never read

test/media_source_engine_unit.js:632: ERROR - Value assigned to local variable p2 is never read

test/mpd_utils_unit.js:20: ERROR - Value assigned to local variable HUGE_NUMBER_STRING is never read

test/streaming_engine_integration.js:55: ERROR - Value assigned to local variable onSeek is never read

test/streaming_engine_unit.js:1263: ERROR - Value assigned to local variable reportedContentType is never read

test/streaming_engine_unit.js:1264: ERROR - Value assigned to local variable reportedPeriodIndex is never read

test/streaming_engine_unit.js:1540: ERROR - Value assigned to local variable size is never read

test/util/dash_parser_util.js:77: ERROR - Value assigned to local variable retry is never read

test/util/dash_parser_util.js💯 ERROR - Value assigned to local variable retry is never read

test/vtt_text_parser_unit.js:272: ERROR - Value assigned to local variable result is never read

Change-Id: I707700250541e04ccbfe81d7298b3f0c5a82dcdc
2016-03-03 16:04:58 -08:00

236 lines
6.7 KiB
JavaScript

/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
goog.provide('shaka.util.XmlUtils');
goog.require('shaka.asserts');
goog.require('shaka.log');
/**
* Finds a child XML element.
* @param {!Element} elem The parent XML element.
* @param {string} name The child XML element's tag name.
* @return {Element} The child XML element, or null if a child XML element does
* not exist with the given tag name OR if there exists more than one
* child XML element with the given tag name.
*/
shaka.util.XmlUtils.findChild = function(elem, name) {
var childElement = null;
for (var i = 0; i < elem.childNodes.length; i++) {
if (elem.childNodes[i].tagName != name)
continue;
if (childElement)
return null;
childElement = elem.childNodes[i];
}
shaka.asserts.assert(!childElement || childElement instanceof Element,
'child element should be an Element');
return /** @type {Element} */(childElement);
};
/**
* Finds child XML elements.
* @param {!Element} elem The parent XML element.
* @param {string} name The child XML element's tag name.
* @return {!Array.<!Element>} The child XML elements.
*/
shaka.util.XmlUtils.findChildren = function(elem, name) {
var childElements = [];
for (var i = 0; i < elem.childNodes.length; i++) {
if (elem.childNodes[i].tagName == name)
childElements.push(elem.childNodes[i]);
}
return childElements;
};
/**
* Gets the text contents of a node.
* @param {!Element} elem The XML element.
* @return {?string} The text contents, or null if there are none.
*/
shaka.util.XmlUtils.getContents = function(elem) {
var contents = elem.firstChild;
if (!contents || contents.nodeType != Node.TEXT_NODE)
return null;
return contents.nodeValue.trim();
};
/**
* Parses an attribute by its name.
* @param {!Element} elem The XML element.
* @param {string} name The attribute name.
* @param {function(string): (T|null)} parseFunction A function that parses
* the attribute.
* @param {(T|null)=} opt_defaultValue The attribute's default value, if not
* specified, the attibute's default value is null.
* @return {(T|null)} The parsed attribute on success, or the attribute's
* default value if the attribute does not exist or could not be parsed.
* @template T
*/
shaka.util.XmlUtils.parseAttr = function(
elem, name, parseFunction, opt_defaultValue) {
var parsedValue = null;
var value = elem.getAttribute(name);
if (value != null)
parsedValue = parseFunction(value);
if (parsedValue == null)
return opt_defaultValue !== undefined ? opt_defaultValue : null;
return parsedValue;
};
/**
* Parses an XML date string.
* @param {string} dateString
* @return {?number} The parsed date in seconds on success; otherwise, return
* null.
*/
shaka.util.XmlUtils.parseDate = function(dateString) {
if (!dateString)
return null;
var result = Date.parse(dateString);
return (!isNaN(result) ? Math.floor(result / 1000.0) : null);
};
/**
* Parses an XML duration string.
* Negative values are not supported. Years and months are treated as exactly
* 365 and 30 days respectively.
* @param {string} durationString The duration string, e.g., "PT1H3M43.2S",
* which means 1 hour, 3 minutes, and 43.2 seconds.
* @return {?number} The parsed duration in seconds on success; otherwise,
* return null.
* @see {@link http://www.datypic.com/sc/xsd/t-xsd_duration.html}
*/
shaka.util.XmlUtils.parseDuration = function(durationString) {
if (!durationString)
return null;
var re = '^P(?:([0-9]*)Y)?(?:([0-9]*)M)?(?:([0-9]*)D)?' +
'(?:T(?:([0-9]*)H)?(?:([0-9]*)M)?(?:([0-9.]*)S)?)?$';
var matches = new RegExp(re).exec(durationString);
if (!matches) {
shaka.log.warning('Invalid duration string:', durationString);
return null;
}
// Note: Number(null) == 0 but Number(undefined) == NaN.
var years = Number(matches[1] || null);
var months = Number(matches[2] || null);
var days = Number(matches[3] || null);
var hours = Number(matches[4] || null);
var minutes = Number(matches[5] || null);
var seconds = Number(matches[6] || null);
// Assume a year always has 365 days and a month always has 30 days.
var d = (60 * 60 * 24 * 365) * years +
(60 * 60 * 24 * 30) * months +
(60 * 60 * 24) * days +
(60 * 60) * hours +
60 * minutes +
seconds;
return isFinite(d) ? d : null;
};
/**
* Parses a range string.
* @param {string} rangeString The range string, e.g., "101-9213".
* @return {?{start: number, end: number}} The parsed range on success;
* otherwise, return null.
*/
shaka.util.XmlUtils.parseRange = function(rangeString) {
var matches = /([0-9]+)-([0-9]+)/.exec(rangeString);
if (!matches)
return null;
var start = Number(matches[1]);
if (!isFinite(start))
return null;
var end = Number(matches[2]);
if (!isFinite(end))
return null;
return {start: start, end: end};
};
/**
* Parses an integer.
* @param {string} intString The integer string.
* @return {?number} The parsed integer on success; otherwise, return null.
*/
shaka.util.XmlUtils.parseInt = function(intString) {
var n = Number(intString);
return (n % 1 === 0) ? n : null;
};
/**
* Parses a positive integer.
* @param {string} intString The integer string.
* @return {?number} The parsed positive integer on success; otherwise,
* return null.
*/
shaka.util.XmlUtils.parsePositiveInt = function(intString) {
var n = Number(intString);
return (n % 1 === 0) && (n > 0) ? n : null;
};
/**
* Parses a non-negative integer.
* @param {string} intString The integer string.
* @return {?number} The parsed non-negative integer on success; otherwise,
* return null.
*/
shaka.util.XmlUtils.parseNonNegativeInt = function(intString) {
var n = Number(intString);
return (n % 1 === 0) && (n >= 0) ? n : null;
};
/**
* Parses a floating point number.
* @param {string} floatString The floating point number string.
* @return {?number} The parsed floating point number on success; otherwise,
* return null. May return NEGATIVE_INFINITY or POSITIVE_INFINITY.
*/
shaka.util.XmlUtils.parseFloat = function(floatString) {
var n = Number(floatString);
return !isNaN(n) ? n : null;
};