From 64df8fc389d2204850c0d10209d39ab8644cb5e6 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Tue, 8 Mar 2022 09:58:40 +0800 Subject: [PATCH] use goog.module --- build/generateExterns.js | 3 ++- lib/abr/ewma.js | 11 ++++++----- lib/abr/ewma_bandwidth_estimator.js | 15 ++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/build/generateExterns.js b/build/generateExterns.js index 5460180e0a1..66c808c6fa6 100755 --- a/build/generateExterns.js +++ b/build/generateExterns.js @@ -39,6 +39,7 @@ if (assert.strict) { const esprima = require('esprima'); const fs = require('fs'); +const googModule = ['goog.module', 'goog.provide']; // The annotations we will consider "exporting" a symbol. const EXPORT_REGEX = /@(?:export|exportInterface|expose)\b/; @@ -127,7 +128,7 @@ function dumpNode(node) { */ function isProvideNode(node) { return isCallNode(node) && - getIdentifierString(node.expression.callee) == 'goog.provide'; + googModule.includes(getIdentifierString(node.expression.callee)); } diff --git a/lib/abr/ewma.js b/lib/abr/ewma.js index 0689cfb8959..10245f4d99d 100644 --- a/lib/abr/ewma.js +++ b/lib/abr/ewma.js @@ -4,23 +4,24 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.provide('shaka.abr.Ewma'); +goog.module('shaka.abr.Ewma'); +goog.module.declareLegacyNamespace(); -goog.require('goog.asserts'); +const {assert} = goog.require('goog.asserts'); /** * @summary * This class computes an exponentionally-weighted moving average. */ -shaka.abr.Ewma = class { +exports = class Ewma { /** * @param {number} halfLife The quantity of prior samples (by weight) used * when creating a new estimate. Those prior samples make up half of the * new estimate. */ constructor(halfLife) { - goog.asserts.assert(halfLife > 0, 'expected halfLife to be positive'); + assert(halfLife > 0, 'expected halfLife to be positive'); /** * Larger values of alpha expire historical data more slowly. @@ -44,7 +45,7 @@ shaka.abr.Ewma = class { * new estimate. */ updateAlpha(halfLife) { - goog.asserts.assert(halfLife > 0, 'expected halfLife to be positive'); + assert(halfLife > 0, 'expected halfLife to be positive'); this.alpha_ = Math.exp(Math.log(0.5) / halfLife); } diff --git a/lib/abr/ewma_bandwidth_estimator.js b/lib/abr/ewma_bandwidth_estimator.js index 88ac9411726..7f771dab6e1 100644 --- a/lib/abr/ewma_bandwidth_estimator.js +++ b/lib/abr/ewma_bandwidth_estimator.js @@ -4,9 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.provide('shaka.abr.EwmaBandwidthEstimator'); +goog.module('shaka.abr.EwmaBandwidthEstimator'); +goog.module.declareLegacyNamespace(); -goog.require('shaka.abr.Ewma'); +const Ewma = goog.require('shaka.abr.Ewma'); /** @@ -16,22 +17,22 @@ goog.require('shaka.abr.Ewma'); * different half-lives. * */ -shaka.abr.EwmaBandwidthEstimator = class { +exports = class EwmaBandwidthEstimator { /** */ constructor() { /** * A fast-moving average. * Half of the estimate is based on the last 2 seconds of sample history. - * @private {!shaka.abr.Ewma} + * @private {!Ewma} */ - this.fast_ = new shaka.abr.Ewma(2); + this.fast_ = new Ewma(2); /** * A slow-moving average. * Half of the estimate is based on the last 5 seconds of sample history. - * @private {!shaka.abr.Ewma} + * @private {!Ewma} */ - this.slow_ = new shaka.abr.Ewma(5); + this.slow_ = new Ewma(5); /** * Number of bytes sampled.