// Copyright 2006 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Bootstrap for the Google JS Library (Closure).16*17* In uncompiled mode base.js will attempt to load Closure's deps file, unless18* the global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects19* to include their own deps file(s) from different locations.20*21* Avoid including base.js more than once. This is strictly discouraged and not22* supported. goog.require(...) won't work properly in that case.23*24* @provideGoog25*/262728/**29* @define {boolean} Overridden to true by the compiler.30*/31var COMPILED = false;323334/**35* Base namespace for the Closure library. Checks to see goog is already36* defined in the current scope before assigning to prevent clobbering if37* base.js is loaded more than once.38*39* @const40*/41var goog = goog || {};424344/**45* Reference to the global context. In most cases this will be 'window'.46*/47goog.global = this;484950/**51* A hook for overriding the define values in uncompiled mode.52*53* In uncompiled mode, {@code CLOSURE_UNCOMPILED_DEFINES} may be defined before54* loading base.js. If a key is defined in {@code CLOSURE_UNCOMPILED_DEFINES},55* {@code goog.define} will use the value instead of the default value. This56* allows flags to be overwritten without compilation (this is normally57* accomplished with the compiler's "define" flag).58*59* Example:60* <pre>61* var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false};62* </pre>63*64* @type {Object<string, (string|number|boolean)>|undefined}65*/66goog.global.CLOSURE_UNCOMPILED_DEFINES;676869/**70* A hook for overriding the define values in uncompiled or compiled mode,71* like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In72* uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence.73*74* Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or75* string literals or the compiler will emit an error.76*77* While any @define value may be set, only those set with goog.define will be78* effective for uncompiled code.79*80* Example:81* <pre>82* var CLOSURE_DEFINES = {'goog.DEBUG': false} ;83* </pre>84*85* @type {Object<string, (string|number|boolean)>|undefined}86*/87goog.global.CLOSURE_DEFINES;888990/**91* Returns true if the specified value is not undefined.92*93* @param {?} val Variable to test.94* @return {boolean} Whether variable is defined.95*/96goog.isDef = function(val) {97// void 0 always evaluates to undefined and hence we do not need to depend on98// the definition of the global variable named 'undefined'.99return val !== void 0;100};101102/**103* Returns true if the specified value is a string.104* @param {?} val Variable to test.105* @return {boolean} Whether variable is a string.106*/107goog.isString = function(val) {108return typeof val == 'string';109};110111112/**113* Returns true if the specified value is a boolean.114* @param {?} val Variable to test.115* @return {boolean} Whether variable is boolean.116*/117goog.isBoolean = function(val) {118return typeof val == 'boolean';119};120121122/**123* Returns true if the specified value is a number.124* @param {?} val Variable to test.125* @return {boolean} Whether variable is a number.126*/127goog.isNumber = function(val) {128return typeof val == 'number';129};130131132/**133* Builds an object structure for the provided namespace path, ensuring that134* names that already exist are not overwritten. For example:135* "a.b.c" -> a = {};a.b={};a.b.c={};136* Used by goog.provide and goog.exportSymbol.137* @param {string} name name of the object that this file defines.138* @param {*=} opt_object the object to expose at the end of the path.139* @param {Object=} opt_objectToExportTo The object to add the path to; default140* is `goog.global`.141* @private142*/143goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) {144var parts = name.split('.');145var cur = opt_objectToExportTo || goog.global;146147// Internet Explorer exhibits strange behavior when throwing errors from148// methods externed in this manner. See the testExportSymbolExceptions in149// base_test.html for an example.150if (!(parts[0] in cur) && cur.execScript) {151cur.execScript('var ' + parts[0]);152}153154for (var part; parts.length && (part = parts.shift());) {155if (!parts.length && goog.isDef(opt_object)) {156// last part and we have an object; use it157cur[part] = opt_object;158} else if (cur[part] && cur[part] !== Object.prototype[part]) {159cur = cur[part];160} else {161cur = cur[part] = {};162}163}164};165166167/**168* Defines a named value. In uncompiled mode, the value is retrieved from169* CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and170* has the property specified, and otherwise used the defined defaultValue.171* When compiled the default can be overridden using the compiler172* options or the value set in the CLOSURE_DEFINES object.173*174* @param {string} name The distinguished name to provide.175* @param {string|number|boolean} defaultValue176*/177goog.define = function(name, defaultValue) {178var value = defaultValue;179if (!COMPILED) {180if (goog.global.CLOSURE_UNCOMPILED_DEFINES &&181// Anti DOM-clobbering runtime check (b/37736576).182/** @type {?} */ (goog.global.CLOSURE_UNCOMPILED_DEFINES).nodeType ===183undefined &&184Object.prototype.hasOwnProperty.call(185goog.global.CLOSURE_UNCOMPILED_DEFINES, name)) {186value = goog.global.CLOSURE_UNCOMPILED_DEFINES[name];187} else if (188goog.global.CLOSURE_DEFINES &&189// Anti DOM-clobbering runtime check (b/37736576).190/** @type {?} */ (goog.global.CLOSURE_DEFINES).nodeType === undefined &&191Object.prototype.hasOwnProperty.call(192goog.global.CLOSURE_DEFINES, name)) {193value = goog.global.CLOSURE_DEFINES[name];194}195}196goog.exportPath_(name, value);197};198199200/**201* @define {boolean} DEBUG is provided as a convenience so that debugging code202* that should not be included in a production. It can be easily stripped203* by specifying --define goog.DEBUG=false to the Closure Compiler aka204* JSCompiler. For example, most toString() methods should be declared inside an205* "if (goog.DEBUG)" conditional because they are generally used for debugging206* purposes and it is difficult for the JSCompiler to statically determine207* whether they are used.208*/209goog.define('goog.DEBUG', true);210211212/**213* @define {string} LOCALE defines the locale being used for compilation. It is214* used to select locale specific data to be compiled in js binary. BUILD rule215* can specify this value by "--define goog.LOCALE=<locale_name>" as a compiler216* option.217*218* Take into account that the locale code format is important. You should use219* the canonical Unicode format with hyphen as a delimiter. Language must be220* lowercase, Language Script - Capitalized, Region - UPPERCASE.221* There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN.222*223* See more info about locale codes here:224* http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers225*226* For language codes you should use values defined by ISO 693-1. See it here227* http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from228* this rule: the Hebrew language. For legacy reasons the old code (iw) should229* be used instead of the new code (he).230*231*/232goog.define('goog.LOCALE', 'en'); // default to en233234235/**236* @define {boolean} Whether this code is running on trusted sites.237*238* On untrusted sites, several native functions can be defined or overridden by239* external libraries like Prototype, Datejs, and JQuery and setting this flag240* to false forces closure to use its own implementations when possible.241*242* If your JavaScript can be loaded by a third party site and you are wary about243* relying on non-standard implementations, specify244* "--define goog.TRUSTED_SITE=false" to the compiler.245*/246goog.define('goog.TRUSTED_SITE', true);247248249/**250* @define {boolean} Whether a project is expected to be running in strict mode.251*252* This define can be used to trigger alternate implementations compatible with253* running in EcmaScript Strict mode or warn about unavailable functionality.254* @see https://goo.gl/PudQ4y255*256*/257goog.define('goog.STRICT_MODE_COMPATIBLE', false);258259260/**261* @define {boolean} Whether code that calls {@link goog.setTestOnly} should262* be disallowed in the compilation unit.263*/264goog.define('goog.DISALLOW_TEST_ONLY_CODE', COMPILED && !goog.DEBUG);265266267/**268* @define {boolean} Whether to use a Chrome app CSP-compliant method for269* loading scripts via goog.require. @see appendScriptSrcNode_.270*/271goog.define('goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING', false);272273274/**275* Defines a namespace in Closure.276*277* A namespace may only be defined once in a codebase. It may be defined using278* goog.provide() or goog.module().279*280* The presence of one or more goog.provide() calls in a file indicates281* that the file defines the given objects/namespaces.282* Provided symbols must not be null or undefined.283*284* In addition, goog.provide() creates the object stubs for a namespace285* (for example, goog.provide("goog.foo.bar") will create the object286* goog.foo.bar if it does not already exist).287*288* Build tools also scan for provide/require/module statements289* to discern dependencies, build dependency files (see deps.js), etc.290*291* @see goog.require292* @see goog.module293* @param {string} name Namespace provided by this file in the form294* "goog.package.part".295*/296goog.provide = function(name) {297if (goog.isInModuleLoader_()) {298throw Error('goog.provide can not be used within a goog.module.');299}300if (!COMPILED) {301// Ensure that the same namespace isn't provided twice.302// A goog.module/goog.provide maps a goog.require to a specific file303if (goog.isProvided_(name)) {304throw Error('Namespace "' + name + '" already declared.');305}306}307308goog.constructNamespace_(name);309};310311312/**313* @param {string} name Namespace provided by this file in the form314* "goog.package.part".315* @param {Object=} opt_obj The object to embed in the namespace.316* @private317*/318goog.constructNamespace_ = function(name, opt_obj) {319if (!COMPILED) {320delete goog.implicitNamespaces_[name];321322var namespace = name;323while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) {324if (goog.getObjectByName(namespace)) {325break;326}327goog.implicitNamespaces_[namespace] = true;328}329}330331goog.exportPath_(name, opt_obj);332};333334335/**336* Module identifier validation regexp.337* Note: This is a conservative check, it is very possible to be more lenient,338* the primary exclusion here is "/" and "\" and a leading ".", these339* restrictions are intended to leave the door open for using goog.require340* with relative file paths rather than module identifiers.341* @private342*/343goog.VALID_MODULE_RE_ = /^[a-zA-Z_$][a-zA-Z0-9._$]*$/;344345346/**347* Defines a module in Closure.348*349* Marks that this file must be loaded as a module and claims the namespace.350*351* A namespace may only be defined once in a codebase. It may be defined using352* goog.provide() or goog.module().353*354* goog.module() has three requirements:355* - goog.module may not be used in the same file as goog.provide.356* - goog.module must be the first statement in the file.357* - only one goog.module is allowed per file.358*359* When a goog.module annotated file is loaded, it is enclosed in360* a strict function closure. This means that:361* - any variables declared in a goog.module file are private to the file362* (not global), though the compiler is expected to inline the module.363* - The code must obey all the rules of "strict" JavaScript.364* - the file will be marked as "use strict"365*366* NOTE: unlike goog.provide, goog.module does not declare any symbols by367* itself. If declared symbols are desired, use368* goog.module.declareLegacyNamespace().369*370*371* See the public goog.module proposal: http://goo.gl/Va1hin372*373* @param {string} name Namespace provided by this file in the form374* "goog.package.part", is expected but not required.375* @return {void}376*/377goog.module = function(name) {378if (!goog.isString(name) || !name ||379name.search(goog.VALID_MODULE_RE_) == -1) {380throw Error('Invalid module identifier');381}382if (!goog.isInModuleLoader_()) {383throw Error(384'Module ' + name + ' has been loaded incorrectly. Note, ' +385'modules cannot be loaded as normal scripts. They require some kind of ' +386'pre-processing step. You\'re likely trying to load a module via a ' +387'script tag or as a part of a concatenated bundle without rewriting the ' +388'module. For more info see: ' +389'https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.');390}391if (goog.moduleLoaderState_.moduleName) {392throw Error('goog.module may only be called once per module.');393}394395// Store the module name for the loader.396goog.moduleLoaderState_.moduleName = name;397if (!COMPILED) {398// Ensure that the same namespace isn't provided twice.399// A goog.module/goog.provide maps a goog.require to a specific file400if (goog.isProvided_(name)) {401throw Error('Namespace "' + name + '" already declared.');402}403delete goog.implicitNamespaces_[name];404}405};406407408/**409* @param {string} name The module identifier.410* @return {?} The module exports for an already loaded module or null.411*412* Note: This is not an alternative to goog.require, it does not413* indicate a hard dependency, instead it is used to indicate414* an optional dependency or to access the exports of a module415* that has already been loaded.416* @suppress {missingProvide}417*/418goog.module.get = function(name) {419return goog.module.getInternal_(name);420};421422423/**424* @param {string} name The module identifier.425* @return {?} The module exports for an already loaded module or null.426* @private427*/428goog.module.getInternal_ = function(name) {429if (!COMPILED) {430if (name in goog.loadedModules_) {431return goog.loadedModules_[name];432} else if (!goog.implicitNamespaces_[name]) {433var ns = goog.getObjectByName(name);434return ns != null ? ns : null;435}436}437return null;438};439440441/**442* @private {?{moduleName: (string|undefined), declareLegacyNamespace:boolean}}443*/444goog.moduleLoaderState_ = null;445446447/**448* @private449* @return {boolean} Whether a goog.module is currently being initialized.450*/451goog.isInModuleLoader_ = function() {452return goog.moduleLoaderState_ != null;453};454455456/**457* Provide the module's exports as a globally accessible object under the458* module's declared name. This is intended to ease migration to goog.module459* for files that have existing usages.460* @suppress {missingProvide}461*/462goog.module.declareLegacyNamespace = function() {463if (!COMPILED && !goog.isInModuleLoader_()) {464throw new Error(465'goog.module.declareLegacyNamespace must be called from ' +466'within a goog.module');467}468if (!COMPILED && !goog.moduleLoaderState_.moduleName) {469throw Error(470'goog.module must be called prior to ' +471'goog.module.declareLegacyNamespace.');472}473goog.moduleLoaderState_.declareLegacyNamespace = true;474};475476477/**478* Marks that the current file should only be used for testing, and never for479* live code in production.480*481* In the case of unit tests, the message may optionally be an exact namespace482* for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra483* provide (if not explicitly defined in the code).484*485* @param {string=} opt_message Optional message to add to the error that's486* raised when used in production code.487*/488goog.setTestOnly = function(opt_message) {489if (goog.DISALLOW_TEST_ONLY_CODE) {490opt_message = opt_message || '';491throw Error(492'Importing test-only code into non-debug environment' +493(opt_message ? ': ' + opt_message : '.'));494}495};496497498/**499* Forward declares a symbol. This is an indication to the compiler that the500* symbol may be used in the source yet is not required and may not be provided501* in compilation.502*503* The most common usage of forward declaration is code that takes a type as a504* function parameter but does not need to require it. By forward declaring505* instead of requiring, no hard dependency is made, and (if not required506* elsewhere) the namespace may never be required and thus, not be pulled507* into the JavaScript binary. If it is required elsewhere, it will be type508* checked as normal.509*510* Before using goog.forwardDeclare, please read the documentation at511* https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation to512* understand the options and tradeoffs when working with forward declarations.513*514* @param {string} name The namespace to forward declare in the form of515* "goog.package.part".516*/517goog.forwardDeclare = function(name) {};518519520/**521* Forward declare type information. Used to assign types to goog.global522* referenced object that would otherwise result in unknown type references523* and thus block property disambiguation.524*/525goog.forwardDeclare('Document');526goog.forwardDeclare('HTMLScriptElement');527goog.forwardDeclare('XMLHttpRequest');528529530if (!COMPILED) {531/**532* Check if the given name has been goog.provided. This will return false for533* names that are available only as implicit namespaces.534* @param {string} name name of the object to look for.535* @return {boolean} Whether the name has been provided.536* @private537*/538goog.isProvided_ = function(name) {539return (name in goog.loadedModules_) ||540(!goog.implicitNamespaces_[name] &&541goog.isDefAndNotNull(goog.getObjectByName(name)));542};543544/**545* Namespaces implicitly defined by goog.provide. For example,546* goog.provide('goog.events.Event') implicitly declares that 'goog' and547* 'goog.events' must be namespaces.548*549* @type {!Object<string, (boolean|undefined)>}550* @private551*/552goog.implicitNamespaces_ = {'goog.module': true};553554// NOTE: We add goog.module as an implicit namespace as goog.module is defined555// here and because the existing module package has not been moved yet out of556// the goog.module namespace. This satisifies both the debug loader and557// ahead-of-time dependency management.558}559560561/**562* Returns an object based on its fully qualified external name. The object563* is not found if null or undefined. If you are using a compilation pass that564* renames property names beware that using this function will not find renamed565* properties.566*567* @param {string} name The fully qualified name.568* @param {Object=} opt_obj The object within which to look; default is569* |goog.global|.570* @return {?} The value (object or primitive) or, if not found, null.571*/572goog.getObjectByName = function(name, opt_obj) {573var parts = name.split('.');574var cur = opt_obj || goog.global;575for (var part; part = parts.shift();) {576if (goog.isDefAndNotNull(cur[part])) {577cur = cur[part];578} else {579return null;580}581}582return cur;583};584585586/**587* Globalizes a whole namespace, such as goog or goog.lang.588*589* @param {!Object} obj The namespace to globalize.590* @param {Object=} opt_global The object to add the properties to.591* @deprecated Properties may be explicitly exported to the global scope, but592* this should no longer be done in bulk.593*/594goog.globalize = function(obj, opt_global) {595var global = opt_global || goog.global;596for (var x in obj) {597global[x] = obj[x];598}599};600601602/**603* Adds a dependency from a file to the files it requires.604* @param {string} relPath The path to the js file.605* @param {!Array<string>} provides An array of strings with606* the names of the objects this file provides.607* @param {!Array<string>} requires An array of strings with608* the names of the objects this file requires.609* @param {boolean|!Object<string>=} opt_loadFlags Parameters indicating610* how the file must be loaded. The boolean 'true' is equivalent611* to {'module': 'goog'} for backwards-compatibility. Valid properties612* and values include {'module': 'goog'} and {'lang': 'es6'}.613*/614goog.addDependency = function(relPath, provides, requires, opt_loadFlags) {615if (goog.DEPENDENCIES_ENABLED) {616var provide, require;617var path = relPath.replace(/\\/g, '/');618var deps = goog.dependencies_;619if (!opt_loadFlags || typeof opt_loadFlags === 'boolean') {620opt_loadFlags = opt_loadFlags ? {'module': 'goog'} : {};621}622for (var i = 0; provide = provides[i]; i++) {623deps.nameToPath[provide] = path;624deps.loadFlags[path] = opt_loadFlags;625}626for (var j = 0; require = requires[j]; j++) {627if (!(path in deps.requires)) {628deps.requires[path] = {};629}630deps.requires[path][require] = true;631}632}633};634635636637638// NOTE(nnaze): The debug DOM loader was included in base.js as an original way639// to do "debug-mode" development. The dependency system can sometimes be640// confusing, as can the debug DOM loader's asynchronous nature.641//642// With the DOM loader, a call to goog.require() is not blocking -- the script643// will not load until some point after the current script. If a namespace is644// needed at runtime, it needs to be defined in a previous script, or loaded via645// require() with its registered dependencies.646//647// User-defined namespaces may need their own deps file. For a reference on648// creating a deps file, see:649// Externally: https://developers.google.com/closure/library/docs/depswriter650//651// Because of legacy clients, the DOM loader can't be easily removed from652// base.js. Work is being done to make it disableable or replaceable for653// different environments (DOM-less JavaScript interpreters like Rhino or V8,654// for example). See bootstrap/ for more information.655656657/**658* @define {boolean} Whether to enable the debug loader.659*660* If enabled, a call to goog.require() will attempt to load the namespace by661* appending a script tag to the DOM (if the namespace has been registered).662*663* If disabled, goog.require() will simply assert that the namespace has been664* provided (and depend on the fact that some outside tool correctly ordered665* the script).666*/667goog.define('goog.ENABLE_DEBUG_LOADER', true);668669670/**671* @param {string} msg672* @private673*/674goog.logToConsole_ = function(msg) {675if (goog.global.console) {676goog.global.console['error'](msg);677}678};679680681/**682* Implements a system for the dynamic resolution of dependencies that works in683* parallel with the BUILD system. Note that all calls to goog.require will be684* stripped by the compiler.685* @see goog.provide686* @param {string} name Namespace to include (as was given in goog.provide()) in687* the form "goog.package.part".688* @return {?} If called within a goog.module file, the associated namespace or689* module otherwise null.690*/691goog.require = function(name) {692// If the object already exists we do not need do do anything.693if (!COMPILED) {694if (goog.ENABLE_DEBUG_LOADER && goog.IS_OLD_IE_) {695goog.maybeProcessDeferredDep_(name);696}697698if (goog.isProvided_(name)) {699if (goog.isInModuleLoader_()) {700return goog.module.getInternal_(name);701}702} else if (goog.ENABLE_DEBUG_LOADER) {703var path = goog.getPathFromDeps_(name);704if (path) {705goog.writeScripts_(path);706} else {707var errorMessage = 'goog.require could not find: ' + name;708goog.logToConsole_(errorMessage);709710throw Error(errorMessage);711}712}713714return null;715}716};717718719/**720* Path for included scripts.721* @type {string}722*/723goog.basePath = '';724725726/**727* A hook for overriding the base path.728* @type {string|undefined}729*/730goog.global.CLOSURE_BASE_PATH;731732733/**734* Whether to attempt to load Closure's deps file. By default, when uncompiled,735* deps files will attempt to be loaded.736* @type {boolean|undefined}737*/738goog.global.CLOSURE_NO_DEPS;739740741/**742* A function to import a single script. This is meant to be overridden when743* Closure is being run in non-HTML contexts, such as web workers. It's defined744* in the global scope so that it can be set before base.js is loaded, which745* allows deps.js to be imported properly.746*747* The function is passed the script source, which is a relative URI. It should748* return true if the script was imported, false otherwise.749* @type {(function(string): boolean)|undefined}750*/751goog.global.CLOSURE_IMPORT_SCRIPT;752753754/**755* Null function used for default values of callbacks, etc.756* @return {void} Nothing.757*/758goog.nullFunction = function() {};759760761/**762* When defining a class Foo with an abstract method bar(), you can do:763* Foo.prototype.bar = goog.abstractMethod764*765* Now if a subclass of Foo fails to override bar(), an error will be thrown766* when bar() is invoked.767*768* @type {!Function}769* @throws {Error} when invoked to indicate the method should be overridden.770*/771goog.abstractMethod = function() {772throw Error('unimplemented abstract method');773};774775776/**777* Adds a {@code getInstance} static method that always returns the same778* instance object.779* @param {!Function} ctor The constructor for the class to add the static780* method to.781*/782goog.addSingletonGetter = function(ctor) {783// instance_ is immediately set to prevent issues with sealed constructors784// such as are encountered when a constructor is returned as the export object785// of a goog.module in unoptimized code.786ctor.instance_ = undefined;787ctor.getInstance = function() {788if (ctor.instance_) {789return ctor.instance_;790}791if (goog.DEBUG) {792// NOTE: JSCompiler can't optimize away Array#push.793goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor;794}795return ctor.instance_ = new ctor;796};797};798799800/**801* All singleton classes that have been instantiated, for testing. Don't read802* it directly, use the {@code goog.testing.singleton} module. The compiler803* removes this variable if unused.804* @type {!Array<!Function>}805* @private806*/807goog.instantiatedSingletons_ = [];808809810/**811* @define {boolean} Whether to load goog.modules using {@code eval} when using812* the debug loader. This provides a better debugging experience as the813* source is unmodified and can be edited using Chrome Workspaces or similar.814* However in some environments the use of {@code eval} is banned815* so we provide an alternative.816*/817goog.define('goog.LOAD_MODULE_USING_EVAL', true);818819820/**821* @define {boolean} Whether the exports of goog.modules should be sealed when822* possible.823*/824goog.define('goog.SEAL_MODULE_EXPORTS', goog.DEBUG);825826827/**828* The registry of initialized modules:829* the module identifier to module exports map.830* @private @const {!Object<string, ?>}831*/832goog.loadedModules_ = {};833834835/**836* True if goog.dependencies_ is available.837* @const {boolean}838*/839goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER;840841842/**843* @define {string} How to decide whether to transpile. Valid values844* are 'always', 'never', and 'detect'. The default ('detect') is to845* use feature detection to determine which language levels need846* transpilation.847*/848// NOTE(user): we could expand this to accept a language level to bypass849// detection: e.g. goog.TRANSPILE == 'es5' would transpile ES6 files but850// would leave ES3 and ES5 files alone.851goog.define('goog.TRANSPILE', 'detect');852853854/**855* @define {string} Path to the transpiler. Executing the script at this856* path (relative to base.js) should define a function $jscomp.transpile.857*/858goog.define('goog.TRANSPILER', 'transpile.js');859860861if (goog.DEPENDENCIES_ENABLED) {862/**863* This object is used to keep track of dependencies and other data that is864* used for loading scripts.865* @private866* @type {{867* loadFlags: !Object<string, !Object<string, string>>,868* nameToPath: !Object<string, string>,869* requires: !Object<string, !Object<string, boolean>>,870* visited: !Object<string, boolean>,871* written: !Object<string, boolean>,872* deferred: !Object<string, string>873* }}874*/875goog.dependencies_ = {876loadFlags: {}, // 1 to 1877878nameToPath: {}, // 1 to 1879880requires: {}, // 1 to many881882// Used when resolving dependencies to prevent us from visiting file twice.883visited: {},884885written: {}, // Used to keep track of script files we have written.886887deferred: {} // Used to track deferred module evaluations in old IEs888};889890891/**892* Tries to detect whether is in the context of an HTML document.893* @return {boolean} True if it looks like HTML document.894* @private895*/896goog.inHtmlDocument_ = function() {897/** @type {Document} */898var doc = goog.global.document;899return doc != null && 'write' in doc; // XULDocument misses write.900};901902903/**904* Tries to detect the base path of base.js script that bootstraps Closure.905* @private906*/907goog.findBasePath_ = function() {908if (goog.isDef(goog.global.CLOSURE_BASE_PATH) &&909// Anti DOM-clobbering runtime check (b/37736576).910goog.isString(goog.global.CLOSURE_BASE_PATH)) {911goog.basePath = goog.global.CLOSURE_BASE_PATH;912return;913} else if (!goog.inHtmlDocument_()) {914return;915}916/** @type {Document} */917var doc = goog.global.document;918// If we have a currentScript available, use it exclusively.919var currentScript = doc.currentScript;920if (currentScript) {921var scripts = [currentScript];922} else {923var scripts = doc.getElementsByTagName('SCRIPT');924}925// Search backwards since the current script is in almost all cases the one926// that has base.js.927for (var i = scripts.length - 1; i >= 0; --i) {928var script = /** @type {!HTMLScriptElement} */ (scripts[i]);929var src = script.src;930var qmark = src.lastIndexOf('?');931var l = qmark == -1 ? src.length : qmark;932if (src.substr(l - 7, 7) == 'base.js') {933goog.basePath = src.substr(0, l - 7);934return;935}936}937};938939940/**941* Imports a script if, and only if, that script hasn't already been imported.942* (Must be called at execution time)943* @param {string} src Script source.944* @param {string=} opt_sourceText The optionally source text to evaluate945* @private946*/947goog.importScript_ = function(src, opt_sourceText) {948var importScript =949goog.global.CLOSURE_IMPORT_SCRIPT || goog.writeScriptTag_;950if (importScript(src, opt_sourceText)) {951goog.dependencies_.written[src] = true;952}953};954955956/**957* Whether the browser is IE9 or earlier, which needs special handling958* for deferred modules.959* @const @private {boolean}960*/961goog.IS_OLD_IE_ =962!!(!goog.global.atob && goog.global.document && goog.global.document.all);963964965/**966* Whether IE9 or earlier is waiting on a dependency. This ensures that967* deferred modules that have no non-deferred dependencies actually get968* loaded, since if we defer them and then never pull in a non-deferred969* script, then `goog.loadQueuedModules_` will never be called. Instead,970* if not waiting on anything we simply don't defer in the first place.971* @private {boolean}972*/973goog.oldIeWaiting_ = false;974975976/**977* Given a URL initiate retrieval and execution of a script that needs978* pre-processing.979* @param {string} src Script source URL.980* @param {boolean} isModule Whether this is a goog.module.981* @param {boolean} needsTranspile Whether this source needs transpilation.982* @private983*/984goog.importProcessedScript_ = function(src, isModule, needsTranspile) {985// In an attempt to keep browsers from timing out loading scripts using986// synchronous XHRs, put each load in its own script block.987var bootstrap = 'goog.retrieveAndExec_("' + src + '", ' + isModule + ', ' +988needsTranspile + ');';989990goog.importScript_('', bootstrap);991};992993994/** @private {!Array<string>} */995goog.queuedModules_ = [];996997998/**999* Return an appropriate module text. Suitable to insert into1000* a script tag (that is unescaped).1001* @param {string} srcUrl1002* @param {string} scriptText1003* @return {string}1004* @private1005*/1006goog.wrapModule_ = function(srcUrl, scriptText) {1007if (!goog.LOAD_MODULE_USING_EVAL || !goog.isDef(goog.global.JSON)) {1008return '' +1009'goog.loadModule(function(exports) {' +1010'"use strict";' + scriptText +1011'\n' + // terminate any trailing single line comment.1012';return exports' +1013'});' +1014'\n//# sourceURL=' + srcUrl + '\n';1015} else {1016return '' +1017'goog.loadModule(' +1018goog.global.JSON.stringify(1019scriptText + '\n//# sourceURL=' + srcUrl + '\n') +1020');';1021}1022};10231024// On IE9 and earlier, it is necessary to handle1025// deferred module loads. In later browsers, the1026// code to be evaluated is simply inserted as a script1027// block in the correct order. To eval deferred1028// code at the right time, we piggy back on goog.require to call1029// goog.maybeProcessDeferredDep_.1030//1031// The goog.requires are used both to bootstrap1032// the loading process (when no deps are available) and1033// declare that they should be available.1034//1035// Here we eval the sources, if all the deps are available1036// either already eval'd or goog.require'd. This will1037// be the case when all the dependencies have already1038// been loaded, and the dependent module is loaded.1039//1040// But this alone isn't sufficient because it is also1041// necessary to handle the case where there is no root1042// that is not deferred. For that there we register for an event1043// and trigger goog.loadQueuedModules_ handle any remaining deferred1044// evaluations.10451046/**1047* Handle any remaining deferred goog.module evals.1048* @private1049*/1050goog.loadQueuedModules_ = function() {1051var count = goog.queuedModules_.length;1052if (count > 0) {1053var queue = goog.queuedModules_;1054goog.queuedModules_ = [];1055for (var i = 0; i < count; i++) {1056var path = queue[i];1057goog.maybeProcessDeferredPath_(path);1058}1059}1060goog.oldIeWaiting_ = false;1061};106210631064/**1065* Eval the named module if its dependencies are1066* available.1067* @param {string} name The module to load.1068* @private1069*/1070goog.maybeProcessDeferredDep_ = function(name) {1071if (goog.isDeferredModule_(name) && goog.allDepsAreAvailable_(name)) {1072var path = goog.getPathFromDeps_(name);1073goog.maybeProcessDeferredPath_(goog.basePath + path);1074}1075};10761077/**1078* @param {string} name The module to check.1079* @return {boolean} Whether the name represents a1080* module whose evaluation has been deferred.1081* @private1082*/1083goog.isDeferredModule_ = function(name) {1084var path = goog.getPathFromDeps_(name);1085var loadFlags = path && goog.dependencies_.loadFlags[path] || {};1086var languageLevel = loadFlags['lang'] || 'es3';1087if (path && (loadFlags['module'] == 'goog' ||1088goog.needsTranspile_(languageLevel))) {1089var abspath = goog.basePath + path;1090return (abspath) in goog.dependencies_.deferred;1091}1092return false;1093};10941095/**1096* @param {string} name The module to check.1097* @return {boolean} Whether the name represents a1098* module whose declared dependencies have all been loaded1099* (eval'd or a deferred module load)1100* @private1101*/1102goog.allDepsAreAvailable_ = function(name) {1103var path = goog.getPathFromDeps_(name);1104if (path && (path in goog.dependencies_.requires)) {1105for (var requireName in goog.dependencies_.requires[path]) {1106if (!goog.isProvided_(requireName) &&1107!goog.isDeferredModule_(requireName)) {1108return false;1109}1110}1111}1112return true;1113};111411151116/**1117* @param {string} abspath1118* @private1119*/1120goog.maybeProcessDeferredPath_ = function(abspath) {1121if (abspath in goog.dependencies_.deferred) {1122var src = goog.dependencies_.deferred[abspath];1123delete goog.dependencies_.deferred[abspath];1124goog.globalEval(src);1125}1126};112711281129/**1130* Load a goog.module from the provided URL. This is not a general purpose1131* code loader and does not support late loading code, that is it should only1132* be used during page load. This method exists to support unit tests and1133* "debug" loaders that would otherwise have inserted script tags. Under the1134* hood this needs to use a synchronous XHR and is not recommeneded for1135* production code.1136*1137* The module's goog.requires must have already been satisified; an exception1138* will be thrown if this is not the case. This assumption is that no1139* "deps.js" file exists, so there is no way to discover and locate the1140* module-to-be-loaded's dependencies and no attempt is made to do so.1141*1142* There should only be one attempt to load a module. If1143* "goog.loadModuleFromUrl" is called for an already loaded module, an1144* exception will be throw.1145*1146* @param {string} url The URL from which to attempt to load the goog.module.1147*/1148goog.loadModuleFromUrl = function(url) {1149// Because this executes synchronously, we don't need to do any additional1150// bookkeeping. When "goog.loadModule" the namespace will be marked as1151// having been provided which is sufficient.1152goog.retrieveAndExec_(url, true, false);1153};115411551156/**1157* Writes a new script pointing to {@code src} directly into the DOM.1158*1159* NOTE: This method is not CSP-compliant. @see goog.appendScriptSrcNode_ for1160* the fallback mechanism.1161*1162* @param {string} src The script URL.1163* @private1164*/1165goog.writeScriptSrcNode_ = function(src) {1166goog.global.document.write(1167'<script type="text/javascript" src="' + src + '"></' +1168'script>');1169};117011711172/**1173* Appends a new script node to the DOM using a CSP-compliant mechanism. This1174* method exists as a fallback for document.write (which is not allowed in a1175* strict CSP context, e.g., Chrome apps).1176*1177* NOTE: This method is not analogous to using document.write to insert a1178* <script> tag; specifically, the user agent will execute a script added by1179* document.write immediately after the current script block finishes1180* executing, whereas the DOM-appended script node will not be executed until1181* the entire document is parsed and executed. That is to say, this script is1182* added to the end of the script execution queue.1183*1184* The page must not attempt to call goog.required entities until after the1185* document has loaded, e.g., in or after the window.onload callback.1186*1187* @param {string} src The script URL.1188* @private1189*/1190goog.appendScriptSrcNode_ = function(src) {1191/** @type {Document} */1192var doc = goog.global.document;1193var scriptEl =1194/** @type {HTMLScriptElement} */ (doc.createElement('script'));1195scriptEl.type = 'text/javascript';1196scriptEl.src = src;1197scriptEl.defer = false;1198scriptEl.async = false;1199doc.head.appendChild(scriptEl);1200};120112021203/**1204* The default implementation of the import function. Writes a script tag to1205* import the script.1206*1207* @param {string} src The script url.1208* @param {string=} opt_sourceText The optionally source text to evaluate1209* @return {boolean} True if the script was imported, false otherwise.1210* @private1211*/1212goog.writeScriptTag_ = function(src, opt_sourceText) {1213if (goog.inHtmlDocument_()) {1214/** @type {!HTMLDocument} */1215var doc = goog.global.document;12161217// If the user tries to require a new symbol after document load,1218// something has gone terribly wrong. Doing a document.write would1219// wipe out the page. This does not apply to the CSP-compliant method1220// of writing script tags.1221if (!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING &&1222doc.readyState == 'complete') {1223// Certain test frameworks load base.js multiple times, which tries1224// to write deps.js each time. If that happens, just fail silently.1225// These frameworks wipe the page between each load of base.js, so this1226// is OK.1227var isDeps = /\bdeps.js$/.test(src);1228if (isDeps) {1229return false;1230} else {1231throw Error('Cannot write "' + src + '" after document load');1232}1233}12341235if (opt_sourceText === undefined) {1236if (!goog.IS_OLD_IE_) {1237if (goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING) {1238goog.appendScriptSrcNode_(src);1239} else {1240goog.writeScriptSrcNode_(src);1241}1242} else {1243goog.oldIeWaiting_ = true;1244var state = ' onreadystatechange=\'goog.onScriptLoad_(this, ' +1245++goog.lastNonModuleScriptIndex_ + ')\' ';1246doc.write(1247'<script type="text/javascript" src="' + src + '"' + state +1248'></' +1249'script>');1250}1251} else {1252doc.write(1253'<script type="text/javascript">' +1254goog.protectScriptTag_(opt_sourceText) + '</' +1255'script>');1256}1257return true;1258} else {1259return false;1260}1261};12621263/**1264* Rewrites closing script tags in input to avoid ending an enclosing script1265* tag.1266*1267* @param {string} str1268* @return {string}1269* @private1270*/1271goog.protectScriptTag_ = function(str) {1272return str.replace(/<\/(SCRIPT)/ig, '\\x3c/$1');1273};12741275/**1276* Determines whether the given language needs to be transpiled.1277* @param {string} lang1278* @return {boolean}1279* @private1280*/1281goog.needsTranspile_ = function(lang) {1282if (goog.TRANSPILE == 'always') {1283return true;1284} else if (goog.TRANSPILE == 'never') {1285return false;1286} else if (!goog.requiresTranspilation_) {1287goog.requiresTranspilation_ = goog.createRequiresTranspilation_();1288}1289if (lang in goog.requiresTranspilation_) {1290return goog.requiresTranspilation_[lang];1291} else {1292throw new Error('Unknown language mode: ' + lang);1293}1294};12951296/** @private {?Object<string, boolean>} */1297goog.requiresTranspilation_ = null;129812991300/** @private {number} */1301goog.lastNonModuleScriptIndex_ = 0;130213031304/**1305* A readystatechange handler for legacy IE1306* @param {!HTMLScriptElement} script1307* @param {number} scriptIndex1308* @return {boolean}1309* @private1310*/1311goog.onScriptLoad_ = function(script, scriptIndex) {1312// for now load the modules when we reach the last script,1313// later allow more inter-mingling.1314if (script.readyState == 'complete' &&1315goog.lastNonModuleScriptIndex_ == scriptIndex) {1316goog.loadQueuedModules_();1317}1318return true;1319};13201321/**1322* Resolves dependencies based on the dependencies added using addDependency1323* and calls importScript_ in the correct order.1324* @param {string} pathToLoad The path from which to start discovering1325* dependencies.1326* @private1327*/1328goog.writeScripts_ = function(pathToLoad) {1329/** @type {!Array<string>} The scripts we need to write this time. */1330var scripts = [];1331var seenScript = {};1332var deps = goog.dependencies_;13331334/** @param {string} path */1335function visitNode(path) {1336if (path in deps.written) {1337return;1338}13391340// We have already visited this one. We can get here if we have cyclic1341// dependencies.1342if (path in deps.visited) {1343return;1344}13451346deps.visited[path] = true;13471348if (path in deps.requires) {1349for (var requireName in deps.requires[path]) {1350// If the required name is defined, we assume that it was already1351// bootstrapped by other means.1352if (!goog.isProvided_(requireName)) {1353if (requireName in deps.nameToPath) {1354visitNode(deps.nameToPath[requireName]);1355} else {1356throw Error('Undefined nameToPath for ' + requireName);1357}1358}1359}1360}13611362if (!(path in seenScript)) {1363seenScript[path] = true;1364scripts.push(path);1365}1366}13671368visitNode(pathToLoad);13691370// record that we are going to load all these scripts.1371for (var i = 0; i < scripts.length; i++) {1372var path = scripts[i];1373goog.dependencies_.written[path] = true;1374}13751376// If a module is loaded synchronously then we need to1377// clear the current inModuleLoader value, and restore it when we are1378// done loading the current "requires".1379var moduleState = goog.moduleLoaderState_;1380goog.moduleLoaderState_ = null;13811382for (var i = 0; i < scripts.length; i++) {1383var path = scripts[i];1384if (path) {1385var loadFlags = deps.loadFlags[path] || {};1386var languageLevel = loadFlags['lang'] || 'es3';1387var needsTranspile = goog.needsTranspile_(languageLevel);1388if (loadFlags['module'] == 'goog' || needsTranspile) {1389goog.importProcessedScript_(1390goog.basePath + path, loadFlags['module'] == 'goog',1391needsTranspile);1392} else {1393goog.importScript_(goog.basePath + path);1394}1395} else {1396goog.moduleLoaderState_ = moduleState;1397throw Error('Undefined script input');1398}1399}14001401// restore the current "module loading state"1402goog.moduleLoaderState_ = moduleState;1403};140414051406/**1407* Looks at the dependency rules and tries to determine the script file that1408* fulfills a particular rule.1409* @param {string} rule In the form goog.namespace.Class or project.script.1410* @return {?string} Url corresponding to the rule, or null.1411* @private1412*/1413goog.getPathFromDeps_ = function(rule) {1414if (rule in goog.dependencies_.nameToPath) {1415return goog.dependencies_.nameToPath[rule];1416} else {1417return null;1418}1419};14201421goog.findBasePath_();14221423// Allow projects to manage the deps files themselves.1424if (!goog.global.CLOSURE_NO_DEPS) {1425goog.importScript_(goog.basePath + 'deps.js');1426}1427}142814291430/**1431* @package {?boolean}1432* Visible for testing.1433*/1434goog.hasBadLetScoping = null;143514361437/**1438* @return {boolean}1439* @package Visible for testing.1440*/1441goog.useSafari10Workaround = function() {1442if (goog.hasBadLetScoping == null) {1443var hasBadLetScoping;1444try {1445hasBadLetScoping = !eval(1446'"use strict";' +1447'let x = 1; function f() { return typeof x; };' +1448'f() == "number";');1449} catch (e) {1450// Assume that ES6 syntax isn't supported.1451hasBadLetScoping = false;1452}1453goog.hasBadLetScoping = hasBadLetScoping;1454}1455return goog.hasBadLetScoping;1456};145714581459/**1460* @param {string} moduleDef1461* @return {string}1462* @package Visible for testing.1463*/1464goog.workaroundSafari10EvalBug = function(moduleDef) {1465return '(function(){' + moduleDef +1466'\n' + // Terminate any trailing single line comment.1467';' + // Terminate any trailing expression.1468'})();\n';1469};147014711472/**1473* @param {function(?):?|string} moduleDef The module definition.1474*/1475goog.loadModule = function(moduleDef) {1476// NOTE: we allow function definitions to be either in the from1477// of a string to eval (which keeps the original source intact) or1478// in a eval forbidden environment (CSP) we allow a function definition1479// which in its body must call {@code goog.module}, and return the exports1480// of the module.1481var previousState = goog.moduleLoaderState_;1482try {1483goog.moduleLoaderState_ = {1484moduleName: undefined,1485declareLegacyNamespace: false1486};1487var exports;1488if (goog.isFunction(moduleDef)) {1489exports = moduleDef.call(undefined, {});1490} else if (goog.isString(moduleDef)) {1491if (goog.useSafari10Workaround()) {1492moduleDef = goog.workaroundSafari10EvalBug(moduleDef);1493}14941495exports = goog.loadModuleFromSource_.call(undefined, moduleDef);1496} else {1497throw Error('Invalid module definition');1498}14991500var moduleName = goog.moduleLoaderState_.moduleName;1501if (!goog.isString(moduleName) || !moduleName) {1502throw Error('Invalid module name \"' + moduleName + '\"');1503}15041505// Don't seal legacy namespaces as they may be uses as a parent of1506// another namespace1507if (goog.moduleLoaderState_.declareLegacyNamespace) {1508goog.constructNamespace_(moduleName, exports);1509} else if (1510goog.SEAL_MODULE_EXPORTS && Object.seal && typeof exports == 'object' &&1511exports != null) {1512Object.seal(exports);1513}15141515goog.loadedModules_[moduleName] = exports;1516} finally {1517goog.moduleLoaderState_ = previousState;1518}1519};152015211522/**1523* @private @const1524*/1525goog.loadModuleFromSource_ = /** @type {function(string):?} */ (function() {1526// NOTE: we avoid declaring parameters or local variables here to avoid1527// masking globals or leaking values into the module definition.1528'use strict';1529var exports = {};1530eval(arguments[0]);1531return exports;1532});153315341535/**1536* Normalize a file path by removing redundant ".." and extraneous "." file1537* path components.1538* @param {string} path1539* @return {string}1540* @private1541*/1542goog.normalizePath_ = function(path) {1543var components = path.split('/');1544var i = 0;1545while (i < components.length) {1546if (components[i] == '.') {1547components.splice(i, 1);1548} else if (1549i && components[i] == '..' && components[i - 1] &&1550components[i - 1] != '..') {1551components.splice(--i, 2);1552} else {1553i++;1554}1555}1556return components.join('/');1557};155815591560/**1561* Provides a hook for loading a file when using Closure's goog.require() API1562* with goog.modules. In particular this hook is provided to support Node.js.1563*1564* @type {(function(string):string)|undefined}1565*/1566goog.global.CLOSURE_LOAD_FILE_SYNC;156715681569/**1570* Loads file by synchronous XHR. Should not be used in production environments.1571* @param {string} src Source URL.1572* @return {?string} File contents, or null if load failed.1573* @private1574*/1575goog.loadFileSync_ = function(src) {1576if (goog.global.CLOSURE_LOAD_FILE_SYNC) {1577return goog.global.CLOSURE_LOAD_FILE_SYNC(src);1578} else {1579try {1580/** @type {XMLHttpRequest} */1581var xhr = new goog.global['XMLHttpRequest']();1582xhr.open('get', src, false);1583xhr.send();1584// NOTE: Successful http: requests have a status of 200, but successful1585// file: requests may have a status of zero. Any other status, or a1586// thrown exception (particularly in case of file: requests) indicates1587// some sort of error, which we treat as a missing or unavailable file.1588return xhr.status == 0 || xhr.status == 200 ? xhr.responseText : null;1589} catch (err) {1590// No need to rethrow or log, since errors should show up on their own.1591return null;1592}1593}1594};159515961597/**1598* Retrieve and execute a script that needs some sort of wrapping.1599* @param {string} src Script source URL.1600* @param {boolean} isModule Whether to load as a module.1601* @param {boolean} needsTranspile Whether to transpile down to ES3.1602* @private1603*/1604goog.retrieveAndExec_ = function(src, isModule, needsTranspile) {1605if (!COMPILED) {1606// The full but non-canonicalized URL for later use.1607var originalPath = src;1608// Canonicalize the path, removing any /./ or /../ since Chrome's debugging1609// console doesn't auto-canonicalize XHR loads as it does <script> srcs.1610src = goog.normalizePath_(src);16111612var importScript =1613goog.global.CLOSURE_IMPORT_SCRIPT || goog.writeScriptTag_;16141615var scriptText = goog.loadFileSync_(src);1616if (scriptText == null) {1617throw new Error('Load of "' + src + '" failed');1618}16191620if (needsTranspile) {1621scriptText = goog.transpile_.call(goog.global, scriptText, src);1622}16231624if (isModule) {1625scriptText = goog.wrapModule_(src, scriptText);1626} else {1627scriptText += '\n//# sourceURL=' + src;1628}1629var isOldIE = goog.IS_OLD_IE_;1630if (isOldIE && goog.oldIeWaiting_) {1631goog.dependencies_.deferred[originalPath] = scriptText;1632goog.queuedModules_.push(originalPath);1633} else {1634importScript(src, scriptText);1635}1636}1637};163816391640/**1641* Lazily retrieves the transpiler and applies it to the source.1642* @param {string} code JS code.1643* @param {string} path Path to the code.1644* @return {string} The transpiled code.1645* @private1646*/1647goog.transpile_ = function(code, path) {1648var jscomp = goog.global['$jscomp'];1649if (!jscomp) {1650goog.global['$jscomp'] = jscomp = {};1651}1652var transpile = jscomp.transpile;1653if (!transpile) {1654var transpilerPath = goog.basePath + goog.TRANSPILER;1655var transpilerCode = goog.loadFileSync_(transpilerPath);1656if (transpilerCode) {1657// This must be executed synchronously, since by the time we know we1658// need it, we're about to load and write the ES6 code synchronously,1659// so a normal script-tag load will be too slow.1660eval(transpilerCode + '\n//# sourceURL=' + transpilerPath);1661// Even though the transpiler is optional, if $gwtExport is found, it's1662// a sign the transpiler was loaded and the $jscomp.transpile *should*1663// be there.1664if (goog.global['$gwtExport'] && goog.global['$gwtExport']['$jscomp'] &&1665!goog.global['$gwtExport']['$jscomp']['transpile']) {1666throw new Error(1667'The transpiler did not properly export the "transpile" ' +1668'method. $gwtExport: ' + JSON.stringify(goog.global['$gwtExport']));1669}1670// transpile.js only exports a single $jscomp function, transpile. We1671// grab just that and add it to the existing definition of $jscomp which1672// contains the polyfills.1673goog.global['$jscomp'].transpile =1674goog.global['$gwtExport']['$jscomp']['transpile'];1675jscomp = goog.global['$jscomp'];1676transpile = jscomp.transpile;1677}1678}1679if (!transpile) {1680// The transpiler is an optional component. If it's not available then1681// replace it with a pass-through function that simply logs.1682var suffix = ' requires transpilation but no transpiler was found.';1683transpile = jscomp.transpile = function(code, path) {1684// TODO(user): figure out some way to get this error to show up1685// in test results, noting that the failure may occur in many1686// different ways, including in loadModule() before the test1687// runner even comes up.1688goog.logToConsole_(path + suffix);1689return code;1690};1691}1692// Note: any transpilation errors/warnings will be logged to the console.1693return transpile(code, path);1694};169516961697//==============================================================================1698// Language Enhancements1699//==============================================================================170017011702/**1703* This is a "fixed" version of the typeof operator. It differs from the typeof1704* operator in such a way that null returns 'null' and arrays return 'array'.1705* @param {?} value The value to get the type of.1706* @return {string} The name of the type.1707*/1708goog.typeOf = function(value) {1709var s = typeof value;1710if (s == 'object') {1711if (value) {1712// Check these first, so we can avoid calling Object.prototype.toString if1713// possible.1714//1715// IE improperly marshals typeof across execution contexts, but a1716// cross-context object will still return false for "instanceof Object".1717if (value instanceof Array) {1718return 'array';1719} else if (value instanceof Object) {1720return s;1721}17221723// HACK: In order to use an Object prototype method on the arbitrary1724// value, the compiler requires the value be cast to type Object,1725// even though the ECMA spec explicitly allows it.1726var className = Object.prototype.toString.call(1727/** @type {!Object} */ (value));1728// In Firefox 3.6, attempting to access iframe window objects' length1729// property throws an NS_ERROR_FAILURE, so we need to special-case it1730// here.1731if (className == '[object Window]') {1732return 'object';1733}17341735// We cannot always use constructor == Array or instanceof Array because1736// different frames have different Array objects. In IE6, if the iframe1737// where the array was created is destroyed, the array loses its1738// prototype. Then dereferencing val.splice here throws an exception, so1739// we can't use goog.isFunction. Calling typeof directly returns 'unknown'1740// so that will work. In this case, this function will return false and1741// most array functions will still work because the array is still1742// array-like (supports length and []) even though it has lost its1743// prototype.1744// Mark Miller noticed that Object.prototype.toString1745// allows access to the unforgeable [[Class]] property.1746// 15.2.4.2 Object.prototype.toString ( )1747// When the toString method is called, the following steps are taken:1748// 1. Get the [[Class]] property of this object.1749// 2. Compute a string value by concatenating the three strings1750// "[object ", Result(1), and "]".1751// 3. Return Result(2).1752// and this behavior survives the destruction of the execution context.1753if ((className == '[object Array]' ||1754// In IE all non value types are wrapped as objects across window1755// boundaries (not iframe though) so we have to do object detection1756// for this edge case.1757typeof value.length == 'number' &&1758typeof value.splice != 'undefined' &&1759typeof value.propertyIsEnumerable != 'undefined' &&1760!value.propertyIsEnumerable('splice')17611762)) {1763return 'array';1764}1765// HACK: There is still an array case that fails.1766// function ArrayImpostor() {}1767// ArrayImpostor.prototype = [];1768// var impostor = new ArrayImpostor;1769// this can be fixed by getting rid of the fast path1770// (value instanceof Array) and solely relying on1771// (value && Object.prototype.toString.vall(value) === '[object Array]')1772// but that would require many more function calls and is not warranted1773// unless closure code is receiving objects from untrusted sources.17741775// IE in cross-window calls does not correctly marshal the function type1776// (it appears just as an object) so we cannot use just typeof val ==1777// 'function'. However, if the object has a call property, it is a1778// function.1779if ((className == '[object Function]' ||1780typeof value.call != 'undefined' &&1781typeof value.propertyIsEnumerable != 'undefined' &&1782!value.propertyIsEnumerable('call'))) {1783return 'function';1784}17851786} else {1787return 'null';1788}17891790} else if (s == 'function' && typeof value.call == 'undefined') {1791// In Safari typeof nodeList returns 'function', and on Firefox typeof1792// behaves similarly for HTML{Applet,Embed,Object}, Elements and RegExps. We1793// would like to return object for those and we can detect an invalid1794// function by making sure that the function object has a call method.1795return 'object';1796}1797return s;1798};179918001801/**1802* Returns true if the specified value is null.1803* @param {?} val Variable to test.1804* @return {boolean} Whether variable is null.1805*/1806goog.isNull = function(val) {1807return val === null;1808};180918101811/**1812* Returns true if the specified value is defined and not null.1813* @param {?} val Variable to test.1814* @return {boolean} Whether variable is defined and not null.1815*/1816goog.isDefAndNotNull = function(val) {1817// Note that undefined == null.1818return val != null;1819};182018211822/**1823* Returns true if the specified value is an array.1824* @param {?} val Variable to test.1825* @return {boolean} Whether variable is an array.1826*/1827goog.isArray = function(val) {1828return goog.typeOf(val) == 'array';1829};183018311832/**1833* Returns true if the object looks like an array. To qualify as array like1834* the value needs to be either a NodeList or an object with a Number length1835* property. As a special case, a function value is not array like, because its1836* length property is fixed to correspond to the number of expected arguments.1837* @param {?} val Variable to test.1838* @return {boolean} Whether variable is an array.1839*/1840goog.isArrayLike = function(val) {1841var type = goog.typeOf(val);1842// We do not use goog.isObject here in order to exclude function values.1843return type == 'array' || type == 'object' && typeof val.length == 'number';1844};184518461847/**1848* Returns true if the object looks like a Date. To qualify as Date-like the1849* value needs to be an object and have a getFullYear() function.1850* @param {?} val Variable to test.1851* @return {boolean} Whether variable is a like a Date.1852*/1853goog.isDateLike = function(val) {1854return goog.isObject(val) && typeof val.getFullYear == 'function';1855};185618571858/**1859* Returns true if the specified value is a function.1860* @param {?} val Variable to test.1861* @return {boolean} Whether variable is a function.1862*/1863goog.isFunction = function(val) {1864return goog.typeOf(val) == 'function';1865};186618671868/**1869* Returns true if the specified value is an object. This includes arrays and1870* functions.1871* @param {?} val Variable to test.1872* @return {boolean} Whether variable is an object.1873*/1874goog.isObject = function(val) {1875var type = typeof val;1876return type == 'object' && val != null || type == 'function';1877// return Object(val) === val also works, but is slower, especially if val is1878// not an object.1879};188018811882/**1883* Gets a unique ID for an object. This mutates the object so that further calls1884* with the same object as a parameter returns the same value. The unique ID is1885* guaranteed to be unique across the current session amongst objects that are1886* passed into {@code getUid}. There is no guarantee that the ID is unique or1887* consistent across sessions. It is unsafe to generate unique ID for function1888* prototypes.1889*1890* @param {Object} obj The object to get the unique ID for.1891* @return {number} The unique ID for the object.1892*/1893goog.getUid = function(obj) {1894// TODO(arv): Make the type stricter, do not accept null.18951896// In Opera window.hasOwnProperty exists but always returns false so we avoid1897// using it. As a consequence the unique ID generated for BaseClass.prototype1898// and SubClass.prototype will be the same.1899return obj[goog.UID_PROPERTY_] ||1900(obj[goog.UID_PROPERTY_] = ++goog.uidCounter_);1901};190219031904/**1905* Whether the given object is already assigned a unique ID.1906*1907* This does not modify the object.1908*1909* @param {!Object} obj The object to check.1910* @return {boolean} Whether there is an assigned unique id for the object.1911*/1912goog.hasUid = function(obj) {1913return !!obj[goog.UID_PROPERTY_];1914};191519161917/**1918* Removes the unique ID from an object. This is useful if the object was1919* previously mutated using {@code goog.getUid} in which case the mutation is1920* undone.1921* @param {Object} obj The object to remove the unique ID field from.1922*/1923goog.removeUid = function(obj) {1924// TODO(arv): Make the type stricter, do not accept null.19251926// In IE, DOM nodes are not instances of Object and throw an exception if we1927// try to delete. Instead we try to use removeAttribute.1928if (obj !== null && 'removeAttribute' in obj) {1929obj.removeAttribute(goog.UID_PROPERTY_);1930}19311932try {1933delete obj[goog.UID_PROPERTY_];1934} catch (ex) {1935}1936};193719381939/**1940* Name for unique ID property. Initialized in a way to help avoid collisions1941* with other closure JavaScript on the same page.1942* @type {string}1943* @private1944*/1945goog.UID_PROPERTY_ = 'closure_uid_' + ((Math.random() * 1e9) >>> 0);194619471948/**1949* Counter for UID.1950* @type {number}1951* @private1952*/1953goog.uidCounter_ = 0;195419551956/**1957* Adds a hash code field to an object. The hash code is unique for the1958* given object.1959* @param {Object} obj The object to get the hash code for.1960* @return {number} The hash code for the object.1961* @deprecated Use goog.getUid instead.1962*/1963goog.getHashCode = goog.getUid;196419651966/**1967* Removes the hash code field from an object.1968* @param {Object} obj The object to remove the field from.1969* @deprecated Use goog.removeUid instead.1970*/1971goog.removeHashCode = goog.removeUid;197219731974/**1975* Clones a value. The input may be an Object, Array, or basic type. Objects and1976* arrays will be cloned recursively.1977*1978* WARNINGS:1979* <code>goog.cloneObject</code> does not detect reference loops. Objects that1980* refer to themselves will cause infinite recursion.1981*1982* <code>goog.cloneObject</code> is unaware of unique identifiers, and copies1983* UIDs created by <code>getUid</code> into cloned results.1984*1985* @param {*} obj The value to clone.1986* @return {*} A clone of the input value.1987* @deprecated goog.cloneObject is unsafe. Prefer the goog.object methods.1988*/1989goog.cloneObject = function(obj) {1990var type = goog.typeOf(obj);1991if (type == 'object' || type == 'array') {1992if (obj.clone) {1993return obj.clone();1994}1995var clone = type == 'array' ? [] : {};1996for (var key in obj) {1997clone[key] = goog.cloneObject(obj[key]);1998}1999return clone;2000}20012002return obj;2003};200420052006/**2007* A native implementation of goog.bind.2008* @param {?function(this:T, ...)} fn A function to partially apply.2009* @param {T} selfObj Specifies the object which this should point to when the2010* function is run.2011* @param {...*} var_args Additional arguments that are partially applied to the2012* function.2013* @return {!Function} A partially-applied form of the function goog.bind() was2014* invoked as a method of.2015* @template T2016* @private2017*/2018goog.bindNative_ = function(fn, selfObj, var_args) {2019return /** @type {!Function} */ (fn.call.apply(fn.bind, arguments));2020};202120222023/**2024* A pure-JS implementation of goog.bind.2025* @param {?function(this:T, ...)} fn A function to partially apply.2026* @param {T} selfObj Specifies the object which this should point to when the2027* function is run.2028* @param {...*} var_args Additional arguments that are partially applied to the2029* function.2030* @return {!Function} A partially-applied form of the function goog.bind() was2031* invoked as a method of.2032* @template T2033* @private2034*/2035goog.bindJs_ = function(fn, selfObj, var_args) {2036if (!fn) {2037throw new Error();2038}20392040if (arguments.length > 2) {2041var boundArgs = Array.prototype.slice.call(arguments, 2);2042return function() {2043// Prepend the bound arguments to the current arguments.2044var newArgs = Array.prototype.slice.call(arguments);2045Array.prototype.unshift.apply(newArgs, boundArgs);2046return fn.apply(selfObj, newArgs);2047};20482049} else {2050return function() {2051return fn.apply(selfObj, arguments);2052};2053}2054};205520562057/**2058* Partially applies this function to a particular 'this object' and zero or2059* more arguments. The result is a new function with some arguments of the first2060* function pre-filled and the value of this 'pre-specified'.2061*2062* Remaining arguments specified at call-time are appended to the pre-specified2063* ones.2064*2065* Also see: {@link #partial}.2066*2067* Usage:2068* <pre>var barMethBound = goog.bind(myFunction, myObj, 'arg1', 'arg2');2069* barMethBound('arg3', 'arg4');</pre>2070*2071* @param {?function(this:T, ...)} fn A function to partially apply.2072* @param {T} selfObj Specifies the object which this should point to when the2073* function is run.2074* @param {...*} var_args Additional arguments that are partially applied to the2075* function.2076* @return {!Function} A partially-applied form of the function goog.bind() was2077* invoked as a method of.2078* @template T2079* @suppress {deprecated} See above.2080*/2081goog.bind = function(fn, selfObj, var_args) {2082// TODO(nicksantos): narrow the type signature.2083if (Function.prototype.bind &&2084// NOTE(nicksantos): Somebody pulled base.js into the default Chrome2085// extension environment. This means that for Chrome extensions, they get2086// the implementation of Function.prototype.bind that calls goog.bind2087// instead of the native one. Even worse, we don't want to introduce a2088// circular dependency between goog.bind and Function.prototype.bind, so2089// we have to hack this to make sure it works correctly.2090Function.prototype.bind.toString().indexOf('native code') != -1) {2091goog.bind = goog.bindNative_;2092} else {2093goog.bind = goog.bindJs_;2094}2095return goog.bind.apply(null, arguments);2096};209720982099/**2100* Like goog.bind(), except that a 'this object' is not required. Useful when2101* the target function is already bound.2102*2103* Usage:2104* var g = goog.partial(f, arg1, arg2);2105* g(arg3, arg4);2106*2107* @param {Function} fn A function to partially apply.2108* @param {...*} var_args Additional arguments that are partially applied to fn.2109* @return {!Function} A partially-applied form of the function goog.partial()2110* was invoked as a method of.2111*/2112goog.partial = function(fn, var_args) {2113var args = Array.prototype.slice.call(arguments, 1);2114return function() {2115// Clone the array (with slice()) and append additional arguments2116// to the existing arguments.2117var newArgs = args.slice();2118newArgs.push.apply(newArgs, arguments);2119return fn.apply(this, newArgs);2120};2121};212221232124/**2125* Copies all the members of a source object to a target object. This method2126* does not work on all browsers for all objects that contain keys such as2127* toString or hasOwnProperty. Use goog.object.extend for this purpose.2128* @param {Object} target Target.2129* @param {Object} source Source.2130*/2131goog.mixin = function(target, source) {2132for (var x in source) {2133target[x] = source[x];2134}21352136// For IE7 or lower, the for-in-loop does not contain any properties that are2137// not enumerable on the prototype object (for example, isPrototypeOf from2138// Object.prototype) but also it will not include 'replace' on objects that2139// extend String and change 'replace' (not that it is common for anyone to2140// extend anything except Object).2141};214221432144/**2145* @return {number} An integer value representing the number of milliseconds2146* between midnight, January 1, 1970 and the current time.2147*/2148goog.now = (goog.TRUSTED_SITE && Date.now) || (function() {2149// Unary plus operator converts its operand to a number which in2150// the case of2151// a date is done by calling getTime().2152return +new Date();2153});215421552156/**2157* Evals JavaScript in the global scope. In IE this uses execScript, other2158* browsers use goog.global.eval. If goog.global.eval does not evaluate in the2159* global scope (for example, in Safari), appends a script tag instead.2160* Throws an exception if neither execScript or eval is defined.2161* @param {string} script JavaScript string.2162*/2163goog.globalEval = function(script) {2164if (goog.global.execScript) {2165goog.global.execScript(script, 'JavaScript');2166} else if (goog.global.eval) {2167// Test to see if eval works2168if (goog.evalWorksForGlobals_ == null) {2169goog.global.eval('var _evalTest_ = 1;');2170if (typeof goog.global['_evalTest_'] != 'undefined') {2171try {2172delete goog.global['_evalTest_'];2173} catch (ignore) {2174// Microsoft edge fails the deletion above in strict mode.2175}2176goog.evalWorksForGlobals_ = true;2177} else {2178goog.evalWorksForGlobals_ = false;2179}2180}21812182if (goog.evalWorksForGlobals_) {2183goog.global.eval(script);2184} else {2185/** @type {Document} */2186var doc = goog.global.document;2187var scriptElt =2188/** @type {!HTMLScriptElement} */ (doc.createElement('SCRIPT'));2189scriptElt.type = 'text/javascript';2190scriptElt.defer = false;2191// Note(user): can't use .innerHTML since "t('<test>')" will fail and2192// .text doesn't work in Safari 2. Therefore we append a text node.2193scriptElt.appendChild(doc.createTextNode(script));2194doc.body.appendChild(scriptElt);2195doc.body.removeChild(scriptElt);2196}2197} else {2198throw Error('goog.globalEval not available');2199}2200};220122022203/**2204* Indicates whether or not we can call 'eval' directly to eval code in the2205* global scope. Set to a Boolean by the first call to goog.globalEval (which2206* empirically tests whether eval works for globals). @see goog.globalEval2207* @type {?boolean}2208* @private2209*/2210goog.evalWorksForGlobals_ = null;221122122213/**2214* Optional map of CSS class names to obfuscated names used with2215* goog.getCssName().2216* @private {!Object<string, string>|undefined}2217* @see goog.setCssNameMapping2218*/2219goog.cssNameMapping_;222022212222/**2223* Optional obfuscation style for CSS class names. Should be set to either2224* 'BY_WHOLE' or 'BY_PART' if defined.2225* @type {string|undefined}2226* @private2227* @see goog.setCssNameMapping2228*/2229goog.cssNameMappingStyle_;2230223122322233/**2234* A hook for modifying the default behavior goog.getCssName. The function2235* if present, will recieve the standard output of the goog.getCssName as2236* its input.2237*2238* @type {(function(string):string)|undefined}2239*/2240goog.global.CLOSURE_CSS_NAME_MAP_FN;224122422243/**2244* Handles strings that are intended to be used as CSS class names.2245*2246* This function works in tandem with @see goog.setCssNameMapping.2247*2248* Without any mapping set, the arguments are simple joined with a hyphen and2249* passed through unaltered.2250*2251* When there is a mapping, there are two possible styles in which these2252* mappings are used. In the BY_PART style, each part (i.e. in between hyphens)2253* of the passed in css name is rewritten according to the map. In the BY_WHOLE2254* style, the full css name is looked up in the map directly. If a rewrite is2255* not specified by the map, the compiler will output a warning.2256*2257* When the mapping is passed to the compiler, it will replace calls to2258* goog.getCssName with the strings from the mapping, e.g.2259* var x = goog.getCssName('foo');2260* var y = goog.getCssName(this.baseClass, 'active');2261* becomes:2262* var x = 'foo';2263* var y = this.baseClass + '-active';2264*2265* If one argument is passed it will be processed, if two are passed only the2266* modifier will be processed, as it is assumed the first argument was generated2267* as a result of calling goog.getCssName.2268*2269* @param {string} className The class name.2270* @param {string=} opt_modifier A modifier to be appended to the class name.2271* @return {string} The class name or the concatenation of the class name and2272* the modifier.2273*/2274goog.getCssName = function(className, opt_modifier) {2275// String() is used for compatibility with compiled soy where the passed2276// className can be non-string objects.2277if (String(className).charAt(0) == '.') {2278throw new Error(2279'className passed in goog.getCssName must not start with ".".' +2280' You passed: ' + className);2281}22822283var getMapping = function(cssName) {2284return goog.cssNameMapping_[cssName] || cssName;2285};22862287var renameByParts = function(cssName) {2288// Remap all the parts individually.2289var parts = cssName.split('-');2290var mapped = [];2291for (var i = 0; i < parts.length; i++) {2292mapped.push(getMapping(parts[i]));2293}2294return mapped.join('-');2295};22962297var rename;2298if (goog.cssNameMapping_) {2299rename =2300goog.cssNameMappingStyle_ == 'BY_WHOLE' ? getMapping : renameByParts;2301} else {2302rename = function(a) {2303return a;2304};2305}23062307var result =2308opt_modifier ? className + '-' + rename(opt_modifier) : rename(className);23092310// The special CLOSURE_CSS_NAME_MAP_FN allows users to specify further2311// processing of the class name.2312if (goog.global.CLOSURE_CSS_NAME_MAP_FN) {2313return goog.global.CLOSURE_CSS_NAME_MAP_FN(result);2314}23152316return result;2317};231823192320/**2321* Sets the map to check when returning a value from goog.getCssName(). Example:2322* <pre>2323* goog.setCssNameMapping({2324* "goog": "a",2325* "disabled": "b",2326* });2327*2328* var x = goog.getCssName('goog');2329* // The following evaluates to: "a a-b".2330* goog.getCssName('goog') + ' ' + goog.getCssName(x, 'disabled')2331* </pre>2332* When declared as a map of string literals to string literals, the JSCompiler2333* will replace all calls to goog.getCssName() using the supplied map if the2334* --process_closure_primitives flag is set.2335*2336* @param {!Object} mapping A map of strings to strings where keys are possible2337* arguments to goog.getCssName() and values are the corresponding values2338* that should be returned.2339* @param {string=} opt_style The style of css name mapping. There are two valid2340* options: 'BY_PART', and 'BY_WHOLE'.2341* @see goog.getCssName for a description.2342*/2343goog.setCssNameMapping = function(mapping, opt_style) {2344goog.cssNameMapping_ = mapping;2345goog.cssNameMappingStyle_ = opt_style;2346};234723482349/**2350* To use CSS renaming in compiled mode, one of the input files should have a2351* call to goog.setCssNameMapping() with an object literal that the JSCompiler2352* can extract and use to replace all calls to goog.getCssName(). In uncompiled2353* mode, JavaScript code should be loaded before this base.js file that declares2354* a global variable, CLOSURE_CSS_NAME_MAPPING, which is used below. This is2355* to ensure that the mapping is loaded before any calls to goog.getCssName()2356* are made in uncompiled mode.2357*2358* A hook for overriding the CSS name mapping.2359* @type {!Object<string, string>|undefined}2360*/2361goog.global.CLOSURE_CSS_NAME_MAPPING;236223632364if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) {2365// This does not call goog.setCssNameMapping() because the JSCompiler2366// requires that goog.setCssNameMapping() be called with an object literal.2367goog.cssNameMapping_ = goog.global.CLOSURE_CSS_NAME_MAPPING;2368}236923702371/**2372* Gets a localized message.2373*2374* This function is a compiler primitive. If you give the compiler a localized2375* message bundle, it will replace the string at compile-time with a localized2376* version, and expand goog.getMsg call to a concatenated string.2377*2378* Messages must be initialized in the form:2379* <code>2380* var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'});2381* </code>2382*2383* This function produces a string which should be treated as plain text. Use2384* {@link goog.html.SafeHtmlFormatter} in conjunction with goog.getMsg to2385* produce SafeHtml.2386*2387* @param {string} str Translatable string, places holders in the form {$foo}.2388* @param {Object<string, string>=} opt_values Maps place holder name to value.2389* @return {string} message with placeholders filled.2390*/2391goog.getMsg = function(str, opt_values) {2392if (opt_values) {2393str = str.replace(/\{\$([^}]+)}/g, function(match, key) {2394return (opt_values != null && key in opt_values) ? opt_values[key] :2395match;2396});2397}2398return str;2399};240024012402/**2403* Gets a localized message. If the message does not have a translation, gives a2404* fallback message.2405*2406* This is useful when introducing a new message that has not yet been2407* translated into all languages.2408*2409* This function is a compiler primitive. Must be used in the form:2410* <code>var x = goog.getMsgWithFallback(MSG_A, MSG_B);</code>2411* where MSG_A and MSG_B were initialized with goog.getMsg.2412*2413* @param {string} a The preferred message.2414* @param {string} b The fallback message.2415* @return {string} The best translated message.2416*/2417goog.getMsgWithFallback = function(a, b) {2418return a;2419};242024212422/**2423* Exposes an unobfuscated global namespace path for the given object.2424* Note that fields of the exported object *will* be obfuscated, unless they are2425* exported in turn via this function or goog.exportProperty.2426*2427* Also handy for making public items that are defined in anonymous closures.2428*2429* ex. goog.exportSymbol('public.path.Foo', Foo);2430*2431* ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction);2432* public.path.Foo.staticFunction();2433*2434* ex. goog.exportSymbol('public.path.Foo.prototype.myMethod',2435* Foo.prototype.myMethod);2436* new public.path.Foo().myMethod();2437*2438* @param {string} publicPath Unobfuscated name to export.2439* @param {*} object Object the name should point to.2440* @param {Object=} opt_objectToExportTo The object to add the path to; default2441* is goog.global.2442*/2443goog.exportSymbol = function(publicPath, object, opt_objectToExportTo) {2444goog.exportPath_(publicPath, object, opt_objectToExportTo);2445};244624472448/**2449* Exports a property unobfuscated into the object's namespace.2450* ex. goog.exportProperty(Foo, 'staticFunction', Foo.staticFunction);2451* ex. goog.exportProperty(Foo.prototype, 'myMethod', Foo.prototype.myMethod);2452* @param {Object} object Object whose static property is being exported.2453* @param {string} publicName Unobfuscated name to export.2454* @param {*} symbol Object the name should point to.2455*/2456goog.exportProperty = function(object, publicName, symbol) {2457object[publicName] = symbol;2458};245924602461/**2462* Inherit the prototype methods from one constructor into another.2463*2464* Usage:2465* <pre>2466* function ParentClass(a, b) { }2467* ParentClass.prototype.foo = function(a) { };2468*2469* function ChildClass(a, b, c) {2470* ChildClass.base(this, 'constructor', a, b);2471* }2472* goog.inherits(ChildClass, ParentClass);2473*2474* var child = new ChildClass('a', 'b', 'see');2475* child.foo(); // This works.2476* </pre>2477*2478* @param {!Function} childCtor Child class.2479* @param {!Function} parentCtor Parent class.2480*/2481goog.inherits = function(childCtor, parentCtor) {2482/** @constructor */2483function tempCtor() {}2484tempCtor.prototype = parentCtor.prototype;2485childCtor.superClass_ = parentCtor.prototype;2486childCtor.prototype = new tempCtor();2487/** @override */2488childCtor.prototype.constructor = childCtor;24892490/**2491* Calls superclass constructor/method.2492*2493* This function is only available if you use goog.inherits to2494* express inheritance relationships between classes.2495*2496* NOTE: This is a replacement for goog.base and for superClass_2497* property defined in childCtor.2498*2499* @param {!Object} me Should always be "this".2500* @param {string} methodName The method name to call. Calling2501* superclass constructor can be done with the special string2502* 'constructor'.2503* @param {...*} var_args The arguments to pass to superclass2504* method/constructor.2505* @return {*} The return value of the superclass method/constructor.2506*/2507childCtor.base = function(me, methodName, var_args) {2508// Copying using loop to avoid deop due to passing arguments object to2509// function. This is faster in many JS engines as of late 2014.2510var args = new Array(arguments.length - 2);2511for (var i = 2; i < arguments.length; i++) {2512args[i - 2] = arguments[i];2513}2514return parentCtor.prototype[methodName].apply(me, args);2515};2516};251725182519/**2520* Call up to the superclass.2521*2522* If this is called from a constructor, then this calls the superclass2523* constructor with arguments 1-N.2524*2525* If this is called from a prototype method, then you must pass the name of the2526* method as the second argument to this function. If you do not, you will get a2527* runtime error. This calls the superclass' method with arguments 2-N.2528*2529* This function only works if you use goog.inherits to express inheritance2530* relationships between your classes.2531*2532* This function is a compiler primitive. At compile-time, the compiler will do2533* macro expansion to remove a lot of the extra overhead that this function2534* introduces. The compiler will also enforce a lot of the assumptions that this2535* function makes, and treat it as a compiler error if you break them.2536*2537* @param {!Object} me Should always be "this".2538* @param {*=} opt_methodName The method name if calling a super method.2539* @param {...*} var_args The rest of the arguments.2540* @return {*} The return value of the superclass method.2541* @suppress {es5Strict} This method can not be used in strict mode, but2542* all Closure Library consumers must depend on this file.2543* @deprecated goog.base is not strict mode compatible. Prefer the static2544* "base" method added to the constructor by goog.inherits2545* or ES6 classes and the "super" keyword.2546*/2547goog.base = function(me, opt_methodName, var_args) {2548var caller = arguments.callee.caller;25492550if (goog.STRICT_MODE_COMPATIBLE || (goog.DEBUG && !caller)) {2551throw Error(2552'arguments.caller not defined. goog.base() cannot be used ' +2553'with strict mode code. See ' +2554'http://www.ecma-international.org/ecma-262/5.1/#sec-C');2555}25562557if (caller.superClass_) {2558// Copying using loop to avoid deop due to passing arguments object to2559// function. This is faster in many JS engines as of late 2014.2560var ctorArgs = new Array(arguments.length - 1);2561for (var i = 1; i < arguments.length; i++) {2562ctorArgs[i - 1] = arguments[i];2563}2564// This is a constructor. Call the superclass constructor.2565return caller.superClass_.constructor.apply(me, ctorArgs);2566}25672568// Copying using loop to avoid deop due to passing arguments object to2569// function. This is faster in many JS engines as of late 2014.2570var args = new Array(arguments.length - 2);2571for (var i = 2; i < arguments.length; i++) {2572args[i - 2] = arguments[i];2573}2574var foundCaller = false;2575for (var ctor = me.constructor; ctor;2576ctor = ctor.superClass_ && ctor.superClass_.constructor) {2577if (ctor.prototype[opt_methodName] === caller) {2578foundCaller = true;2579} else if (foundCaller) {2580return ctor.prototype[opt_methodName].apply(me, args);2581}2582}25832584// If we did not find the caller in the prototype chain, then one of two2585// things happened:2586// 1) The caller is an instance method.2587// 2) This method was not called by the right caller.2588if (me[opt_methodName] === caller) {2589return me.constructor.prototype[opt_methodName].apply(me, args);2590} else {2591throw Error(2592'goog.base called from a method of one name ' +2593'to a method of a different name');2594}2595};259625972598/**2599* Allow for aliasing within scope functions. This function exists for2600* uncompiled code - in compiled code the calls will be inlined and the aliases2601* applied. In uncompiled code the function is simply run since the aliases as2602* written are valid JavaScript.2603*2604*2605* @param {function()} fn Function to call. This function can contain aliases2606* to namespaces (e.g. "var dom = goog.dom") or classes2607* (e.g. "var Timer = goog.Timer").2608*/2609goog.scope = function(fn) {2610if (goog.isInModuleLoader_()) {2611throw Error('goog.scope is not supported within a goog.module.');2612}2613fn.call(goog.global);2614};261526162617/*2618* To support uncompiled, strict mode bundles that use eval to divide source2619* like so:2620* eval('someSource;//# sourceUrl sourcefile.js');2621* We need to export the globally defined symbols "goog" and "COMPILED".2622* Exporting "goog" breaks the compiler optimizations, so we required that2623* be defined externally.2624* NOTE: We don't use goog.exportSymbol here because we don't want to trigger2625* extern generation when that compiler option is enabled.2626*/2627if (!COMPILED) {2628goog.global['COMPILED'] = COMPILED;2629}263026312632//==============================================================================2633// goog.defineClass implementation2634//==============================================================================263526362637/**2638* Creates a restricted form of a Closure "class":2639* - from the compiler's perspective, the instance returned from the2640* constructor is sealed (no new properties may be added). This enables2641* better checks.2642* - the compiler will rewrite this definition to a form that is optimal2643* for type checking and optimization (initially this will be a more2644* traditional form).2645*2646* @param {Function} superClass The superclass, Object or null.2647* @param {goog.defineClass.ClassDescriptor} def2648* An object literal describing2649* the class. It may have the following properties:2650* "constructor": the constructor function2651* "statics": an object literal containing methods to add to the constructor2652* as "static" methods or a function that will receive the constructor2653* function as its only parameter to which static properties can2654* be added.2655* all other properties are added to the prototype.2656* @return {!Function} The class constructor.2657*/2658goog.defineClass = function(superClass, def) {2659// TODO(johnlenz): consider making the superClass an optional parameter.2660var constructor = def.constructor;2661var statics = def.statics;2662// Wrap the constructor prior to setting up the prototype and static methods.2663if (!constructor || constructor == Object.prototype.constructor) {2664constructor = function() {2665throw Error('cannot instantiate an interface (no constructor defined).');2666};2667}26682669var cls = goog.defineClass.createSealingConstructor_(constructor, superClass);2670if (superClass) {2671goog.inherits(cls, superClass);2672}26732674// Remove all the properties that should not be copied to the prototype.2675delete def.constructor;2676delete def.statics;26772678goog.defineClass.applyProperties_(cls.prototype, def);2679if (statics != null) {2680if (statics instanceof Function) {2681statics(cls);2682} else {2683goog.defineClass.applyProperties_(cls, statics);2684}2685}26862687return cls;2688};268926902691/**2692* @typedef {{2693* constructor: (!Function|undefined),2694* statics: (Object|undefined|function(Function):void)2695* }}2696*/2697goog.defineClass.ClassDescriptor;269826992700/**2701* @define {boolean} Whether the instances returned by goog.defineClass should2702* be sealed when possible.2703*2704* When sealing is disabled the constructor function will not be wrapped by2705* goog.defineClass, making it incompatible with ES6 class methods.2706*/2707goog.define('goog.defineClass.SEAL_CLASS_INSTANCES', goog.DEBUG);270827092710/**2711* If goog.defineClass.SEAL_CLASS_INSTANCES is enabled and Object.seal is2712* defined, this function will wrap the constructor in a function that seals the2713* results of the provided constructor function.2714*2715* @param {!Function} ctr The constructor whose results maybe be sealed.2716* @param {Function} superClass The superclass constructor.2717* @return {!Function} The replacement constructor.2718* @private2719*/2720goog.defineClass.createSealingConstructor_ = function(ctr, superClass) {2721if (!goog.defineClass.SEAL_CLASS_INSTANCES) {2722// Do now wrap the constructor when sealing is disabled. Angular code2723// depends on this for injection to work properly.2724return ctr;2725}27262727// Compute whether the constructor is sealable at definition time, rather2728// than when the instance is being constructed.2729var superclassSealable = !goog.defineClass.isUnsealable_(superClass);27302731/**2732* @this {Object}2733* @return {?}2734*/2735var wrappedCtr = function() {2736// Don't seal an instance of a subclass when it calls the constructor of2737// its super class as there is most likely still setup to do.2738var instance = ctr.apply(this, arguments) || this;2739instance[goog.UID_PROPERTY_] = instance[goog.UID_PROPERTY_];27402741if (this.constructor === wrappedCtr && superclassSealable &&2742Object.seal instanceof Function) {2743Object.seal(instance);2744}2745return instance;2746};27472748return wrappedCtr;2749};275027512752/**2753* @param {Function} ctr The constructor to test.2754* @return {boolean} Whether the constructor has been tagged as unsealable2755* using goog.tagUnsealableClass.2756* @private2757*/2758goog.defineClass.isUnsealable_ = function(ctr) {2759return ctr && ctr.prototype &&2760ctr.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_];2761};276227632764// TODO(johnlenz): share these values with the goog.object2765/**2766* The names of the fields that are defined on Object.prototype.2767* @type {!Array<string>}2768* @private2769* @const2770*/2771goog.defineClass.OBJECT_PROTOTYPE_FIELDS_ = [2772'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',2773'toLocaleString', 'toString', 'valueOf'2774];277527762777// TODO(johnlenz): share this function with the goog.object2778/**2779* @param {!Object} target The object to add properties to.2780* @param {!Object} source The object to copy properties from.2781* @private2782*/2783goog.defineClass.applyProperties_ = function(target, source) {2784// TODO(johnlenz): update this to support ES5 getters/setters27852786var key;2787for (key in source) {2788if (Object.prototype.hasOwnProperty.call(source, key)) {2789target[key] = source[key];2790}2791}27922793// For IE the for-in-loop does not contain any properties that are not2794// enumerable on the prototype object (for example isPrototypeOf from2795// Object.prototype) and it will also not include 'replace' on objects that2796// extend String and change 'replace' (not that it is common for anyone to2797// extend anything except Object).2798for (var i = 0; i < goog.defineClass.OBJECT_PROTOTYPE_FIELDS_.length; i++) {2799key = goog.defineClass.OBJECT_PROTOTYPE_FIELDS_[i];2800if (Object.prototype.hasOwnProperty.call(source, key)) {2801target[key] = source[key];2802}2803}2804};280528062807/**2808* Sealing classes breaks the older idiom of assigning properties on the2809* prototype rather than in the constructor. As such, goog.defineClass2810* must not seal subclasses of these old-style classes until they are fixed.2811* Until then, this marks a class as "broken", instructing defineClass2812* not to seal subclasses.2813* @param {!Function} ctr The legacy constructor to tag as unsealable.2814*/2815goog.tagUnsealableClass = function(ctr) {2816if (!COMPILED && goog.defineClass.SEAL_CLASS_INSTANCES) {2817ctr.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_] = true;2818}2819};282028212822/**2823* Name for unsealable tag property.2824* @const @private {string}2825*/2826goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_ = 'goog_defineClass_legacy_unsealable';282728282829/**2830* Returns a newly created map from language mode string to a boolean2831* indicating whether transpilation should be done for that mode.2832*2833* Guaranteed invariant:2834* For any two modes, l1 and l2 where l2 is a newer mode than l1,2835* `map[l1] == true` implies that `map[l2] == true`.2836* @private2837* @return {!Object<string, boolean>}2838*/2839goog.createRequiresTranspilation_ = function() {2840var /** !Object<string, boolean> */ requiresTranspilation = {'es3': false};2841var transpilationRequiredForAllLaterModes = false;28422843/**2844* Adds an entry to requiresTranspliation for the given language mode.2845*2846* IMPORTANT: Calls must be made in order from oldest to newest language2847* mode.2848* @param {string} modeName2849* @param {function(): boolean} isSupported Returns true if the JS engine2850* supports the given mode.2851*/2852function addNewerLanguageTranspilationCheck(modeName, isSupported) {2853if (transpilationRequiredForAllLaterModes) {2854requiresTranspilation[modeName] = true;2855} else if (isSupported()) {2856requiresTranspilation[modeName] = false;2857} else {2858requiresTranspilation[modeName] = true;2859transpilationRequiredForAllLaterModes = true;2860}2861}28622863/**2864* Does the given code evaluate without syntax errors and return a truthy2865* result?2866*/2867function /** boolean */ evalCheck(/** string */ code) {2868try {2869return !!eval(code);2870} catch (ignored) {2871return false;2872}2873}28742875var userAgent = goog.global.navigator && goog.global.navigator.userAgent ?2876goog.global.navigator.userAgent :2877'';28782879// Identify ES3-only browsers by their incorrect treatment of commas.2880addNewerLanguageTranspilationCheck('es5', function() {2881return evalCheck('[1,].length==1');2882});2883addNewerLanguageTranspilationCheck('es6', function() {2884// Edge has a non-deterministic (i.e., not reproducible) bug with ES6:2885// https://github.com/Microsoft/ChakraCore/issues/1496.2886var re = /Edge\/(\d+)(\.\d)*/i;2887var edgeUserAgent = userAgent.match(re);2888if (edgeUserAgent && Number(edgeUserAgent[1]) < 15) {2889return false;2890}2891// Test es6: [FF50 (?), Edge 14 (?), Chrome 50]2892// (a) default params (specifically shadowing locals),2893// (b) destructuring, (c) block-scoped functions,2894// (d) for-of (const), (e) new.target/Reflect.construct2895var es6fullTest =2896'class X{constructor(){if(new.target!=String)throw 1;this.x=42}}' +2897'let q=Reflect.construct(X,[],String);if(q.x!=42||!(q instanceof ' +2898'String))throw 1;for(const a of[2,3]){if(a==2)continue;function ' +2899'f(z={a}){let a=0;return z.a}{function f(){return 0;}}return f()' +2900'==3}';29012902return evalCheck('(()=>{"use strict";' + es6fullTest + '})()');2903});2904// TODO(joeltine): Remove es6-impl references for b/31340605.2905// Consider es6-impl (widely-implemented es6 features) to be supported2906// whenever es6 is supported. Technically es6-impl is a lower level of2907// support than es6, but we don't have tests specifically for it.2908addNewerLanguageTranspilationCheck('es6-impl', function() {2909return true;2910});2911// ** and **= are the only new features in 'es7'2912addNewerLanguageTranspilationCheck('es7', function() {2913return evalCheck('2 ** 2 == 4');2914});2915// async functions are the only new features in 'es8'2916addNewerLanguageTranspilationCheck('es8', function() {2917return evalCheck('async () => 1, true');2918});2919return requiresTranspilation;2920};292129222923