1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027 |
- /**
- * @license
- * Copyright The Closure Library Authors.
- * SPDX-License-Identifier: Apache-2.0
- */
- /**
- * @fileoverview Bootstrap for the Google JS Library (Closure).
- *
- * In uncompiled mode base.js will attempt to load Closure's deps file, unless
- * the global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects
- * to include their own deps file(s) from different locations.
- *
- * Avoid including base.js more than once. This is strictly discouraged and not
- * supported. goog.require(...) won't work properly in that case.
- *
- * @provideGoog
- */
- /**
- * @define {boolean} Overridden to true by the compiler.
- */
- var COMPILED = false;
- /**
- * Base namespace for the Closure library. Checks to see goog is already
- * defined in the current scope before assigning to prevent clobbering if
- * base.js is loaded more than once.
- *
- * @const
- */
- var goog = goog || {};
- /**
- * Reference to the global object.
- * https://www.ecma-international.org/ecma-262/9.0/index.html#sec-global-object
- *
- * More info on this implementation here:
- * https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI/edit
- *
- * @const
- * @suppress {undefinedVars} self won't be referenced unless `this` is falsy.
- * @type {!Global}
- */
- goog.global =
- // Check `this` first for backwards compatibility.
- // Valid unless running as an ES module or in a function wrapper called
- // without setting `this` properly.
- // Note that base.js can't usefully be imported as an ES module, but it may
- // be compiled into bundles that are loadable as ES modules.
- this ||
- // https://developer.mozilla.org/en-US/docs/Web/API/Window/self
- // For in-page browser environments and workers.
- self;
- /**
- * A hook for overriding the define values in uncompiled mode.
- *
- * In uncompiled mode, `CLOSURE_UNCOMPILED_DEFINES` may be defined before
- * loading base.js. If a key is defined in `CLOSURE_UNCOMPILED_DEFINES`,
- * `goog.define` will use the value instead of the default value. This
- * allows flags to be overwritten without compilation (this is normally
- * accomplished with the compiler's "define" flag).
- *
- * Example:
- * <pre>
- * var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false};
- * </pre>
- *
- * @type {Object<string, (string|number|boolean)>|undefined}
- */
- goog.global.CLOSURE_UNCOMPILED_DEFINES;
- /**
- * A hook for overriding the define values in uncompiled or compiled mode,
- * like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In
- * uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence.
- *
- * Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or
- * string literals or the compiler will emit an error.
- *
- * While any @define value may be set, only those set with goog.define will be
- * effective for uncompiled code.
- *
- * Example:
- * <pre>
- * var CLOSURE_DEFINES = {'goog.DEBUG': false} ;
- * </pre>
- *
- * @type {Object<string, (string|number|boolean)>|undefined}
- */
- goog.global.CLOSURE_DEFINES;
- /**
- * Builds an object structure for the provided namespace path, ensuring that
- * names that already exist are not overwritten. For example:
- * "a.b.c" -> a = {};a.b={};a.b.c={};
- * Used by goog.provide and goog.exportSymbol.
- * @param {string} name name of the object that this file defines.
- * @param {*=} opt_object the object to expose at the end of the path.
- * @param {Object=} opt_objectToExportTo The object to add the path to; default
- * is `goog.global`.
- * @private
- */
- goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) {
- var parts = name.split('.');
- var cur = opt_objectToExportTo || goog.global;
- // Internet Explorer exhibits strange behavior when throwing errors from
- // methods externed in this manner. See the testExportSymbolExceptions in
- // base_test.html for an example.
- if (!(parts[0] in cur) && typeof cur.execScript != 'undefined') {
- cur.execScript('var ' + parts[0]);
- }
- for (var part; parts.length && (part = parts.shift());) {
- if (!parts.length && opt_object !== undefined) {
- // last part and we have an object; use it
- cur[part] = opt_object;
- } else if (cur[part] && cur[part] !== Object.prototype[part]) {
- cur = cur[part];
- } else {
- cur = cur[part] = {};
- }
- }
- };
- /**
- * Defines a named value. In uncompiled mode, the value is retrieved from
- * CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and
- * has the property specified, and otherwise used the defined defaultValue.
- * When compiled the default can be overridden using the compiler options or the
- * value set in the CLOSURE_DEFINES object. Returns the defined value so that it
- * can be used safely in modules. Note that the value type MUST be either
- * boolean, number, or string.
- *
- * @param {string} name The distinguished name to provide.
- * @param {T} defaultValue
- * @return {T} The defined value.
- * @template T
- */
- goog.define = function(name, defaultValue) {
- var value = defaultValue;
- if (!COMPILED) {
- var uncompiledDefines = goog.global.CLOSURE_UNCOMPILED_DEFINES;
- var defines = goog.global.CLOSURE_DEFINES;
- if (uncompiledDefines &&
- // Anti DOM-clobbering runtime check (b/37736576).
- /** @type {?} */ (uncompiledDefines).nodeType === undefined &&
- Object.prototype.hasOwnProperty.call(uncompiledDefines, name)) {
- value = uncompiledDefines[name];
- } else if (
- defines &&
- // Anti DOM-clobbering runtime check (b/37736576).
- /** @type {?} */ (defines).nodeType === undefined &&
- Object.prototype.hasOwnProperty.call(defines, name)) {
- value = defines[name];
- }
- }
- return value;
- };
- /**
- * @define {number} Integer year indicating the set of browser features that are
- * guaranteed to be present. This is defined to include exactly features that
- * work correctly on all "modern" browsers that are stable on January 1 of the
- * specified year. For example,
- * ```js
- * if (goog.FEATURESET_YEAR >= 2019) {
- * // use APIs known to be available on all major stable browsers Jan 1, 2019
- * } else {
- * // polyfill for older browsers
- * }
- * ```
- * This is intended to be the primary define for removing
- * unnecessary browser compatibility code (such as ponyfills and workarounds),
- * and should inform the default value for most other defines:
- * ```js
- * const ASSUME_NATIVE_PROMISE =
- * goog.define('ASSUME_NATIVE_PROMISE', goog.FEATURESET_YEAR >= 2016);
- * ```
- *
- * The default assumption is that IE9 is the lowest supported browser, which was
- * first available Jan 1, 2012.
- *
- * TODO(user): Reference more thorough documentation when it's available.
- */
- goog.FEATURESET_YEAR = goog.define('goog.FEATURESET_YEAR', 2012);
- /**
- * @define {boolean} DEBUG is provided as a convenience so that debugging code
- * that should not be included in a production. It can be easily stripped
- * by specifying --define goog.DEBUG=false to the Closure Compiler aka
- * JSCompiler. For example, most toString() methods should be declared inside an
- * "if (goog.DEBUG)" conditional because they are generally used for debugging
- * purposes and it is difficult for the JSCompiler to statically determine
- * whether they are used.
- */
- goog.DEBUG = goog.define('goog.DEBUG', true);
- /**
- * @define {string} LOCALE defines the locale being used for compilation. It is
- * used to select locale specific data to be compiled in js binary. BUILD rule
- * can specify this value by "--define goog.LOCALE=<locale_name>" as a compiler
- * option.
- *
- * Take into account that the locale code format is important. You should use
- * the canonical Unicode format with hyphen as a delimiter. Language must be
- * lowercase, Language Script - Capitalized, Region - UPPERCASE.
- * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN.
- *
- * See more info about locale codes here:
- * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers
- *
- * For language codes you should use values defined by ISO 693-1. See it here
- * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from
- * this rule: the Hebrew language. For legacy reasons the old code (iw) should
- * be used instead of the new code (he).
- *
- */
- goog.LOCALE = goog.define('goog.LOCALE', 'en'); // default to en
- /**
- * @define {boolean} Whether this code is running on trusted sites.
- *
- * On untrusted sites, several native functions can be defined or overridden by
- * external libraries like Prototype, Datejs, and JQuery and setting this flag
- * to false forces closure to use its own implementations when possible.
- *
- * If your JavaScript can be loaded by a third party site and you are wary about
- * relying on non-standard implementations, specify
- * "--define goog.TRUSTED_SITE=false" to the compiler.
- */
- goog.TRUSTED_SITE = goog.define('goog.TRUSTED_SITE', true);
- /**
- * @define {boolean} Whether a project is expected to be running in strict mode.
- *
- * This define can be used to trigger alternate implementations compatible with
- * running in EcmaScript Strict mode or warn about unavailable functionality.
- * @see https://goo.gl/PudQ4y
- *
- */
- goog.STRICT_MODE_COMPATIBLE = goog.define('goog.STRICT_MODE_COMPATIBLE', false);
- /**
- * @define {boolean} Whether code that calls {@link goog.setTestOnly} should
- * be disallowed in the compilation unit.
- */
- goog.DISALLOW_TEST_ONLY_CODE =
- goog.define('goog.DISALLOW_TEST_ONLY_CODE', COMPILED && !goog.DEBUG);
- /**
- * @define {boolean} Whether to use a Chrome app CSP-compliant method for
- * loading scripts via goog.require. @see appendScriptSrcNode_.
- */
- goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING =
- goog.define('goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING', false);
- /**
- * Defines a namespace in Closure.
- *
- * A namespace may only be defined once in a codebase. It may be defined using
- * goog.provide() or goog.module().
- *
- * The presence of one or more goog.provide() calls in a file indicates
- * that the file defines the given objects/namespaces.
- * Provided symbols must not be null or undefined.
- *
- * In addition, goog.provide() creates the object stubs for a namespace
- * (for example, goog.provide("goog.foo.bar") will create the object
- * goog.foo.bar if it does not already exist).
- *
- * Build tools also scan for provide/require/module statements
- * to discern dependencies, build dependency files (see deps.js), etc.
- *
- * @see goog.require
- * @see goog.module
- * @param {string} name Namespace provided by this file in the form
- * "goog.package.part".
- */
- goog.provide = function(name) {
- if (goog.isInModuleLoader_()) {
- throw new Error('goog.provide cannot be used within a module.');
- }
- if (!COMPILED) {
- // Ensure that the same namespace isn't provided twice.
- // A goog.module/goog.provide maps a goog.require to a specific file
- if (goog.isProvided_(name)) {
- throw new Error('Namespace "' + name + '" already declared.');
- }
- }
- goog.constructNamespace_(name);
- };
- /**
- * @param {string} name Namespace provided by this file in the form
- * "goog.package.part".
- * @param {Object=} opt_obj The object to embed in the namespace.
- * @private
- */
- goog.constructNamespace_ = function(name, opt_obj) {
- if (!COMPILED) {
- delete goog.implicitNamespaces_[name];
- var namespace = name;
- while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) {
- if (goog.getObjectByName(namespace)) {
- break;
- }
- goog.implicitNamespaces_[namespace] = true;
- }
- }
- goog.exportPath_(name, opt_obj);
- };
- /**
- * Returns CSP nonce, if set for any script tag.
- * @param {?Window=} opt_window The window context used to retrieve the nonce.
- * Defaults to global context.
- * @return {string} CSP nonce or empty string if no nonce is present.
- */
- goog.getScriptNonce = function(opt_window) {
- if (opt_window && opt_window != goog.global) {
- return goog.getScriptNonce_(opt_window.document);
- }
- if (goog.cspNonce_ === null) {
- goog.cspNonce_ = goog.getScriptNonce_(goog.global.document);
- }
- return goog.cspNonce_;
- };
- /**
- * According to the CSP3 spec a nonce must be a valid base64 string.
- * @see https://www.w3.org/TR/CSP3/#grammardef-base64-value
- * @private @const
- */
- goog.NONCE_PATTERN_ = /^[\w+/_-]+[=]{0,2}$/;
- /**
- * @private {?string}
- */
- goog.cspNonce_ = null;
- /**
- * Returns CSP nonce, if set for any script tag.
- * @param {!Document} doc
- * @return {string} CSP nonce or empty string if no nonce is present.
- * @private
- */
- goog.getScriptNonce_ = function(doc) {
- var script = doc.querySelector && doc.querySelector('script[nonce]');
- if (script) {
- // Try to get the nonce from the IDL property first, because browsers that
- // implement additional nonce protection features (currently only Chrome) to
- // prevent nonce stealing via CSS do not expose the nonce via attributes.
- // See https://github.com/whatwg/html/issues/2369
- var nonce = script['nonce'] || script.getAttribute('nonce');
- if (nonce && goog.NONCE_PATTERN_.test(nonce)) {
- return nonce;
- }
- }
- return '';
- };
- /**
- * Module identifier validation regexp.
- * Note: This is a conservative check, it is very possible to be more lenient,
- * the primary exclusion here is "/" and "\" and a leading ".", these
- * restrictions are intended to leave the door open for using goog.require
- * with relative file paths rather than module identifiers.
- * @private
- */
- goog.VALID_MODULE_RE_ = /^[a-zA-Z_$][a-zA-Z0-9._$]*$/;
- /**
- * Defines a module in Closure.
- *
- * Marks that this file must be loaded as a module and claims the namespace.
- *
- * A namespace may only be defined once in a codebase. It may be defined using
- * goog.provide() or goog.module().
- *
- * goog.module() has three requirements:
- * - goog.module may not be used in the same file as goog.provide.
- * - goog.module must be the first statement in the file.
- * - only one goog.module is allowed per file.
- *
- * When a goog.module annotated file is loaded, it is enclosed in
- * a strict function closure. This means that:
- * - any variables declared in a goog.module file are private to the file
- * (not global), though the compiler is expected to inline the module.
- * - The code must obey all the rules of "strict" JavaScript.
- * - the file will be marked as "use strict"
- *
- * NOTE: unlike goog.provide, goog.module does not declare any symbols by
- * itself. If declared symbols are desired, use
- * goog.module.declareLegacyNamespace().
- *
- *
- * See the public goog.module proposal: http://goo.gl/Va1hin
- *
- * @param {string} name Namespace provided by this file in the form
- * "goog.package.part", is expected but not required.
- * @return {void}
- */
- goog.module = function(name) {
- if (typeof name !== 'string' || !name ||
- name.search(goog.VALID_MODULE_RE_) == -1) {
- throw new Error('Invalid module identifier');
- }
- if (!goog.isInGoogModuleLoader_()) {
- throw new Error(
- 'Module ' + name + ' has been loaded incorrectly. Note, ' +
- 'modules cannot be loaded as normal scripts. They require some kind of ' +
- 'pre-processing step. You\'re likely trying to load a module via a ' +
- 'script tag or as a part of a concatenated bundle without rewriting the ' +
- 'module. For more info see: ' +
- 'https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.');
- }
- if (goog.moduleLoaderState_.moduleName) {
- throw new Error('goog.module may only be called once per module.');
- }
- // Store the module name for the loader.
- goog.moduleLoaderState_.moduleName = name;
- if (!COMPILED) {
- // Ensure that the same namespace isn't provided twice.
- // A goog.module/goog.provide maps a goog.require to a specific file
- if (goog.isProvided_(name)) {
- throw new Error('Namespace "' + name + '" already declared.');
- }
- delete goog.implicitNamespaces_[name];
- }
- };
- /**
- * @param {string} name The module identifier.
- * @return {?} The module exports for an already loaded module or null.
- *
- * Note: This is not an alternative to goog.require, it does not
- * indicate a hard dependency, instead it is used to indicate
- * an optional dependency or to access the exports of a module
- * that has already been loaded.
- * @suppress {missingProvide}
- */
- goog.module.get = function(name) {
- return goog.module.getInternal_(name);
- };
- /**
- * @param {string} name The module identifier.
- * @return {?} The module exports for an already loaded module or null.
- * @private
- */
- goog.module.getInternal_ = function(name) {
- if (!COMPILED) {
- if (name in goog.loadedModules_) {
- return goog.loadedModules_[name].exports;
- } else if (!goog.implicitNamespaces_[name]) {
- var ns = goog.getObjectByName(name);
- return ns != null ? ns : null;
- }
- }
- return null;
- };
- /**
- * Types of modules the debug loader can load.
- * @enum {string}
- */
- goog.ModuleType = {
- ES6: 'es6',
- GOOG: 'goog'
- };
- /**
- * @private {?{
- * moduleName: (string|undefined),
- * declareLegacyNamespace:boolean,
- * type: ?goog.ModuleType
- * }}
- */
- goog.moduleLoaderState_ = null;
- /**
- * @private
- * @return {boolean} Whether a goog.module or an es6 module is currently being
- * initialized.
- */
- goog.isInModuleLoader_ = function() {
- return goog.isInGoogModuleLoader_() || goog.isInEs6ModuleLoader_();
- };
- /**
- * @private
- * @return {boolean} Whether a goog.module is currently being initialized.
- */
- goog.isInGoogModuleLoader_ = function() {
- return !!goog.moduleLoaderState_ &&
- goog.moduleLoaderState_.type == goog.ModuleType.GOOG;
- };
- /**
- * @private
- * @return {boolean} Whether an es6 module is currently being initialized.
- */
- goog.isInEs6ModuleLoader_ = function() {
- var inLoader = !!goog.moduleLoaderState_ &&
- goog.moduleLoaderState_.type == goog.ModuleType.ES6;
- if (inLoader) {
- return true;
- }
- var jscomp = goog.global['$jscomp'];
- if (jscomp) {
- // jscomp may not have getCurrentModulePath if this is a compiled bundle
- // that has some of the runtime, but not all of it. This can happen if
- // optimizations are turned on so the unused runtime is removed but renaming
- // and Closure pass are off (so $jscomp is still named $jscomp and the
- // goog.provide/require calls still exist).
- if (typeof jscomp.getCurrentModulePath != 'function') {
- return false;
- }
- // Bundled ES6 module.
- return !!jscomp.getCurrentModulePath();
- }
- return false;
- };
- /**
- * Provide the module's exports as a globally accessible object under the
- * module's declared name. This is intended to ease migration to goog.module
- * for files that have existing usages.
- * @suppress {missingProvide}
- */
- goog.module.declareLegacyNamespace = function() {
- if (!COMPILED && !goog.isInGoogModuleLoader_()) {
- throw new Error(
- 'goog.module.declareLegacyNamespace must be called from ' +
- 'within a goog.module');
- }
- if (!COMPILED && !goog.moduleLoaderState_.moduleName) {
- throw new Error(
- 'goog.module must be called prior to ' +
- 'goog.module.declareLegacyNamespace.');
- }
- goog.moduleLoaderState_.declareLegacyNamespace = true;
- };
- /**
- * Associates an ES6 module with a Closure module ID so that is available via
- * goog.require. The associated ID acts like a goog.module ID - it does not
- * create any global names, it is merely available via goog.require /
- * goog.module.get / goog.forwardDeclare / goog.requireType. goog.require and
- * goog.module.get will return the entire module as if it was import *'d. This
- * allows Closure files to reference ES6 modules for the sake of migration.
- *
- * @param {string} namespace
- * @suppress {missingProvide}
- */
- goog.declareModuleId = function(namespace) {
- if (!COMPILED) {
- if (!goog.isInEs6ModuleLoader_()) {
- throw new Error(
- 'goog.declareModuleId may only be called from ' +
- 'within an ES6 module');
- }
- if (goog.moduleLoaderState_ && goog.moduleLoaderState_.moduleName) {
- throw new Error(
- 'goog.declareModuleId may only be called once per module.');
- }
- if (namespace in goog.loadedModules_) {
- throw new Error(
- 'Module with namespace "' + namespace + '" already exists.');
- }
- }
- if (goog.moduleLoaderState_) {
- // Not bundled - debug loading.
- goog.moduleLoaderState_.moduleName = namespace;
- } else {
- // Bundled - not debug loading, no module loader state.
- var jscomp = goog.global['$jscomp'];
- if (!jscomp || typeof jscomp.getCurrentModulePath != 'function') {
- throw new Error(
- 'Module with namespace "' + namespace +
- '" has been loaded incorrectly.');
- }
- var exports = jscomp.require(jscomp.getCurrentModulePath());
- goog.loadedModules_[namespace] = {
- exports: exports,
- type: goog.ModuleType.ES6,
- moduleId: namespace
- };
- }
- };
- /**
- * Marks that the current file should only be used for testing, and never for
- * live code in production.
- *
- * In the case of unit tests, the message may optionally be an exact namespace
- * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra
- * provide (if not explicitly defined in the code).
- *
- * @param {string=} opt_message Optional message to add to the error that's
- * raised when used in production code.
- */
- goog.setTestOnly = function(opt_message) {
- if (goog.DISALLOW_TEST_ONLY_CODE) {
- opt_message = opt_message || '';
- throw new Error(
- 'Importing test-only code into non-debug environment' +
- (opt_message ? ': ' + opt_message : '.'));
- }
- };
- /**
- * Forward declares a symbol. This is an indication to the compiler that the
- * symbol may be used in the source yet is not required and may not be provided
- * in compilation.
- *
- * The most common usage of forward declaration is code that takes a type as a
- * function parameter but does not need to require it. By forward declaring
- * instead of requiring, no hard dependency is made, and (if not required
- * elsewhere) the namespace may never be required and thus, not be pulled
- * into the JavaScript binary. If it is required elsewhere, it will be type
- * checked as normal.
- *
- * Before using goog.forwardDeclare, please read the documentation at
- * https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation to
- * understand the options and tradeoffs when working with forward declarations.
- *
- * @param {string} name The namespace to forward declare in the form of
- * "goog.package.part".
- * @deprecated See go/noforwarddeclaration, Use `goog.requireType` instead.
- */
- goog.forwardDeclare = function(name) {};
- /**
- * Forward declare type information. Used to assign types to goog.global
- * referenced object that would otherwise result in unknown type references
- * and thus block property disambiguation.
- */
- goog.forwardDeclare('Document');
- goog.forwardDeclare('HTMLScriptElement');
- goog.forwardDeclare('XMLHttpRequest');
- if (!COMPILED) {
- /**
- * Check if the given name has been goog.provided. This will return false for
- * names that are available only as implicit namespaces.
- * @param {string} name name of the object to look for.
- * @return {boolean} Whether the name has been provided.
- * @private
- */
- goog.isProvided_ = function(name) {
- return (name in goog.loadedModules_) ||
- (!goog.implicitNamespaces_[name] && goog.getObjectByName(name) != null);
- };
- /**
- * Namespaces implicitly defined by goog.provide. For example,
- * goog.provide('goog.events.Event') implicitly declares that 'goog' and
- * 'goog.events' must be namespaces.
- *
- * @type {!Object<string, (boolean|undefined)>}
- * @private
- */
- goog.implicitNamespaces_ = {'goog.module': true};
- // NOTE: We add goog.module as an implicit namespace as goog.module is defined
- // here and because the existing module package has not been moved yet out of
- // the goog.module namespace. This satisifies both the debug loader and
- // ahead-of-time dependency management.
- }
- /**
- * Returns an object based on its fully qualified external name. The object
- * is not found if null or undefined. If you are using a compilation pass that
- * renames property names beware that using this function will not find renamed
- * properties.
- *
- * @param {string} name The fully qualified name.
- * @param {Object=} opt_obj The object within which to look; default is
- * |goog.global|.
- * @return {?} The value (object or primitive) or, if not found, null.
- */
- goog.getObjectByName = function(name, opt_obj) {
- var parts = name.split('.');
- var cur = opt_obj || goog.global;
- for (var i = 0; i < parts.length; i++) {
- cur = cur[parts[i]];
- if (cur == null) {
- return null;
- }
- }
- return cur;
- };
- /**
- * Globalizes a whole namespace, such as goog or goog.lang.
- *
- * @param {!Object} obj The namespace to globalize.
- * @param {Object=} opt_global The object to add the properties to.
- * @deprecated Properties may be explicitly exported to the global scope, but
- * this should no longer be done in bulk.
- */
- goog.globalize = function(obj, opt_global) {
- var global = opt_global || goog.global;
- for (var x in obj) {
- global[x] = obj[x];
- }
- };
- /**
- * Adds a dependency from a file to the files it requires.
- * @param {string} relPath The path to the js file.
- * @param {!Array<string>} provides An array of strings with
- * the names of the objects this file provides.
- * @param {!Array<string>} requires An array of strings with
- * the names of the objects this file requires.
- * @param {boolean|!Object<string>=} opt_loadFlags Parameters indicating
- * how the file must be loaded. The boolean 'true' is equivalent
- * to {'module': 'goog'} for backwards-compatibility. Valid properties
- * and values include {'module': 'goog'} and {'lang': 'es6'}.
- */
- goog.addDependency = function(relPath, provides, requires, opt_loadFlags) {
- if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
- goog.debugLoader_.addDependency(relPath, provides, requires, opt_loadFlags);
- }
- };
- // NOTE(nnaze): The debug DOM loader was included in base.js as an original way
- // to do "debug-mode" development. The dependency system can sometimes be
- // confusing, as can the debug DOM loader's asynchronous nature.
- //
- // With the DOM loader, a call to goog.require() is not blocking -- the script
- // will not load until some point after the current script. If a namespace is
- // needed at runtime, it needs to be defined in a previous script, or loaded via
- // require() with its registered dependencies.
- //
- // User-defined namespaces may need their own deps file. For a reference on
- // creating a deps file, see:
- // Externally: https://developers.google.com/closure/library/docs/depswriter
- //
- // Because of legacy clients, the DOM loader can't be easily removed from
- // base.js. Work was done to make it disableable or replaceable for
- // different environments (DOM-less JavaScript interpreters like Rhino or V8,
- // for example). See bootstrap/ for more information.
- /**
- * @define {boolean} Whether to enable the debug loader.
- *
- * If enabled, a call to goog.require() will attempt to load the namespace by
- * appending a script tag to the DOM (if the namespace has been registered).
- *
- * If disabled, goog.require() will simply assert that the namespace has been
- * provided (and depend on the fact that some outside tool correctly ordered
- * the script).
- */
- goog.ENABLE_DEBUG_LOADER = goog.define('goog.ENABLE_DEBUG_LOADER', true);
- /**
- * @param {string} msg
- * @private
- */
- goog.logToConsole_ = function(msg) {
- if (goog.global.console) {
- goog.global.console['error'](msg);
- }
- };
- /**
- * Implements a system for the dynamic resolution of dependencies that works in
- * parallel with the BUILD system.
- *
- * Note that all calls to goog.require will be stripped by the compiler.
- *
- * @see goog.provide
- * @param {string} namespace Namespace (as was given in goog.provide,
- * goog.module, or goog.declareModuleId) in the form
- * "goog.package.part".
- * @return {?} If called within a goog.module or ES6 module file, the associated
- * namespace or module otherwise null.
- */
- goog.require = function(namespace) {
- if (!COMPILED) {
- // Might need to lazy load on old IE.
- if (goog.ENABLE_DEBUG_LOADER) {
- goog.debugLoader_.requested(namespace);
- }
- // If the object already exists we do not need to do anything.
- if (goog.isProvided_(namespace)) {
- if (goog.isInModuleLoader_()) {
- return goog.module.getInternal_(namespace);
- }
- } else if (goog.ENABLE_DEBUG_LOADER) {
- var moduleLoaderState = goog.moduleLoaderState_;
- goog.moduleLoaderState_ = null;
- try {
- goog.debugLoader_.load_(namespace);
- } finally {
- goog.moduleLoaderState_ = moduleLoaderState;
- }
- }
- return null;
- }
- };
- /**
- * Requires a symbol for its type information. This is an indication to the
- * compiler that the symbol may appear in type annotations, yet it is not
- * referenced at runtime.
- *
- * When called within a goog.module or ES6 module file, the return value may be
- * assigned to or destructured into a variable, but it may not be otherwise used
- * in code outside of a type annotation.
- *
- * Note that all calls to goog.requireType will be stripped by the compiler.
- *
- * @param {string} namespace Namespace (as was given in goog.provide,
- * goog.module, or goog.declareModuleId) in the form
- * "goog.package.part".
- * @return {?}
- */
- goog.requireType = function(namespace) {
- // Return an empty object so that single-level destructuring of the return
- // value doesn't crash at runtime when using the debug loader. Multi-level
- // destructuring isn't supported.
- return {};
- };
- /**
- * Path for included scripts.
- * @type {string}
- */
- goog.basePath = '';
- /**
- * A hook for overriding the base path.
- * @type {string|undefined}
- */
- goog.global.CLOSURE_BASE_PATH;
- /**
- * Whether to attempt to load Closure's deps file. By default, when uncompiled,
- * deps files will attempt to be loaded.
- * @type {boolean|undefined}
- */
- goog.global.CLOSURE_NO_DEPS;
- /**
- * A function to import a single script. This is meant to be overridden when
- * Closure is being run in non-HTML contexts, such as web workers. It's defined
- * in the global scope so that it can be set before base.js is loaded, which
- * allows deps.js to be imported properly.
- *
- * The first parameter the script source, which is a relative URI. The second,
- * optional parameter is the script contents, in the event the script needed
- * transformation. It should return true if the script was imported, false
- * otherwise.
- * @type {(function(string, string=): boolean)|undefined}
- */
- goog.global.CLOSURE_IMPORT_SCRIPT;
- /**
- * Null function used for default values of callbacks, etc.
- * @return {void} Nothing.
- */
- goog.nullFunction = function() {};
- /**
- * When defining a class Foo with an abstract method bar(), you can do:
- * Foo.prototype.bar = goog.abstractMethod
- *
- * Now if a subclass of Foo fails to override bar(), an error will be thrown
- * when bar() is invoked.
- *
- * @type {!Function}
- * @throws {Error} when invoked to indicate the method should be overridden.
- * @deprecated Use "@abstract" annotation instead of goog.abstractMethod in new
- * code. See
- * https://github.com/google/closure-compiler/wiki/@abstract-classes-and-methods
- */
- goog.abstractMethod = function() {
- throw new Error('unimplemented abstract method');
- };
- /**
- * Adds a `getInstance` static method that always returns the same
- * instance object.
- * @param {!Function} ctor The constructor for the class to add the static
- * method to.
- * @suppress {missingProperties} 'instance_' isn't a property on 'Function'
- * but we don't have a better type to use here.
- */
- goog.addSingletonGetter = function(ctor) {
- // instance_ is immediately set to prevent issues with sealed constructors
- // such as are encountered when a constructor is returned as the export object
- // of a goog.module in unoptimized code.
- // Delcare type to avoid conformance violations that ctor.instance_ is unknown
- /** @type {undefined|!Object} @suppress {underscore} */
- ctor.instance_ = undefined;
- ctor.getInstance = function() {
- if (ctor.instance_) {
- return ctor.instance_;
- }
- if (goog.DEBUG) {
- // NOTE: JSCompiler can't optimize away Array#push.
- goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor;
- }
- // Cast to avoid conformance violations that ctor.instance_ is unknown
- return /** @type {!Object|undefined} */ (ctor.instance_) = new ctor;
- };
- };
- /**
- * All singleton classes that have been instantiated, for testing. Don't read
- * it directly, use the `goog.testing.singleton` module. The compiler
- * removes this variable if unused.
- * @type {!Array<!Function>}
- * @private
- */
- goog.instantiatedSingletons_ = [];
- /**
- * @define {boolean} Whether to load goog.modules using `eval` when using
- * the debug loader. This provides a better debugging experience as the
- * source is unmodified and can be edited using Chrome Workspaces or similar.
- * However in some environments the use of `eval` is banned
- * so we provide an alternative.
- */
- goog.LOAD_MODULE_USING_EVAL = goog.define('goog.LOAD_MODULE_USING_EVAL', true);
- /**
- * @define {boolean} Whether the exports of goog.modules should be sealed when
- * possible.
- */
- goog.SEAL_MODULE_EXPORTS = goog.define('goog.SEAL_MODULE_EXPORTS', goog.DEBUG);
- /**
- * The registry of initialized modules:
- * The module identifier or path to module exports map.
- * @private @const {!Object<string, {exports:?,type:string,moduleId:string}>}
- */
- goog.loadedModules_ = {};
- /**
- * True if the debug loader enabled and used.
- * @const {boolean}
- */
- goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER;
- /**
- * @define {string} How to decide whether to transpile. Valid values
- * are 'always', 'never', and 'detect'. The default ('detect') is to
- * use feature detection to determine which language levels need
- * transpilation.
- */
- // NOTE(sdh): we could expand this to accept a language level to bypass
- // detection: e.g. goog.TRANSPILE == 'es5' would transpile ES6 files but
- // would leave ES3 and ES5 files alone.
- goog.TRANSPILE = goog.define('goog.TRANSPILE', 'detect');
- /**
- * @define {boolean} If true assume that ES modules have already been
- * transpiled by the jscompiler (in the same way that transpile.js would
- * transpile them - to jscomp modules). Useful only for servers that wish to use
- * the debug loader and transpile server side. Thus this is only respected if
- * goog.TRANSPILE is "never".
- */
- goog.ASSUME_ES_MODULES_TRANSPILED =
- goog.define('goog.ASSUME_ES_MODULES_TRANSPILED', false);
- /**
- * @define {string} If a file needs to be transpiled what the output language
- * should be. By default this is the highest language level this file detects
- * the current environment supports. Generally this flag should not be set, but
- * it could be useful to override. Example: If the current environment supports
- * ES6 then by default ES7+ files will be transpiled to ES6, unless this is
- * overridden.
- *
- * Valid values include: es3, es5, es6, es7, and es8. Anything not recognized
- * is treated as es3.
- *
- * Note that setting this value does not force transpilation. Just if
- * transpilation occurs this will be the output. So this is most useful when
- * goog.TRANSPILE is set to 'always' and then forcing the language level to be
- * something lower than what the environment detects.
- */
- goog.TRANSPILE_TO_LANGUAGE = goog.define('goog.TRANSPILE_TO_LANGUAGE', '');
- /**
- * @define {string} Path to the transpiler. Executing the script at this
- * path (relative to base.js) should define a function $jscomp.transpile.
- */
- goog.TRANSPILER = goog.define('goog.TRANSPILER', 'transpile.js');
- /**
- * @package {?boolean}
- * Visible for testing.
- */
- goog.hasBadLetScoping = null;
- /**
- * @return {boolean}
- * @package Visible for testing.
- */
- goog.useSafari10Workaround = function() {
- if (goog.hasBadLetScoping == null) {
- var hasBadLetScoping;
- try {
- hasBadLetScoping = !eval(
- '"use strict";' +
- 'let x = 1; function f() { return typeof x; };' +
- 'f() == "number";');
- } catch (e) {
- // Assume that ES6 syntax isn't supported.
- hasBadLetScoping = false;
- }
- goog.hasBadLetScoping = hasBadLetScoping;
- }
- return goog.hasBadLetScoping;
- };
- /**
- * @param {string} moduleDef
- * @return {string}
- * @package Visible for testing.
- */
- goog.workaroundSafari10EvalBug = function(moduleDef) {
- return '(function(){' + moduleDef +
- '\n' + // Terminate any trailing single line comment.
- ';' + // Terminate any trailing expression.
- '})();\n';
- };
- /**
- * @param {function(?):?|string} moduleDef The module definition.
- */
- goog.loadModule = function(moduleDef) {
- // NOTE: we allow function definitions to be either in the from
- // of a string to eval (which keeps the original source intact) or
- // in a eval forbidden environment (CSP) we allow a function definition
- // which in its body must call `goog.module`, and return the exports
- // of the module.
- var previousState = goog.moduleLoaderState_;
- try {
- goog.moduleLoaderState_ = {
- moduleName: '',
- declareLegacyNamespace: false,
- type: goog.ModuleType.GOOG
- };
- var exports;
- if (goog.isFunction(moduleDef)) {
- exports = moduleDef.call(undefined, {});
- } else if (typeof moduleDef === 'string') {
- if (goog.useSafari10Workaround()) {
- moduleDef = goog.workaroundSafari10EvalBug(moduleDef);
- }
- exports = goog.loadModuleFromSource_.call(undefined, moduleDef);
- } else {
- throw new Error('Invalid module definition');
- }
- var moduleName = goog.moduleLoaderState_.moduleName;
- if (typeof moduleName === 'string' && moduleName) {
- // Don't seal legacy namespaces as they may be used as a parent of
- // another namespace
- if (goog.moduleLoaderState_.declareLegacyNamespace) {
- goog.constructNamespace_(moduleName, exports);
- } else if (
- goog.SEAL_MODULE_EXPORTS && Object.seal &&
- typeof exports == 'object' && exports != null) {
- Object.seal(exports);
- }
- var data = {
- exports: exports,
- type: goog.ModuleType.GOOG,
- moduleId: goog.moduleLoaderState_.moduleName
- };
- goog.loadedModules_[moduleName] = data;
- } else {
- throw new Error('Invalid module name \"' + moduleName + '\"');
- }
- } finally {
- goog.moduleLoaderState_ = previousState;
- }
- };
- /**
- * @private @const
- */
- goog.loadModuleFromSource_ = /** @type {function(string):?} */ (function() {
- // NOTE: we avoid declaring parameters or local variables here to avoid
- // masking globals or leaking values into the module definition.
- 'use strict';
- var exports = {};
- eval(arguments[0]);
- return exports;
- });
- /**
- * Normalize a file path by removing redundant ".." and extraneous "." file
- * path components.
- * @param {string} path
- * @return {string}
- * @private
- */
- goog.normalizePath_ = function(path) {
- var components = path.split('/');
- var i = 0;
- while (i < components.length) {
- if (components[i] == '.') {
- components.splice(i, 1);
- } else if (
- i && components[i] == '..' && components[i - 1] &&
- components[i - 1] != '..') {
- components.splice(--i, 2);
- } else {
- i++;
- }
- }
- return components.join('/');
- };
- /**
- * Provides a hook for loading a file when using Closure's goog.require() API
- * with goog.modules. In particular this hook is provided to support Node.js.
- *
- * @type {(function(string):string)|undefined}
- */
- goog.global.CLOSURE_LOAD_FILE_SYNC;
- /**
- * Loads file by synchronous XHR. Should not be used in production environments.
- * @param {string} src Source URL.
- * @return {?string} File contents, or null if load failed.
- * @private
- */
- goog.loadFileSync_ = function(src) {
- if (goog.global.CLOSURE_LOAD_FILE_SYNC) {
- return goog.global.CLOSURE_LOAD_FILE_SYNC(src);
- } else {
- try {
- /** @type {XMLHttpRequest} */
- var xhr = new goog.global['XMLHttpRequest']();
- xhr.open('get', src, false);
- xhr.send();
- // NOTE: Successful http: requests have a status of 200, but successful
- // file: requests may have a status of zero. Any other status, or a
- // thrown exception (particularly in case of file: requests) indicates
- // some sort of error, which we treat as a missing or unavailable file.
- return xhr.status == 0 || xhr.status == 200 ? xhr.responseText : null;
- } catch (err) {
- // No need to rethrow or log, since errors should show up on their own.
- return null;
- }
- }
- };
- /**
- * Lazily retrieves the transpiler and applies it to the source.
- * @param {string} code JS code.
- * @param {string} path Path to the code.
- * @param {string} target Language level output.
- * @return {string} The transpiled code.
- * @private
- */
- goog.transpile_ = function(code, path, target) {
- var jscomp = goog.global['$jscomp'];
- if (!jscomp) {
- goog.global['$jscomp'] = jscomp = {};
- }
- var transpile = jscomp.transpile;
- if (!transpile) {
- var transpilerPath = goog.basePath + goog.TRANSPILER;
- var transpilerCode = goog.loadFileSync_(transpilerPath);
- if (transpilerCode) {
- // This must be executed synchronously, since by the time we know we
- // need it, we're about to load and write the ES6 code synchronously,
- // so a normal script-tag load will be too slow. Wrapped in a function
- // so that code is eval'd in the global scope.
- (function() {
- (0, eval)(transpilerCode + '\n//# sourceURL=' + transpilerPath);
- }).call(goog.global);
- // Even though the transpiler is optional, if $gwtExport is found, it's
- // a sign the transpiler was loaded and the $jscomp.transpile *should*
- // be there.
- if (goog.global['$gwtExport'] && goog.global['$gwtExport']['$jscomp'] &&
- !goog.global['$gwtExport']['$jscomp']['transpile']) {
- throw new Error(
- 'The transpiler did not properly export the "transpile" ' +
- 'method. $gwtExport: ' + JSON.stringify(goog.global['$gwtExport']));
- }
- // transpile.js only exports a single $jscomp function, transpile. We
- // grab just that and add it to the existing definition of $jscomp which
- // contains the polyfills.
- goog.global['$jscomp'].transpile =
- goog.global['$gwtExport']['$jscomp']['transpile'];
- jscomp = goog.global['$jscomp'];
- transpile = jscomp.transpile;
- }
- }
- if (!transpile) {
- // The transpiler is an optional component. If it's not available then
- // replace it with a pass-through function that simply logs.
- var suffix = ' requires transpilation but no transpiler was found.';
- transpile = jscomp.transpile = function(code, path) {
- // TODO(sdh): figure out some way to get this error to show up
- // in test results, noting that the failure may occur in many
- // different ways, including in loadModule() before the test
- // runner even comes up.
- goog.logToConsole_(path + suffix);
- return code;
- };
- }
- // Note: any transpilation errors/warnings will be logged to the console.
- return transpile(code, path, target);
- };
- //==============================================================================
- // Language Enhancements
- //==============================================================================
- /**
- * This is a "fixed" version of the typeof operator. It differs from the typeof
- * operator in such a way that null returns 'null' and arrays return 'array'.
- * @param {?} value The value to get the type of.
- * @return {string} The name of the type.
- */
- goog.typeOf = function(value) {
- var s = typeof value;
- if (s == 'object') {
- if (value) {
- // Check these first, so we can avoid calling Object.prototype.toString if
- // possible.
- //
- // IE9 and below improperly marshals typeof across execution contexts, but
- // a cross-context object will still return false for "instanceof Object".
- if (value instanceof Array) {
- return 'array';
- } else if (value instanceof Object) {
- return s;
- }
- // HACK: In order to use an Object prototype method on the arbitrary
- // value, the compiler requires the value be cast to type Object,
- // even though the ECMA spec explicitly allows it.
- var className = Object.prototype.toString.call(
- /** @type {!Object} */ (value));
- // In Firefox 3.6, attempting to access iframe window objects' length
- // property throws an NS_ERROR_FAILURE, so we need to special-case it
- // here.
- if (className == '[object Window]') {
- return 'object';
- }
- // We cannot always use constructor == Array or instanceof Array because
- // different frames have different Array objects. In IE6, if the iframe
- // where the array was created is destroyed, the array loses its
- // prototype. Then dereferencing val.splice here throws an exception, so
- // we can't use goog.isFunction. Calling typeof directly returns 'unknown'
- // so that will work. In this case, this function will return false and
- // most array functions will still work because the array is still
- // array-like (supports length and []) even though it has lost its
- // prototype.
- // Mark Miller noticed that Object.prototype.toString
- // allows access to the unforgeable [[Class]] property.
- // 15.2.4.2 Object.prototype.toString ( )
- // When the toString method is called, the following steps are taken:
- // 1. Get the [[Class]] property of this object.
- // 2. Compute a string value by concatenating the three strings
- // "[object ", Result(1), and "]".
- // 3. Return Result(2).
- // and this behavior survives the destruction of the execution context.
- if ((className == '[object Array]' ||
- // In IE all non value types are wrapped as objects across window
- // boundaries (not iframe though) so we have to do object detection
- // for this edge case.
- typeof value.length == 'number' &&
- typeof value.splice != 'undefined' &&
- typeof value.propertyIsEnumerable != 'undefined' &&
- !value.propertyIsEnumerable('splice')
- )) {
- return 'array';
- }
- // HACK: There is still an array case that fails.
- // function ArrayImpostor() {}
- // ArrayImpostor.prototype = [];
- // var impostor = new ArrayImpostor;
- // this can be fixed by getting rid of the fast path
- // (value instanceof Array) and solely relying on
- // (value && Object.prototype.toString.vall(value) === '[object Array]')
- // but that would require many more function calls and is not warranted
- // unless closure code is receiving objects from untrusted sources.
- // IE in cross-window calls does not correctly marshal the function type
- // (it appears just as an object) so we cannot use just typeof val ==
- // 'function'. However, if the object has a call property, it is a
- // function.
- if ((className == '[object Function]' ||
- typeof value.call != 'undefined' &&
- typeof value.propertyIsEnumerable != 'undefined' &&
- !value.propertyIsEnumerable('call'))) {
- return 'function';
- }
- } else {
- return 'null';
- }
- } else if (s == 'function' && typeof value.call == 'undefined') {
- // In Safari typeof nodeList returns 'function', and on Firefox typeof
- // behaves similarly for HTML{Applet,Embed,Object}, Elements and RegExps. We
- // would like to return object for those and we can detect an invalid
- // function by making sure that the function object has a call method.
- return 'object';
- }
- return s;
- };
- /**
- * Returns true if the specified value is an array.
- * @param {?} val Variable to test.
- * @return {boolean} Whether variable is an array.
- * @deprecated Use Array.isArray instead.
- */
- goog.isArray = function(val) {
- return goog.typeOf(val) == 'array';
- };
- /**
- * Returns true if the object looks like an array. To qualify as array like
- * the value needs to be either a NodeList or an object with a Number length
- * property. Note that for this function neither strings nor functions are
- * considered "array-like".
- *
- * @param {?} val Variable to test.
- * @return {boolean} Whether variable is an array.
- */
- goog.isArrayLike = function(val) {
- var type = goog.typeOf(val);
- // We do not use goog.isObject here in order to exclude function values.
- return type == 'array' || type == 'object' && typeof val.length == 'number';
- };
- /**
- * Returns true if the object looks like a Date. To qualify as Date-like the
- * value needs to be an object and have a getFullYear() function.
- * @param {?} val Variable to test.
- * @return {boolean} Whether variable is a like a Date.
- */
- goog.isDateLike = function(val) {
- return goog.isObject(val) && typeof val.getFullYear == 'function';
- };
- /**
- * Returns true if the specified value is a function.
- * @param {?} val Variable to test.
- * @return {boolean} Whether variable is a function.
- */
- goog.isFunction = function(val) {
- return goog.typeOf(val) == 'function';
- };
- /**
- * Returns true if the specified value is an object. This includes arrays and
- * functions.
- * @param {?} val Variable to test.
- * @return {boolean} Whether variable is an object.
- */
- goog.isObject = function(val) {
- var type = typeof val;
- return type == 'object' && val != null || type == 'function';
- // return Object(val) === val also works, but is slower, especially if val is
- // not an object.
- };
- /**
- * Gets a unique ID for an object. This mutates the object so that further calls
- * with the same object as a parameter returns the same value. The unique ID is
- * guaranteed to be unique across the current session amongst objects that are
- * passed into `getUid`. There is no guarantee that the ID is unique or
- * consistent across sessions. It is unsafe to generate unique ID for function
- * prototypes.
- *
- * @param {Object} obj The object to get the unique ID for.
- * @return {number} The unique ID for the object.
- */
- goog.getUid = function(obj) {
- // TODO(arv): Make the type stricter, do not accept null.
- return Object.prototype.hasOwnProperty.call(obj, goog.UID_PROPERTY_) &&
- obj[goog.UID_PROPERTY_] ||
- (obj[goog.UID_PROPERTY_] = ++goog.uidCounter_);
- };
- /**
- * Whether the given object is already assigned a unique ID.
- *
- * This does not modify the object.
- *
- * @param {!Object} obj The object to check.
- * @return {boolean} Whether there is an assigned unique id for the object.
- */
- goog.hasUid = function(obj) {
- return !!obj[goog.UID_PROPERTY_];
- };
- /**
- * Removes the unique ID from an object. This is useful if the object was
- * previously mutated using `goog.getUid` in which case the mutation is
- * undone.
- * @param {Object} obj The object to remove the unique ID field from.
- */
- goog.removeUid = function(obj) {
- // TODO(arv): Make the type stricter, do not accept null.
- // In IE, DOM nodes are not instances of Object and throw an exception if we
- // try to delete. Instead we try to use removeAttribute.
- if (obj !== null && 'removeAttribute' in obj) {
- obj.removeAttribute(goog.UID_PROPERTY_);
- }
- try {
- delete obj[goog.UID_PROPERTY_];
- } catch (ex) {
- }
- };
- /**
- * Name for unique ID property. Initialized in a way to help avoid collisions
- * with other closure JavaScript on the same page.
- * @type {string}
- * @private
- */
- goog.UID_PROPERTY_ = 'closure_uid_' + ((Math.random() * 1e9) >>> 0);
- /**
- * Counter for UID.
- * @type {number}
- * @private
- */
- goog.uidCounter_ = 0;
- /**
- * Adds a hash code field to an object. The hash code is unique for the
- * given object.
- * @param {Object} obj The object to get the hash code for.
- * @return {number} The hash code for the object.
- * @deprecated Use goog.getUid instead.
- */
- goog.getHashCode = goog.getUid;
- /**
- * Removes the hash code field from an object.
- * @param {Object} obj The object to remove the field from.
- * @deprecated Use goog.removeUid instead.
- */
- goog.removeHashCode = goog.removeUid;
- /**
- * Clones a value. The input may be an Object, Array, or basic type. Objects and
- * arrays will be cloned recursively.
- *
- * WARNINGS:
- * <code>goog.cloneObject</code> does not detect reference loops. Objects that
- * refer to themselves will cause infinite recursion.
- *
- * <code>goog.cloneObject</code> is unaware of unique identifiers, and copies
- * UIDs created by <code>getUid</code> into cloned results.
- *
- * @param {*} obj The value to clone.
- * @return {*} A clone of the input value.
- * @deprecated goog.cloneObject is unsafe. Prefer the goog.object methods.
- */
- goog.cloneObject = function(obj) {
- var type = goog.typeOf(obj);
- if (type == 'object' || type == 'array') {
- if (typeof obj.clone === 'function') {
- return obj.clone();
- }
- var clone = type == 'array' ? [] : {};
- for (var key in obj) {
- clone[key] = goog.cloneObject(obj[key]);
- }
- return clone;
- }
- return obj;
- };
- /**
- * A native implementation of goog.bind.
- * @param {?function(this:T, ...)} fn A function to partially apply.
- * @param {T} selfObj Specifies the object which this should point to when the
- * function is run.
- * @param {...*} var_args Additional arguments that are partially applied to the
- * function.
- * @return {!Function} A partially-applied form of the function goog.bind() was
- * invoked as a method of.
- * @template T
- * @private
- */
- goog.bindNative_ = function(fn, selfObj, var_args) {
- return /** @type {!Function} */ (fn.call.apply(fn.bind, arguments));
- };
- /**
- * A pure-JS implementation of goog.bind.
- * @param {?function(this:T, ...)} fn A function to partially apply.
- * @param {T} selfObj Specifies the object which this should point to when the
- * function is run.
- * @param {...*} var_args Additional arguments that are partially applied to the
- * function.
- * @return {!Function} A partially-applied form of the function goog.bind() was
- * invoked as a method of.
- * @template T
- * @private
- */
- goog.bindJs_ = function(fn, selfObj, var_args) {
- if (!fn) {
- throw new Error();
- }
- if (arguments.length > 2) {
- var boundArgs = Array.prototype.slice.call(arguments, 2);
- return function() {
- // Prepend the bound arguments to the current arguments.
- var newArgs = Array.prototype.slice.call(arguments);
- Array.prototype.unshift.apply(newArgs, boundArgs);
- return fn.apply(selfObj, newArgs);
- };
- } else {
- return function() {
- return fn.apply(selfObj, arguments);
- };
- }
- };
- /**
- * Partially applies this function to a particular 'this object' and zero or
- * more arguments. The result is a new function with some arguments of the first
- * function pre-filled and the value of this 'pre-specified'.
- *
- * Remaining arguments specified at call-time are appended to the pre-specified
- * ones.
- *
- * Also see: {@link #partial}.
- *
- * Usage:
- * <pre>var barMethBound = goog.bind(myFunction, myObj, 'arg1', 'arg2');
- * barMethBound('arg3', 'arg4');</pre>
- *
- * @param {?function(this:T, ...)} fn A function to partially apply.
- * @param {T} selfObj Specifies the object which this should point to when the
- * function is run.
- * @param {...*} var_args Additional arguments that are partially applied to the
- * function.
- * @return {!Function} A partially-applied form of the function goog.bind() was
- * invoked as a method of.
- * @template T
- * @suppress {deprecated} See above.
- */
- goog.bind = function(fn, selfObj, var_args) {
- // TODO(nicksantos): narrow the type signature.
- if (Function.prototype.bind &&
- // NOTE(nicksantos): Somebody pulled base.js into the default Chrome
- // extension environment. This means that for Chrome extensions, they get
- // the implementation of Function.prototype.bind that calls goog.bind
- // instead of the native one. Even worse, we don't want to introduce a
- // circular dependency between goog.bind and Function.prototype.bind, so
- // we have to hack this to make sure it works correctly.
- Function.prototype.bind.toString().indexOf('native code') != -1) {
- goog.bind = goog.bindNative_;
- } else {
- goog.bind = goog.bindJs_;
- }
- return goog.bind.apply(null, arguments);
- };
- /**
- * Like goog.bind(), except that a 'this object' is not required. Useful when
- * the target function is already bound.
- *
- * Usage:
- * var g = goog.partial(f, arg1, arg2);
- * g(arg3, arg4);
- *
- * @param {Function} fn A function to partially apply.
- * @param {...*} var_args Additional arguments that are partially applied to fn.
- * @return {!Function} A partially-applied form of the function goog.partial()
- * was invoked as a method of.
- */
- goog.partial = function(fn, var_args) {
- var args = Array.prototype.slice.call(arguments, 1);
- return function() {
- // Clone the array (with slice()) and append additional arguments
- // to the existing arguments.
- var newArgs = args.slice();
- newArgs.push.apply(newArgs, arguments);
- return fn.apply(/** @type {?} */ (this), newArgs);
- };
- };
- /**
- * Copies all the members of a source object to a target object. This method
- * does not work on all browsers for all objects that contain keys such as
- * toString or hasOwnProperty. Use goog.object.extend for this purpose.
- *
- * NOTE: Some have advocated for the use of goog.mixin to setup classes
- * with multiple inheritence (traits, mixins, etc). However, as it simply
- * uses "for in", this is not compatible with ES6 classes whose methods are
- * non-enumerable. Changing this, would break cases where non-enumerable
- * properties are not expected.
- *
- * @param {Object} target Target.
- * @param {Object} source Source.
- * @deprecated Prefer Object.assign
- */
- goog.mixin = function(target, source) {
- for (var x in source) {
- target[x] = source[x];
- }
- // For IE7 or lower, the for-in-loop does not contain any properties that are
- // not enumerable on the prototype object (for example, isPrototypeOf from
- // Object.prototype) but also it will not include 'replace' on objects that
- // extend String and change 'replace' (not that it is common for anyone to
- // extend anything except Object).
- };
- /**
- * @return {number} An integer value representing the number of milliseconds
- * between midnight, January 1, 1970 and the current time.
- * @deprecated Use Date.now
- */
- goog.now = (goog.TRUSTED_SITE && Date.now) || (function() {
- // Unary plus operator converts its operand to a number which in
- // the case of
- // a date is done by calling getTime().
- return +new Date();
- });
- /**
- * Evals JavaScript in the global scope. In IE this uses execScript, other
- * browsers use goog.global.eval. If goog.global.eval does not evaluate in the
- * global scope (for example, in Safari), appends a script tag instead.
- * Throws an exception if neither execScript or eval is defined.
- * @param {string} script JavaScript string.
- */
- goog.globalEval = function(script) {
- if (goog.global.execScript) {
- goog.global.execScript(script, 'JavaScript');
- } else if (goog.global.eval) {
- // Test to see if eval works
- if (goog.evalWorksForGlobals_ == null) {
- try {
- goog.global.eval('var _evalTest_ = 1;');
- } catch (ignore) {
- }
- if (typeof goog.global['_evalTest_'] != 'undefined') {
- try {
- delete goog.global['_evalTest_'];
- } catch (ignore) {
- // Microsoft edge fails the deletion above in strict mode.
- }
- goog.evalWorksForGlobals_ = true;
- } else {
- goog.evalWorksForGlobals_ = false;
- }
- }
- if (goog.evalWorksForGlobals_) {
- goog.global.eval(script);
- } else {
- /** @type {!Document} */
- var doc = goog.global.document;
- var scriptElt =
- /** @type {!HTMLScriptElement} */ (doc.createElement('script'));
- scriptElt.type = 'text/javascript';
- scriptElt.defer = false;
- // Note(user): can't use .innerHTML since "t('<test>')" will fail and
- // .text doesn't work in Safari 2. Therefore we append a text node.
- scriptElt.appendChild(doc.createTextNode(script));
- doc.head.appendChild(scriptElt);
- doc.head.removeChild(scriptElt);
- }
- } else {
- throw new Error('goog.globalEval not available');
- }
- };
- /**
- * Indicates whether or not we can call 'eval' directly to eval code in the
- * global scope. Set to a Boolean by the first call to goog.globalEval (which
- * empirically tests whether eval works for globals). @see goog.globalEval
- * @type {?boolean}
- * @private
- */
- goog.evalWorksForGlobals_ = null;
- /**
- * Optional map of CSS class names to obfuscated names used with
- * goog.getCssName().
- * @private {!Object<string, string>|undefined}
- * @see goog.setCssNameMapping
- */
- goog.cssNameMapping_;
- /**
- * Optional obfuscation style for CSS class names. Should be set to either
- * 'BY_WHOLE' or 'BY_PART' if defined.
- * @type {string|undefined}
- * @private
- * @see goog.setCssNameMapping
- */
- goog.cssNameMappingStyle_;
- /**
- * A hook for modifying the default behavior goog.getCssName. The function
- * if present, will receive the standard output of the goog.getCssName as
- * its input.
- *
- * @type {(function(string):string)|undefined}
- */
- goog.global.CLOSURE_CSS_NAME_MAP_FN;
- /**
- * Handles strings that are intended to be used as CSS class names.
- *
- * This function works in tandem with @see goog.setCssNameMapping.
- *
- * Without any mapping set, the arguments are simple joined with a hyphen and
- * passed through unaltered.
- *
- * When there is a mapping, there are two possible styles in which these
- * mappings are used. In the BY_PART style, each part (i.e. in between hyphens)
- * of the passed in css name is rewritten according to the map. In the BY_WHOLE
- * style, the full css name is looked up in the map directly. If a rewrite is
- * not specified by the map, the compiler will output a warning.
- *
- * When the mapping is passed to the compiler, it will replace calls to
- * goog.getCssName with the strings from the mapping, e.g.
- * var x = goog.getCssName('foo');
- * var y = goog.getCssName(this.baseClass, 'active');
- * becomes:
- * var x = 'foo';
- * var y = this.baseClass + '-active';
- *
- * If one argument is passed it will be processed, if two are passed only the
- * modifier will be processed, as it is assumed the first argument was generated
- * as a result of calling goog.getCssName.
- *
- * @param {string} className The class name.
- * @param {string=} opt_modifier A modifier to be appended to the class name.
- * @return {string} The class name or the concatenation of the class name and
- * the modifier.
- */
- goog.getCssName = function(className, opt_modifier) {
- // String() is used for compatibility with compiled soy where the passed
- // className can be non-string objects.
- if (String(className).charAt(0) == '.') {
- throw new Error(
- 'className passed in goog.getCssName must not start with ".".' +
- ' You passed: ' + className);
- }
- var getMapping = function(cssName) {
- return goog.cssNameMapping_[cssName] || cssName;
- };
- var renameByParts = function(cssName) {
- // Remap all the parts individually.
- var parts = cssName.split('-');
- var mapped = [];
- for (var i = 0; i < parts.length; i++) {
- mapped.push(getMapping(parts[i]));
- }
- return mapped.join('-');
- };
- var rename;
- if (goog.cssNameMapping_) {
- rename =
- goog.cssNameMappingStyle_ == 'BY_WHOLE' ? getMapping : renameByParts;
- } else {
- rename = function(a) {
- return a;
- };
- }
- var result =
- opt_modifier ? className + '-' + rename(opt_modifier) : rename(className);
- // The special CLOSURE_CSS_NAME_MAP_FN allows users to specify further
- // processing of the class name.
- if (goog.global.CLOSURE_CSS_NAME_MAP_FN) {
- return goog.global.CLOSURE_CSS_NAME_MAP_FN(result);
- }
- return result;
- };
- /**
- * Sets the map to check when returning a value from goog.getCssName(). Example:
- * <pre>
- * goog.setCssNameMapping({
- * "goog": "a",
- * "disabled": "b",
- * });
- *
- * var x = goog.getCssName('goog');
- * // The following evaluates to: "a a-b".
- * goog.getCssName('goog') + ' ' + goog.getCssName(x, 'disabled')
- * </pre>
- * When declared as a map of string literals to string literals, the JSCompiler
- * will replace all calls to goog.getCssName() using the supplied map if the
- * --process_closure_primitives flag is set.
- *
- * @param {!Object} mapping A map of strings to strings where keys are possible
- * arguments to goog.getCssName() and values are the corresponding values
- * that should be returned.
- * @param {string=} opt_style The style of css name mapping. There are two valid
- * options: 'BY_PART', and 'BY_WHOLE'.
- * @see goog.getCssName for a description.
- */
- goog.setCssNameMapping = function(mapping, opt_style) {
- goog.cssNameMapping_ = mapping;
- goog.cssNameMappingStyle_ = opt_style;
- };
- /**
- * To use CSS renaming in compiled mode, one of the input files should have a
- * call to goog.setCssNameMapping() with an object literal that the JSCompiler
- * can extract and use to replace all calls to goog.getCssName(). In uncompiled
- * mode, JavaScript code should be loaded before this base.js file that declares
- * a global variable, CLOSURE_CSS_NAME_MAPPING, which is used below. This is
- * to ensure that the mapping is loaded before any calls to goog.getCssName()
- * are made in uncompiled mode.
- *
- * A hook for overriding the CSS name mapping.
- * @type {!Object<string, string>|undefined}
- */
- goog.global.CLOSURE_CSS_NAME_MAPPING;
- if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) {
- // This does not call goog.setCssNameMapping() because the JSCompiler
- // requires that goog.setCssNameMapping() be called with an object literal.
- goog.cssNameMapping_ = goog.global.CLOSURE_CSS_NAME_MAPPING;
- }
- /**
- * Gets a localized message.
- *
- * This function is a compiler primitive. If you give the compiler a localized
- * message bundle, it will replace the string at compile-time with a localized
- * version, and expand goog.getMsg call to a concatenated string.
- *
- * Messages must be initialized in the form:
- * <code>
- * var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'});
- * </code>
- *
- * This function produces a string which should be treated as plain text. Use
- * {@link goog.html.SafeHtmlFormatter} in conjunction with goog.getMsg to
- * produce SafeHtml.
- *
- * @param {string} str Translatable string, places holders in the form {$foo}.
- * @param {Object<string, string>=} opt_values Maps place holder name to value.
- * @param {{html: boolean}=} opt_options Options:
- * html: Escape '<' in str to '<'. Used by Closure Templates where the
- * generated code size and performance is critical which is why {@link
- * goog.html.SafeHtmlFormatter} is not used. The value must be literal true
- * or false.
- * @return {string} message with placeholders filled.
- */
- goog.getMsg = function(str, opt_values, opt_options) {
- if (opt_options && opt_options.html) {
- // Note that '&' is not replaced because the translation can contain HTML
- // entities.
- str = str.replace(/</g, '<');
- }
- if (opt_values) {
- str = str.replace(/\{\$([^}]+)}/g, function(match, key) {
- return (opt_values != null && key in opt_values) ? opt_values[key] :
- match;
- });
- }
- return str;
- };
- /**
- * Gets a localized message. If the message does not have a translation, gives a
- * fallback message.
- *
- * This is useful when introducing a new message that has not yet been
- * translated into all languages.
- *
- * This function is a compiler primitive. Must be used in the form:
- * <code>var x = goog.getMsgWithFallback(MSG_A, MSG_B);</code>
- * where MSG_A and MSG_B were initialized with goog.getMsg.
- *
- * @param {string} a The preferred message.
- * @param {string} b The fallback message.
- * @return {string} The best translated message.
- */
- goog.getMsgWithFallback = function(a, b) {
- return a;
- };
- /**
- * Exposes an unobfuscated global namespace path for the given object.
- * Note that fields of the exported object *will* be obfuscated, unless they are
- * exported in turn via this function or goog.exportProperty.
- *
- * Also handy for making public items that are defined in anonymous closures.
- *
- * ex. goog.exportSymbol('public.path.Foo', Foo);
- *
- * ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction);
- * public.path.Foo.staticFunction();
- *
- * ex. goog.exportSymbol('public.path.Foo.prototype.myMethod',
- * Foo.prototype.myMethod);
- * new public.path.Foo().myMethod();
- *
- * @param {string} publicPath Unobfuscated name to export.
- * @param {*} object Object the name should point to.
- * @param {Object=} opt_objectToExportTo The object to add the path to; default
- * is goog.global.
- */
- goog.exportSymbol = function(publicPath, object, opt_objectToExportTo) {
- goog.exportPath_(publicPath, object, opt_objectToExportTo);
- };
- /**
- * Exports a property unobfuscated into the object's namespace.
- * ex. goog.exportProperty(Foo, 'staticFunction', Foo.staticFunction);
- * ex. goog.exportProperty(Foo.prototype, 'myMethod', Foo.prototype.myMethod);
- * @param {Object} object Object whose static property is being exported.
- * @param {string} publicName Unobfuscated name to export.
- * @param {*} symbol Object the name should point to.
- */
- goog.exportProperty = function(object, publicName, symbol) {
- object[publicName] = symbol;
- };
- /**
- * Inherit the prototype methods from one constructor into another.
- *
- * Usage:
- * <pre>
- * function ParentClass(a, b) { }
- * ParentClass.prototype.foo = function(a) { };
- *
- * function ChildClass(a, b, c) {
- * ChildClass.base(this, 'constructor', a, b);
- * }
- * goog.inherits(ChildClass, ParentClass);
- *
- * var child = new ChildClass('a', 'b', 'see');
- * child.foo(); // This works.
- * </pre>
- *
- * @param {!Function} childCtor Child class.
- * @param {!Function} parentCtor Parent class.
- * @suppress {strictMissingProperties} superClass_ and base is not defined on
- * Function.
- */
- goog.inherits = function(childCtor, parentCtor) {
- /** @constructor */
- function tempCtor() {}
- tempCtor.prototype = parentCtor.prototype;
- childCtor.superClass_ = parentCtor.prototype;
- childCtor.prototype = new tempCtor();
- /** @override */
- childCtor.prototype.constructor = childCtor;
- /**
- * Calls superclass constructor/method.
- *
- * This function is only available if you use goog.inherits to
- * express inheritance relationships between classes.
- *
- * NOTE: This is a replacement for goog.base and for superClass_
- * property defined in childCtor.
- *
- * @param {!Object} me Should always be "this".
- * @param {string} methodName The method name to call. Calling
- * superclass constructor can be done with the special string
- * 'constructor'.
- * @param {...*} var_args The arguments to pass to superclass
- * method/constructor.
- * @return {*} The return value of the superclass method/constructor.
- */
- childCtor.base = function(me, methodName, var_args) {
- // Copying using loop to avoid deop due to passing arguments object to
- // function. This is faster in many JS engines as of late 2014.
- var args = new Array(arguments.length - 2);
- for (var i = 2; i < arguments.length; i++) {
- args[i - 2] = arguments[i];
- }
- return parentCtor.prototype[methodName].apply(me, args);
- };
- };
- /**
- * Allow for aliasing within scope functions. This function exists for
- * uncompiled code - in compiled code the calls will be inlined and the aliases
- * applied. In uncompiled code the function is simply run since the aliases as
- * written are valid JavaScript.
- *
- *
- * @param {function()} fn Function to call. This function can contain aliases
- * to namespaces (e.g. "var dom = goog.dom") or classes
- * (e.g. "var Timer = goog.Timer").
- * @deprecated Use goog.module instead.
- */
- goog.scope = function(fn) {
- if (goog.isInModuleLoader_()) {
- throw new Error('goog.scope is not supported within a module.');
- }
- fn.call(goog.global);
- };
- /*
- * To support uncompiled, strict mode bundles that use eval to divide source
- * like so:
- * eval('someSource;//# sourceUrl sourcefile.js');
- * We need to export the globally defined symbols "goog" and "COMPILED".
- * Exporting "goog" breaks the compiler optimizations, so we required that
- * be defined externally.
- * NOTE: We don't use goog.exportSymbol here because we don't want to trigger
- * extern generation when that compiler option is enabled.
- */
- if (!COMPILED) {
- goog.global['COMPILED'] = COMPILED;
- }
- //==============================================================================
- // goog.defineClass implementation
- //==============================================================================
- /**
- * Creates a restricted form of a Closure "class":
- * - from the compiler's perspective, the instance returned from the
- * constructor is sealed (no new properties may be added). This enables
- * better checks.
- * - the compiler will rewrite this definition to a form that is optimal
- * for type checking and optimization (initially this will be a more
- * traditional form).
- *
- * @param {Function} superClass The superclass, Object or null.
- * @param {goog.defineClass.ClassDescriptor} def
- * An object literal describing
- * the class. It may have the following properties:
- * "constructor": the constructor function
- * "statics": an object literal containing methods to add to the constructor
- * as "static" methods or a function that will receive the constructor
- * function as its only parameter to which static properties can
- * be added.
- * all other properties are added to the prototype.
- * @return {!Function} The class constructor.
- * @deprecated Use ES6 class syntax instead.
- */
- goog.defineClass = function(superClass, def) {
- // TODO(johnlenz): consider making the superClass an optional parameter.
- var constructor = def.constructor;
- var statics = def.statics;
- // Wrap the constructor prior to setting up the prototype and static methods.
- if (!constructor || constructor == Object.prototype.constructor) {
- constructor = function() {
- throw new Error(
- 'cannot instantiate an interface (no constructor defined).');
- };
- }
- var cls = goog.defineClass.createSealingConstructor_(constructor, superClass);
- if (superClass) {
- goog.inherits(cls, superClass);
- }
- // Remove all the properties that should not be copied to the prototype.
- delete def.constructor;
- delete def.statics;
- goog.defineClass.applyProperties_(cls.prototype, def);
- if (statics != null) {
- if (statics instanceof Function) {
- statics(cls);
- } else {
- goog.defineClass.applyProperties_(cls, statics);
- }
- }
- return cls;
- };
- /**
- * @typedef {{
- * constructor: (!Function|undefined),
- * statics: (Object|undefined|function(Function):void)
- * }}
- */
- goog.defineClass.ClassDescriptor;
- /**
- * @define {boolean} Whether the instances returned by goog.defineClass should
- * be sealed when possible.
- *
- * When sealing is disabled the constructor function will not be wrapped by
- * goog.defineClass, making it incompatible with ES6 class methods.
- */
- goog.defineClass.SEAL_CLASS_INSTANCES =
- goog.define('goog.defineClass.SEAL_CLASS_INSTANCES', goog.DEBUG);
- /**
- * If goog.defineClass.SEAL_CLASS_INSTANCES is enabled and Object.seal is
- * defined, this function will wrap the constructor in a function that seals the
- * results of the provided constructor function.
- *
- * @param {!Function} ctr The constructor whose results maybe be sealed.
- * @param {Function} superClass The superclass constructor.
- * @return {!Function} The replacement constructor.
- * @private
- */
- goog.defineClass.createSealingConstructor_ = function(ctr, superClass) {
- if (!goog.defineClass.SEAL_CLASS_INSTANCES) {
- // Do now wrap the constructor when sealing is disabled. Angular code
- // depends on this for injection to work properly.
- return ctr;
- }
- // Compute whether the constructor is sealable at definition time, rather
- // than when the instance is being constructed.
- var superclassSealable = !goog.defineClass.isUnsealable_(superClass);
- /**
- * @this {Object}
- * @return {?}
- */
- var wrappedCtr = function() {
- // Don't seal an instance of a subclass when it calls the constructor of
- // its super class as there is most likely still setup to do.
- var instance = ctr.apply(this, arguments) || this;
- instance[goog.UID_PROPERTY_] = instance[goog.UID_PROPERTY_];
- if (this.constructor === wrappedCtr && superclassSealable &&
- Object.seal instanceof Function) {
- Object.seal(instance);
- }
- return instance;
- };
- return wrappedCtr;
- };
- /**
- * @param {Function} ctr The constructor to test.
- * @return {boolean} Whether the constructor has been tagged as unsealable
- * using goog.tagUnsealableClass.
- * @private
- */
- goog.defineClass.isUnsealable_ = function(ctr) {
- return ctr && ctr.prototype &&
- ctr.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_];
- };
- // TODO(johnlenz): share these values with the goog.object
- /**
- * The names of the fields that are defined on Object.prototype.
- * @type {!Array<string>}
- * @private
- * @const
- */
- goog.defineClass.OBJECT_PROTOTYPE_FIELDS_ = [
- 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
- 'toLocaleString', 'toString', 'valueOf'
- ];
- // TODO(johnlenz): share this function with the goog.object
- /**
- * @param {!Object} target The object to add properties to.
- * @param {!Object} source The object to copy properties from.
- * @private
- */
- goog.defineClass.applyProperties_ = function(target, source) {
- // TODO(johnlenz): update this to support ES5 getters/setters
- var key;
- for (key in source) {
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- target[key] = source[key];
- }
- }
- // For IE the for-in-loop does not contain any properties that are not
- // enumerable on the prototype object (for example isPrototypeOf from
- // Object.prototype) and it will also not include 'replace' on objects that
- // extend String and change 'replace' (not that it is common for anyone to
- // extend anything except Object).
- for (var i = 0; i < goog.defineClass.OBJECT_PROTOTYPE_FIELDS_.length; i++) {
- key = goog.defineClass.OBJECT_PROTOTYPE_FIELDS_[i];
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- target[key] = source[key];
- }
- }
- };
- /**
- * Sealing classes breaks the older idiom of assigning properties on the
- * prototype rather than in the constructor. As such, goog.defineClass
- * must not seal subclasses of these old-style classes until they are fixed.
- * Until then, this marks a class as "broken", instructing defineClass
- * not to seal subclasses.
- * @param {!Function} ctr The legacy constructor to tag as unsealable.
- */
- goog.tagUnsealableClass = function(ctr) {
- if (!COMPILED && goog.defineClass.SEAL_CLASS_INSTANCES) {
- ctr.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_] = true;
- }
- };
- /**
- * Name for unsealable tag property.
- * @const @private {string}
- */
- goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_ = 'goog_defineClass_legacy_unsealable';
- // There's a bug in the compiler where without collapse properties the
- // Closure namespace defines do not guard code correctly. To help reduce code
- // size also check for !COMPILED even though it redundant until this is fixed.
- if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
- /**
- * Tries to detect whether is in the context of an HTML document.
- * @return {boolean} True if it looks like HTML document.
- * @private
- */
- goog.inHtmlDocument_ = function() {
- /** @type {!Document} */
- var doc = goog.global.document;
- return doc != null && 'write' in doc; // XULDocument misses write.
- };
- /**
- * We'd like to check for if the document readyState is 'loading'; however
- * there are bugs on IE 10 and below where the readyState being anything other
- * than 'complete' is not reliable.
- * @return {boolean}
- * @private
- */
- goog.isDocumentLoading_ = function() {
- // attachEvent is available on IE 6 thru 10 only, and thus can be used to
- // detect those browsers.
- /** @type {!HTMLDocument} */
- var doc = goog.global.document;
- return doc.attachEvent ? doc.readyState != 'complete' :
- doc.readyState == 'loading';
- };
- /**
- * Tries to detect the base path of base.js script that bootstraps Closure.
- * @private
- */
- goog.findBasePath_ = function() {
- if (goog.global.CLOSURE_BASE_PATH != undefined &&
- // Anti DOM-clobbering runtime check (b/37736576).
- typeof goog.global.CLOSURE_BASE_PATH === 'string') {
- goog.basePath = goog.global.CLOSURE_BASE_PATH;
- return;
- } else if (!goog.inHtmlDocument_()) {
- return;
- }
- /** @type {!Document} */
- var doc = goog.global.document;
- // If we have a currentScript available, use it exclusively.
- var currentScript = doc.currentScript;
- if (currentScript) {
- var scripts = [currentScript];
- } else {
- var scripts = doc.getElementsByTagName('SCRIPT');
- }
- // Search backwards since the current script is in almost all cases the one
- // that has base.js.
- for (var i = scripts.length - 1; i >= 0; --i) {
- var script = /** @type {!HTMLScriptElement} */ (scripts[i]);
- var src = script.src;
- var qmark = src.lastIndexOf('?');
- var l = qmark == -1 ? src.length : qmark;
- if (src.substr(l - 7, 7) == 'base.js') {
- goog.basePath = src.substr(0, l - 7);
- return;
- }
- }
- };
- goog.findBasePath_();
- /** @struct @constructor @final */
- goog.Transpiler = function() {
- /** @private {?Object<string, boolean>} */
- this.requiresTranspilation_ = null;
- /** @private {string} */
- this.transpilationTarget_ = goog.TRANSPILE_TO_LANGUAGE;
- };
- /**
- * Returns a newly created map from language mode string to a boolean
- * indicating whether transpilation should be done for that mode as well as
- * the highest level language that this environment supports.
- *
- * Guaranteed invariant:
- * For any two modes, l1 and l2 where l2 is a newer mode than l1,
- * `map[l1] == true` implies that `map[l2] == true`.
- *
- * Note this method is extracted and used elsewhere, so it cannot rely on
- * anything external (it should easily be able to be transformed into a
- * standalone, top level function).
- *
- * @private
- * @return {{
- * target: string,
- * map: !Object<string, boolean>
- * }}
- */
- goog.Transpiler.prototype.createRequiresTranspilation_ = function() {
- var transpilationTarget = 'es3';
- var /** !Object<string, boolean> */ requiresTranspilation = {'es3': false};
- var transpilationRequiredForAllLaterModes = false;
- /**
- * Adds an entry to requiresTranspliation for the given language mode.
- *
- * IMPORTANT: Calls must be made in order from oldest to newest language
- * mode.
- * @param {string} modeName
- * @param {function(): boolean} isSupported Returns true if the JS engine
- * supports the given mode.
- */
- function addNewerLanguageTranspilationCheck(modeName, isSupported) {
- if (transpilationRequiredForAllLaterModes) {
- requiresTranspilation[modeName] = true;
- } else if (isSupported()) {
- transpilationTarget = modeName;
- requiresTranspilation[modeName] = false;
- } else {
- requiresTranspilation[modeName] = true;
- transpilationRequiredForAllLaterModes = true;
- }
- }
- /**
- * Does the given code evaluate without syntax errors and return a truthy
- * result?
- */
- function /** boolean */ evalCheck(/** string */ code) {
- try {
- return !!eval(code);
- } catch (ignored) {
- return false;
- }
- }
- var userAgent = goog.global.navigator && goog.global.navigator.userAgent ?
- goog.global.navigator.userAgent :
- '';
- // Identify ES3-only browsers by their incorrect treatment of commas.
- addNewerLanguageTranspilationCheck('es5', function() {
- return evalCheck('[1,].length==1');
- });
- addNewerLanguageTranspilationCheck('es6', function() {
- // Edge has a non-deterministic (i.e., not reproducible) bug with ES6:
- // https://github.com/Microsoft/ChakraCore/issues/1496.
- var re = /Edge\/(\d+)(\.\d)*/i;
- var edgeUserAgent = userAgent.match(re);
- if (edgeUserAgent) {
- // The Reflect.construct test below is flaky on Edge. It can sometimes
- // pass or fail on 40 15.15063, so just exit early for Edge and treat
- // it as ES5. Until we're on a more up to date version just always use
- // ES5. See https://github.com/Microsoft/ChakraCore/issues/3217.
- return false;
- }
- // Test es6: [FF50 (?), Edge 14 (?), Chrome 50]
- // (a) default params (specifically shadowing locals),
- // (b) destructuring, (c) block-scoped functions,
- // (d) for-of (const), (e) new.target/Reflect.construct
- var es6fullTest =
- 'class X{constructor(){if(new.target!=String)throw 1;this.x=42}}' +
- 'let q=Reflect.construct(X,[],String);if(q.x!=42||!(q instanceof ' +
- 'String))throw 1;for(const a of[2,3]){if(a==2)continue;function ' +
- 'f(z={a}){let a=0;return z.a}{function f(){return 0;}}return f()' +
- '==3}';
- return evalCheck('(()=>{"use strict";' + es6fullTest + '})()');
- });
- // ** and **= are the only new features in 'es7'
- addNewerLanguageTranspilationCheck('es7', function() {
- return evalCheck('2 ** 2 == 4');
- });
- // async functions are the only new features in 'es8'
- addNewerLanguageTranspilationCheck('es8', function() {
- return evalCheck('async () => 1, true');
- });
- addNewerLanguageTranspilationCheck('es9', function() {
- return evalCheck('({...rest} = {}), true');
- });
- addNewerLanguageTranspilationCheck('es_next', function() {
- return false; // assume it always need to transpile
- });
- return {target: transpilationTarget, map: requiresTranspilation};
- };
- /**
- * Determines whether the given language needs to be transpiled.
- * @param {string} lang
- * @param {string|undefined} module
- * @return {boolean}
- */
- goog.Transpiler.prototype.needsTranspile = function(lang, module) {
- if (goog.TRANSPILE == 'always') {
- return true;
- } else if (goog.TRANSPILE == 'never') {
- return false;
- } else if (!this.requiresTranspilation_) {
- var obj = this.createRequiresTranspilation_();
- this.requiresTranspilation_ = obj.map;
- this.transpilationTarget_ = this.transpilationTarget_ || obj.target;
- }
- if (lang in this.requiresTranspilation_) {
- if (this.requiresTranspilation_[lang]) {
- return true;
- } else if (
- goog.inHtmlDocument_() && module == 'es6' &&
- !('noModule' in goog.global.document.createElement('script'))) {
- return true;
- } else {
- return false;
- }
- } else {
- throw new Error('Unknown language mode: ' + lang);
- }
- };
- /**
- * Lazily retrieves the transpiler and applies it to the source.
- * @param {string} code JS code.
- * @param {string} path Path to the code.
- * @return {string} The transpiled code.
- */
- goog.Transpiler.prototype.transpile = function(code, path) {
- // TODO(johnplaisted): We should delete goog.transpile_ and just have this
- // function. But there's some compile error atm where goog.global is being
- // stripped incorrectly without this.
- return goog.transpile_(code, path, this.transpilationTarget_);
- };
- /** @private @final {!goog.Transpiler} */
- goog.transpiler_ = new goog.Transpiler();
- /**
- * Rewrites closing script tags in input to avoid ending an enclosing script
- * tag.
- *
- * @param {string} str
- * @return {string}
- * @private
- */
- goog.protectScriptTag_ = function(str) {
- return str.replace(/<\/(SCRIPT)/ig, '\\x3c/$1');
- };
- /**
- * A debug loader is responsible for downloading and executing javascript
- * files in an unbundled, uncompiled environment.
- *
- * This can be custimized via the setDependencyFactory method, or by
- * CLOSURE_IMPORT_SCRIPT/CLOSURE_LOAD_FILE_SYNC.
- *
- * @struct @constructor @final @private
- */
- goog.DebugLoader_ = function() {
- /** @private @const {!Object<string, !goog.Dependency>} */
- this.dependencies_ = {};
- /** @private @const {!Object<string, string>} */
- this.idToPath_ = {};
- /** @private @const {!Object<string, boolean>} */
- this.written_ = {};
- /** @private @const {!Array<!goog.Dependency>} */
- this.loadingDeps_ = [];
- /** @private {!Array<!goog.Dependency>} */
- this.depsToLoad_ = [];
- /** @private {boolean} */
- this.paused_ = false;
- /** @private {!goog.DependencyFactory} */
- this.factory_ = new goog.DependencyFactory(goog.transpiler_);
- /** @private @const {!Object<string, !Function>} */
- this.deferredCallbacks_ = {};
- /** @private @const {!Array<string>} */
- this.deferredQueue_ = [];
- };
- /**
- * @param {!Array<string>} namespaces
- * @param {function(): undefined} callback Function to call once all the
- * namespaces have loaded.
- */
- goog.DebugLoader_.prototype.bootstrap = function(namespaces, callback) {
- var cb = callback;
- function resolve() {
- if (cb) {
- goog.global.setTimeout(cb, 0);
- cb = null;
- }
- }
- if (!namespaces.length) {
- resolve();
- return;
- }
- var deps = [];
- for (var i = 0; i < namespaces.length; i++) {
- var path = this.getPathFromDeps_(namespaces[i]);
- if (!path) {
- throw new Error('Unregonized namespace: ' + namespaces[i]);
- }
- deps.push(this.dependencies_[path]);
- }
- var require = goog.require;
- var loaded = 0;
- for (var i = 0; i < namespaces.length; i++) {
- require(namespaces[i]);
- deps[i].onLoad(function() {
- if (++loaded == namespaces.length) {
- resolve();
- }
- });
- }
- };
- /**
- * Loads the Closure Dependency file.
- *
- * Exposed a public function so CLOSURE_NO_DEPS can be set to false, base
- * loaded, setDependencyFactory called, and then this called. i.e. allows
- * custom loading of the deps file.
- */
- goog.DebugLoader_.prototype.loadClosureDeps = function() {
- // Circumvent addDependency, which would try to transpile deps.js if
- // transpile is set to always.
- var relPath = 'deps.js';
- this.depsToLoad_.push(this.factory_.createDependency(
- goog.normalizePath_(goog.basePath + relPath), relPath, [], [], {},
- false));
- this.loadDeps_();
- };
- /**
- * Notifies the debug loader when a dependency has been requested.
- *
- * @param {string} absPathOrId Path of the dependency or goog id.
- * @param {boolean=} opt_force
- */
- goog.DebugLoader_.prototype.requested = function(absPathOrId, opt_force) {
- var path = this.getPathFromDeps_(absPathOrId);
- if (path &&
- (opt_force || this.areDepsLoaded_(this.dependencies_[path].requires))) {
- var callback = this.deferredCallbacks_[path];
- if (callback) {
- delete this.deferredCallbacks_[path];
- callback();
- }
- }
- };
- /**
- * Sets the dependency factory, which can be used to create custom
- * goog.Dependency implementations to control how dependencies are loaded.
- *
- * @param {!goog.DependencyFactory} factory
- */
- goog.DebugLoader_.prototype.setDependencyFactory = function(factory) {
- this.factory_ = factory;
- };
- /**
- * Travserses the dependency graph and queues the given dependency, and all of
- * its transitive dependencies, for loading and then starts loading if not
- * paused.
- *
- * @param {string} namespace
- * @private
- */
- goog.DebugLoader_.prototype.load_ = function(namespace) {
- if (!this.getPathFromDeps_(namespace)) {
- var errorMessage = 'goog.require could not find: ' + namespace;
- goog.logToConsole_(errorMessage);
- throw Error(errorMessage);
- } else {
- var loader = this;
- var deps = [];
- /** @param {string} namespace */
- var visit = function(namespace) {
- var path = loader.getPathFromDeps_(namespace);
- if (!path) {
- throw new Error('Bad dependency path or symbol: ' + namespace);
- }
- if (loader.written_[path]) {
- return;
- }
- loader.written_[path] = true;
- var dep = loader.dependencies_[path];
- for (var i = 0; i < dep.requires.length; i++) {
- if (!goog.isProvided_(dep.requires[i])) {
- visit(dep.requires[i]);
- }
- }
- deps.push(dep);
- };
- visit(namespace);
- var wasLoading = !!this.depsToLoad_.length;
- this.depsToLoad_ = this.depsToLoad_.concat(deps);
- if (!this.paused_ && !wasLoading) {
- this.loadDeps_();
- }
- }
- };
- /**
- * Loads any queued dependencies until they are all loaded or paused.
- *
- * @private
- */
- goog.DebugLoader_.prototype.loadDeps_ = function() {
- var loader = this;
- var paused = this.paused_;
- while (this.depsToLoad_.length && !paused) {
- (function() {
- var loadCallDone = false;
- var dep = loader.depsToLoad_.shift();
- var loaded = false;
- loader.loading_(dep);
- var controller = {
- pause: function() {
- if (loadCallDone) {
- throw new Error('Cannot call pause after the call to load.');
- } else {
- paused = true;
- }
- },
- resume: function() {
- if (loadCallDone) {
- loader.resume_();
- } else {
- // Some dep called pause and then resume in the same load call.
- // Just keep running this same loop.
- paused = false;
- }
- },
- loaded: function() {
- if (loaded) {
- throw new Error('Double call to loaded.');
- }
- loaded = true;
- loader.loaded_(dep);
- },
- pending: function() {
- // Defensive copy.
- var pending = [];
- for (var i = 0; i < loader.loadingDeps_.length; i++) {
- pending.push(loader.loadingDeps_[i]);
- }
- return pending;
- },
- /**
- * @param {goog.ModuleType} type
- */
- setModuleState: function(type) {
- goog.moduleLoaderState_ = {
- type: type,
- moduleName: '',
- declareLegacyNamespace: false
- };
- },
- /** @type {function(string, string, string=)} */
- registerEs6ModuleExports: function(
- path, exports, opt_closureNamespace) {
- if (opt_closureNamespace) {
- goog.loadedModules_[opt_closureNamespace] = {
- exports: exports,
- type: goog.ModuleType.ES6,
- moduleId: opt_closureNamespace || ''
- };
- }
- },
- /** @type {function(string, ?)} */
- registerGoogModuleExports: function(moduleId, exports) {
- goog.loadedModules_[moduleId] = {
- exports: exports,
- type: goog.ModuleType.GOOG,
- moduleId: moduleId
- };
- },
- clearModuleState: function() {
- goog.moduleLoaderState_ = null;
- },
- defer: function(callback) {
- if (loadCallDone) {
- throw new Error(
- 'Cannot register with defer after the call to load.');
- }
- loader.defer_(dep, callback);
- },
- areDepsLoaded: function() {
- return loader.areDepsLoaded_(dep.requires);
- }
- };
- try {
- dep.load(controller);
- } finally {
- loadCallDone = true;
- }
- })();
- }
- if (paused) {
- this.pause_();
- }
- };
- /** @private */
- goog.DebugLoader_.prototype.pause_ = function() {
- this.paused_ = true;
- };
- /** @private */
- goog.DebugLoader_.prototype.resume_ = function() {
- if (this.paused_) {
- this.paused_ = false;
- this.loadDeps_();
- }
- };
- /**
- * Marks the given dependency as loading (load has been called but it has not
- * yet marked itself as finished). Useful for dependencies that want to know
- * what else is loading. Example: goog.modules cannot eval if there are
- * loading dependencies.
- *
- * @param {!goog.Dependency} dep
- * @private
- */
- goog.DebugLoader_.prototype.loading_ = function(dep) {
- this.loadingDeps_.push(dep);
- };
- /**
- * Marks the given dependency as having finished loading and being available
- * for require.
- *
- * @param {!goog.Dependency} dep
- * @private
- */
- goog.DebugLoader_.prototype.loaded_ = function(dep) {
- for (var i = 0; i < this.loadingDeps_.length; i++) {
- if (this.loadingDeps_[i] == dep) {
- this.loadingDeps_.splice(i, 1);
- break;
- }
- }
- for (var i = 0; i < this.deferredQueue_.length; i++) {
- if (this.deferredQueue_[i] == dep.path) {
- this.deferredQueue_.splice(i, 1);
- break;
- }
- }
- if (this.loadingDeps_.length == this.deferredQueue_.length &&
- !this.depsToLoad_.length) {
- // Something has asked to load these, but they may not be directly
- // required again later, so load them now that we know we're done loading
- // everything else. e.g. a goog module entry point.
- while (this.deferredQueue_.length) {
- this.requested(this.deferredQueue_.shift(), true);
- }
- }
- dep.loaded();
- };
- /**
- * @param {!Array<string>} pathsOrIds
- * @return {boolean}
- * @private
- */
- goog.DebugLoader_.prototype.areDepsLoaded_ = function(pathsOrIds) {
- for (var i = 0; i < pathsOrIds.length; i++) {
- var path = this.getPathFromDeps_(pathsOrIds[i]);
- if (!path ||
- (!(path in this.deferredCallbacks_) &&
- !goog.isProvided_(pathsOrIds[i]))) {
- return false;
- }
- }
- return true;
- };
- /**
- * @param {string} absPathOrId
- * @return {?string}
- * @private
- */
- goog.DebugLoader_.prototype.getPathFromDeps_ = function(absPathOrId) {
- if (absPathOrId in this.idToPath_) {
- return this.idToPath_[absPathOrId];
- } else if (absPathOrId in this.dependencies_) {
- return absPathOrId;
- } else {
- return null;
- }
- };
- /**
- * @param {!goog.Dependency} dependency
- * @param {!Function} callback
- * @private
- */
- goog.DebugLoader_.prototype.defer_ = function(dependency, callback) {
- this.deferredCallbacks_[dependency.path] = callback;
- this.deferredQueue_.push(dependency.path);
- };
- /**
- * Interface for goog.Dependency implementations to have some control over
- * loading of dependencies.
- *
- * @record
- */
- goog.LoadController = function() {};
- /**
- * Tells the controller to halt loading of more dependencies.
- */
- goog.LoadController.prototype.pause = function() {};
- /**
- * Tells the controller to resume loading of more dependencies if paused.
- */
- goog.LoadController.prototype.resume = function() {};
- /**
- * Tells the controller that this dependency has finished loading.
- *
- * This causes this to be removed from pending() and any load callbacks to
- * fire.
- */
- goog.LoadController.prototype.loaded = function() {};
- /**
- * List of dependencies on which load has been called but which have not
- * called loaded on their controller. This includes the current dependency.
- *
- * @return {!Array<!goog.Dependency>}
- */
- goog.LoadController.prototype.pending = function() {};
- /**
- * Registers an object as an ES6 module's exports so that goog.modules may
- * require it by path.
- *
- * @param {string} path Full path of the module.
- * @param {?} exports
- * @param {string=} opt_closureNamespace Closure namespace to associate with
- * this module.
- */
- goog.LoadController.prototype.registerEs6ModuleExports = function(
- path, exports, opt_closureNamespace) {};
- /**
- * Sets the current module state.
- *
- * @param {goog.ModuleType} type Type of module.
- */
- goog.LoadController.prototype.setModuleState = function(type) {};
- /**
- * Clears the current module state.
- */
- goog.LoadController.prototype.clearModuleState = function() {};
- /**
- * Registers a callback to call once the dependency is actually requested
- * via goog.require + all of the immediate dependencies have been loaded or
- * all other files have been loaded. Allows for lazy loading until
- * require'd without pausing dependency loading, which is needed on old IE.
- *
- * @param {!Function} callback
- */
- goog.LoadController.prototype.defer = function(callback) {};
- /**
- * @return {boolean}
- */
- goog.LoadController.prototype.areDepsLoaded = function() {};
- /**
- * Basic super class for all dependencies Closure Library can load.
- *
- * This default implementation is designed to load untranspiled, non-module
- * scripts in a web broswer.
- *
- * For transpiled non-goog.module files {@see goog.TranspiledDependency}.
- * For goog.modules see {@see goog.GoogModuleDependency}.
- * For untranspiled ES6 modules {@see goog.Es6ModuleDependency}.
- *
- * @param {string} path Absolute path of this script.
- * @param {string} relativePath Path of this script relative to goog.basePath.
- * @param {!Array<string>} provides goog.provided or goog.module symbols
- * in this file.
- * @param {!Array<string>} requires goog symbols or relative paths to Closure
- * this depends on.
- * @param {!Object<string, string>} loadFlags
- * @struct @constructor
- */
- goog.Dependency = function(
- path, relativePath, provides, requires, loadFlags) {
- /** @const */
- this.path = path;
- /** @const */
- this.relativePath = relativePath;
- /** @const */
- this.provides = provides;
- /** @const */
- this.requires = requires;
- /** @const */
- this.loadFlags = loadFlags;
- /** @private {boolean} */
- this.loaded_ = false;
- /** @private {!Array<function()>} */
- this.loadCallbacks_ = [];
- };
- /**
- * @return {string} The pathname part of this dependency's path if it is a
- * URI.
- */
- goog.Dependency.prototype.getPathName = function() {
- var pathName = this.path;
- var protocolIndex = pathName.indexOf('://');
- if (protocolIndex >= 0) {
- pathName = pathName.substring(protocolIndex + 3);
- var slashIndex = pathName.indexOf('/');
- if (slashIndex >= 0) {
- pathName = pathName.substring(slashIndex + 1);
- }
- }
- return pathName;
- };
- /**
- * @param {function()} callback Callback to fire as soon as this has loaded.
- * @final
- */
- goog.Dependency.prototype.onLoad = function(callback) {
- if (this.loaded_) {
- callback();
- } else {
- this.loadCallbacks_.push(callback);
- }
- };
- /**
- * Marks this dependency as loaded and fires any callbacks registered with
- * onLoad.
- * @final
- */
- goog.Dependency.prototype.loaded = function() {
- this.loaded_ = true;
- var callbacks = this.loadCallbacks_;
- this.loadCallbacks_ = [];
- for (var i = 0; i < callbacks.length; i++) {
- callbacks[i]();
- }
- };
- /**
- * Whether or not document.written / appended script tags should be deferred.
- *
- * @private {boolean}
- */
- goog.Dependency.defer_ = false;
- /**
- * Map of script ready / state change callbacks. Old IE cannot handle putting
- * these properties on goog.global.
- *
- * @private @const {!Object<string, function(?):undefined>}
- */
- goog.Dependency.callbackMap_ = {};
- /**
- * @param {function(...?):?} callback
- * @return {string}
- * @private
- */
- goog.Dependency.registerCallback_ = function(callback) {
- var key = Math.random().toString(32);
- goog.Dependency.callbackMap_[key] = callback;
- return key;
- };
- /**
- * @param {string} key
- * @private
- */
- goog.Dependency.unregisterCallback_ = function(key) {
- delete goog.Dependency.callbackMap_[key];
- };
- /**
- * @param {string} key
- * @param {...?} var_args
- * @private
- * @suppress {unusedPrivateMembers}
- */
- goog.Dependency.callback_ = function(key, var_args) {
- if (key in goog.Dependency.callbackMap_) {
- var callback = goog.Dependency.callbackMap_[key];
- var args = [];
- for (var i = 1; i < arguments.length; i++) {
- args.push(arguments[i]);
- }
- callback.apply(undefined, args);
- } else {
- var errorMessage = 'Callback key ' + key +
- ' does not exist (was base.js loaded more than once?).';
- throw Error(errorMessage);
- }
- };
- /**
- * Starts loading this dependency. This dependency can pause loading if it
- * needs to and resume it later via the controller interface.
- *
- * When this is loaded it should call controller.loaded(). Note that this will
- * end up calling the loaded method of this dependency; there is no need to
- * call it explicitly.
- *
- * @param {!goog.LoadController} controller
- */
- goog.Dependency.prototype.load = function(controller) {
- if (goog.global.CLOSURE_IMPORT_SCRIPT) {
- if (goog.global.CLOSURE_IMPORT_SCRIPT(this.path)) {
- controller.loaded();
- } else {
- controller.pause();
- }
- return;
- }
- if (!goog.inHtmlDocument_()) {
- goog.logToConsole_(
- 'Cannot use default debug loader outside of HTML documents.');
- if (this.relativePath == 'deps.js') {
- // Some old code is relying on base.js auto loading deps.js failing with
- // no error before later setting CLOSURE_IMPORT_SCRIPT.
- // CLOSURE_IMPORT_SCRIPT should be set *before* base.js is loaded, or
- // CLOSURE_NO_DEPS set to true.
- goog.logToConsole_(
- 'Consider setting CLOSURE_IMPORT_SCRIPT before loading base.js, ' +
- 'or setting CLOSURE_NO_DEPS to true.');
- controller.loaded();
- } else {
- controller.pause();
- }
- return;
- }
- /** @type {!HTMLDocument} */
- var doc = goog.global.document;
- // If the user tries to require a new symbol after document load,
- // something has gone terribly wrong. Doing a document.write would
- // wipe out the page. This does not apply to the CSP-compliant method
- // of writing script tags.
- if (doc.readyState == 'complete' &&
- !goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING) {
- // Certain test frameworks load base.js multiple times, which tries
- // to write deps.js each time. If that happens, just fail silently.
- // These frameworks wipe the page between each load of base.js, so this
- // is OK.
- var isDeps = /\bdeps.js$/.test(this.path);
- if (isDeps) {
- controller.loaded();
- return;
- } else {
- throw Error('Cannot write "' + this.path + '" after document load');
- }
- }
- if (!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING &&
- goog.isDocumentLoading_()) {
- var key = goog.Dependency.registerCallback_(function(script) {
- if (!goog.DebugLoader_.IS_OLD_IE_ || script.readyState == 'complete') {
- goog.Dependency.unregisterCallback_(key);
- controller.loaded();
- }
- });
- var nonceAttr = !goog.DebugLoader_.IS_OLD_IE_ && goog.getScriptNonce() ?
- ' nonce="' + goog.getScriptNonce() + '"' :
- '';
- var event =
- goog.DebugLoader_.IS_OLD_IE_ ? 'onreadystatechange' : 'onload';
- var defer = goog.Dependency.defer_ ? 'defer' : '';
- var script = '<script src="' + this.path + '" ' + event +
- '="goog.Dependency.callback_(\'' + key +
- '\', this)" type="text/javascript" ' + defer + nonceAttr + '><' +
- '/script>';
- doc.write(
- goog.TRUSTED_TYPES_POLICY_ ?
- goog.TRUSTED_TYPES_POLICY_.createHTML(script) :
- script);
- } else {
- var scriptEl =
- /** @type {!HTMLScriptElement} */ (doc.createElement('script'));
- scriptEl.defer = goog.Dependency.defer_;
- scriptEl.async = false;
- scriptEl.type = 'text/javascript';
- // If CSP nonces are used, propagate them to dynamically created scripts.
- // This is necessary to allow nonce-based CSPs without 'strict-dynamic'.
- var nonce = goog.getScriptNonce();
- if (nonce) {
- scriptEl.setAttribute('nonce', nonce);
- }
- if (goog.DebugLoader_.IS_OLD_IE_) {
- // Execution order is not guaranteed on old IE, halt loading and write
- // these scripts one at a time, after each loads.
- controller.pause();
- scriptEl.onreadystatechange = function() {
- if (scriptEl.readyState == 'loaded' ||
- scriptEl.readyState == 'complete') {
- controller.loaded();
- controller.resume();
- }
- };
- } else {
- scriptEl.onload = function() {
- scriptEl.onload = null;
- controller.loaded();
- };
- }
- scriptEl.src = goog.TRUSTED_TYPES_POLICY_ ?
- goog.TRUSTED_TYPES_POLICY_.createScriptURL(this.path) :
- this.path;
- doc.head.appendChild(scriptEl);
- }
- };
- /**
- * @param {string} path Absolute path of this script.
- * @param {string} relativePath Path of this script relative to goog.basePath.
- * @param {!Array<string>} provides Should be an empty array.
- * TODO(johnplaisted) add support for adding closure namespaces to ES6
- * modules for interop purposes.
- * @param {!Array<string>} requires goog symbols or relative paths to Closure
- * this depends on.
- * @param {!Object<string, string>} loadFlags
- * @struct @constructor
- * @extends {goog.Dependency}
- */
- goog.Es6ModuleDependency = function(
- path, relativePath, provides, requires, loadFlags) {
- goog.Es6ModuleDependency.base(
- this, 'constructor', path, relativePath, provides, requires, loadFlags);
- };
- goog.inherits(goog.Es6ModuleDependency, goog.Dependency);
- /** @override */
- goog.Es6ModuleDependency.prototype.load = function(controller) {
- if (goog.global.CLOSURE_IMPORT_SCRIPT) {
- if (goog.global.CLOSURE_IMPORT_SCRIPT(this.path)) {
- controller.loaded();
- } else {
- controller.pause();
- }
- return;
- }
- if (!goog.inHtmlDocument_()) {
- goog.logToConsole_(
- 'Cannot use default debug loader outside of HTML documents.');
- controller.pause();
- return;
- }
- /** @type {!HTMLDocument} */
- var doc = goog.global.document;
- var dep = this;
- // TODO(johnplaisted): Does document.writing really speed up anything? Any
- // difference between this and just waiting for interactive mode and then
- // appending?
- function write(src, contents) {
- if (contents) {
- var script = '<script type="module" crossorigin>' + contents + '</' +
- 'script>';
- doc.write(
- goog.TRUSTED_TYPES_POLICY_ ?
- goog.TRUSTED_TYPES_POLICY_.createHTML(script) :
- script);
- } else {
- var script = '<script type="module" crossorigin src="' + src + '"></' +
- 'script>';
- doc.write(
- goog.TRUSTED_TYPES_POLICY_ ?
- goog.TRUSTED_TYPES_POLICY_.createHTML(script) :
- script);
- }
- }
- function append(src, contents) {
- var scriptEl =
- /** @type {!HTMLScriptElement} */ (doc.createElement('script'));
- scriptEl.defer = true;
- scriptEl.async = false;
- scriptEl.type = 'module';
- scriptEl.setAttribute('crossorigin', true);
- // If CSP nonces are used, propagate them to dynamically created scripts.
- // This is necessary to allow nonce-based CSPs without 'strict-dynamic'.
- var nonce = goog.getScriptNonce();
- if (nonce) {
- scriptEl.setAttribute('nonce', nonce);
- }
- if (contents) {
- scriptEl.textContent = goog.TRUSTED_TYPES_POLICY_ ?
- goog.TRUSTED_TYPES_POLICY_.createScript(contents) :
- contents;
- } else {
- scriptEl.src = goog.TRUSTED_TYPES_POLICY_ ?
- goog.TRUSTED_TYPES_POLICY_.createScriptURL(src) :
- src;
- }
- doc.head.appendChild(scriptEl);
- }
- var create;
- if (goog.isDocumentLoading_()) {
- create = write;
- // We can ONLY call document.write if we are guaranteed that any
- // non-module script tags document.written after this are deferred.
- // Small optimization, in theory document.writing is faster.
- goog.Dependency.defer_ = true;
- } else {
- create = append;
- }
- // Write 4 separate tags here:
- // 1) Sets the module state at the correct time (just before execution).
- // 2) A src node for this, which just hopefully lets the browser load it a
- // little early (no need to parse #3).
- // 3) Import the module and register it.
- // 4) Clear the module state at the correct time. Guaranteed to run even
- // if there is an error in the module (#3 will not run if there is an
- // error in the module).
- var beforeKey = goog.Dependency.registerCallback_(function() {
- goog.Dependency.unregisterCallback_(beforeKey);
- controller.setModuleState(goog.ModuleType.ES6);
- });
- create(undefined, 'goog.Dependency.callback_("' + beforeKey + '")');
- // TODO(johnplaisted): Does this really speed up anything?
- create(this.path, undefined);
- var registerKey = goog.Dependency.registerCallback_(function(exports) {
- goog.Dependency.unregisterCallback_(registerKey);
- controller.registerEs6ModuleExports(
- dep.path, exports, goog.moduleLoaderState_.moduleName);
- });
- create(
- undefined,
- 'import * as m from "' + this.path + '"; goog.Dependency.callback_("' +
- registerKey + '", m)');
- var afterKey = goog.Dependency.registerCallback_(function() {
- goog.Dependency.unregisterCallback_(afterKey);
- controller.clearModuleState();
- controller.loaded();
- });
- create(undefined, 'goog.Dependency.callback_("' + afterKey + '")');
- };
- /**
- * Superclass of any dependency that needs to be loaded into memory,
- * transformed, and then eval'd (goog.modules and transpiled files).
- *
- * @param {string} path Absolute path of this script.
- * @param {string} relativePath Path of this script relative to goog.basePath.
- * @param {!Array<string>} provides goog.provided or goog.module symbols
- * in this file.
- * @param {!Array<string>} requires goog symbols or relative paths to Closure
- * this depends on.
- * @param {!Object<string, string>} loadFlags
- * @struct @constructor @abstract
- * @extends {goog.Dependency}
- */
- goog.TransformedDependency = function(
- path, relativePath, provides, requires, loadFlags) {
- goog.TransformedDependency.base(
- this, 'constructor', path, relativePath, provides, requires, loadFlags);
- /** @private {?string} */
- this.contents_ = null;
- /**
- * Whether to lazily make the synchronous XHR (when goog.require'd) or make
- * the synchronous XHR when initially loading. On FireFox 61 there is a bug
- * where an ES6 module cannot make a synchronous XHR (rather, it can, but if
- * it does then no other ES6 modules will load after).
- *
- * tl;dr we lazy load due to bugs on older browsers and eager load due to
- * bugs on newer ones.
- *
- * https://bugzilla.mozilla.org/show_bug.cgi?id=1477090
- *
- * @private @const {boolean}
- */
- this.lazyFetch_ = !goog.inHtmlDocument_() ||
- !('noModule' in goog.global.document.createElement('script'));
- };
- goog.inherits(goog.TransformedDependency, goog.Dependency);
- /** @override */
- goog.TransformedDependency.prototype.load = function(controller) {
- var dep = this;
- function fetch() {
- dep.contents_ = goog.loadFileSync_(dep.path);
- if (dep.contents_) {
- dep.contents_ = dep.transform(dep.contents_);
- if (dep.contents_) {
- dep.contents_ += '\n//# sourceURL=' + dep.path;
- }
- }
- }
- if (goog.global.CLOSURE_IMPORT_SCRIPT) {
- fetch();
- if (this.contents_ &&
- goog.global.CLOSURE_IMPORT_SCRIPT('', this.contents_)) {
- this.contents_ = null;
- controller.loaded();
- } else {
- controller.pause();
- }
- return;
- }
- var isEs6 = this.loadFlags['module'] == goog.ModuleType.ES6;
- if (!this.lazyFetch_) {
- fetch();
- }
- function load() {
- if (dep.lazyFetch_) {
- fetch();
- }
- if (!dep.contents_) {
- // loadFileSync_ or transform are responsible. Assume they logged an
- // error.
- return;
- }
- if (isEs6) {
- controller.setModuleState(goog.ModuleType.ES6);
- }
- var namespace;
- try {
- var contents = dep.contents_;
- dep.contents_ = null;
- goog.globalEval(contents);
- if (isEs6) {
- namespace = goog.moduleLoaderState_.moduleName;
- }
- } finally {
- if (isEs6) {
- controller.clearModuleState();
- }
- }
- if (isEs6) {
- // Due to circular dependencies this may not be available for require
- // right now.
- goog.global['$jscomp']['require']['ensure'](
- [dep.getPathName()], function() {
- controller.registerEs6ModuleExports(
- dep.path,
- goog.global['$jscomp']['require'](dep.getPathName()),
- namespace);
- });
- }
- controller.loaded();
- }
- // Do not fetch now; in FireFox 47 the synchronous XHR doesn't block all
- // events. If we fetched now and then document.write'd the contents the
- // document.write would be an eval and would execute too soon! Instead write
- // a script tag to fetch and eval synchronously at the correct time.
- function fetchInOwnScriptThenLoad() {
- /** @type {!HTMLDocument} */
- var doc = goog.global.document;
- var key = goog.Dependency.registerCallback_(function() {
- goog.Dependency.unregisterCallback_(key);
- load();
- });
- var script = '<script type="text/javascript">' +
- goog.protectScriptTag_('goog.Dependency.callback_("' + key + '");') +
- '</' +
- 'script>';
- doc.write(
- goog.TRUSTED_TYPES_POLICY_ ?
- goog.TRUSTED_TYPES_POLICY_.createHTML(script) :
- script);
- }
- // If one thing is pending it is this.
- var anythingElsePending = controller.pending().length > 1;
- // If anything else is loading we need to lazy load due to bugs in old IE.
- // Specifically script tags with src and script tags with contents could
- // execute out of order if document.write is used, so we cannot use
- // document.write. Do not pause here; it breaks old IE as well.
- var useOldIeWorkAround =
- anythingElsePending && goog.DebugLoader_.IS_OLD_IE_;
- // Additionally if we are meant to defer scripts but the page is still
- // loading (e.g. an ES6 module is loading) then also defer. Or if we are
- // meant to defer and anything else is pending then defer (those may be
- // scripts that did not need transformation and are just script tags with
- // defer set to true, and we need to evaluate after that deferred script).
- var needsAsyncLoading = goog.Dependency.defer_ &&
- (anythingElsePending || goog.isDocumentLoading_());
- if (useOldIeWorkAround || needsAsyncLoading) {
- // Note that we only defer when we have to rather than 100% of the time.
- // Always defering would work, but then in theory the order of
- // goog.require calls would then matter. We want to enforce that most of
- // the time the order of the require calls does not matter.
- controller.defer(function() {
- load();
- });
- return;
- }
- // TODO(johnplaisted): Externs are missing onreadystatechange for
- // HTMLDocument.
- /** @type {?} */
- var doc = goog.global.document;
- var isInternetExplorer =
- goog.inHtmlDocument_() && 'ActiveXObject' in goog.global;
- // Don't delay in any version of IE. There's bug around this that will
- // cause out of order script execution. This means that on older IE ES6
- // modules will load too early (while the document is still loading + the
- // dom is not available). The other option is to load too late (when the
- // document is complete and the onload even will never fire). This seems
- // to be the lesser of two evils as scripts already act like the former.
- if (isEs6 && goog.inHtmlDocument_() && goog.isDocumentLoading_() &&
- !isInternetExplorer) {
- goog.Dependency.defer_ = true;
- // Transpiled ES6 modules still need to load like regular ES6 modules,
- // aka only after the document is interactive.
- controller.pause();
- var oldCallback = doc.onreadystatechange;
- doc.onreadystatechange = function() {
- if (doc.readyState == 'interactive') {
- doc.onreadystatechange = oldCallback;
- load();
- controller.resume();
- }
- if (goog.isFunction(oldCallback)) {
- oldCallback.apply(undefined, arguments);
- }
- };
- } else {
- // Always eval on old IE.
- if (goog.DebugLoader_.IS_OLD_IE_ || !goog.inHtmlDocument_() ||
- !goog.isDocumentLoading_()) {
- load();
- } else {
- fetchInOwnScriptThenLoad();
- }
- }
- };
- /**
- * @param {string} contents
- * @return {string}
- * @abstract
- */
- goog.TransformedDependency.prototype.transform = function(contents) {};
- /**
- * Any non-goog.module dependency which needs to be transpiled before eval.
- *
- * @param {string} path Absolute path of this script.
- * @param {string} relativePath Path of this script relative to goog.basePath.
- * @param {!Array<string>} provides goog.provided or goog.module symbols
- * in this file.
- * @param {!Array<string>} requires goog symbols or relative paths to Closure
- * this depends on.
- * @param {!Object<string, string>} loadFlags
- * @param {!goog.Transpiler} transpiler
- * @struct @constructor
- * @extends {goog.TransformedDependency}
- */
- goog.TranspiledDependency = function(
- path, relativePath, provides, requires, loadFlags, transpiler) {
- goog.TranspiledDependency.base(
- this, 'constructor', path, relativePath, provides, requires, loadFlags);
- /** @protected @const*/
- this.transpiler = transpiler;
- };
- goog.inherits(goog.TranspiledDependency, goog.TransformedDependency);
- /** @override */
- goog.TranspiledDependency.prototype.transform = function(contents) {
- // Transpile with the pathname so that ES6 modules are domain agnostic.
- return this.transpiler.transpile(contents, this.getPathName());
- };
- /**
- * An ES6 module dependency that was transpiled to a jscomp module outside
- * of the debug loader, e.g. server side.
- *
- * @param {string} path Absolute path of this script.
- * @param {string} relativePath Path of this script relative to goog.basePath.
- * @param {!Array<string>} provides goog.provided or goog.module symbols
- * in this file.
- * @param {!Array<string>} requires goog symbols or relative paths to Closure
- * this depends on.
- * @param {!Object<string, string>} loadFlags
- * @struct @constructor
- * @extends {goog.TransformedDependency}
- */
- goog.PreTranspiledEs6ModuleDependency = function(
- path, relativePath, provides, requires, loadFlags) {
- goog.PreTranspiledEs6ModuleDependency.base(
- this, 'constructor', path, relativePath, provides, requires, loadFlags);
- };
- goog.inherits(
- goog.PreTranspiledEs6ModuleDependency, goog.TransformedDependency);
- /** @override */
- goog.PreTranspiledEs6ModuleDependency.prototype.transform = function(
- contents) {
- return contents;
- };
- /**
- * A goog.module, transpiled or not. Will always perform some minimal
- * transformation even when not transpiled to wrap in a goog.loadModule
- * statement.
- *
- * @param {string} path Absolute path of this script.
- * @param {string} relativePath Path of this script relative to goog.basePath.
- * @param {!Array<string>} provides goog.provided or goog.module symbols
- * in this file.
- * @param {!Array<string>} requires goog symbols or relative paths to Closure
- * this depends on.
- * @param {!Object<string, string>} loadFlags
- * @param {boolean} needsTranspile
- * @param {!goog.Transpiler} transpiler
- * @struct @constructor
- * @extends {goog.TransformedDependency}
- */
- goog.GoogModuleDependency = function(
- path, relativePath, provides, requires, loadFlags, needsTranspile,
- transpiler) {
- goog.GoogModuleDependency.base(
- this, 'constructor', path, relativePath, provides, requires, loadFlags);
- /** @private @const */
- this.needsTranspile_ = needsTranspile;
- /** @private @const */
- this.transpiler_ = transpiler;
- };
- goog.inherits(goog.GoogModuleDependency, goog.TransformedDependency);
- /** @override */
- goog.GoogModuleDependency.prototype.transform = function(contents) {
- if (this.needsTranspile_) {
- contents = this.transpiler_.transpile(contents, this.getPathName());
- }
- if (!goog.LOAD_MODULE_USING_EVAL || goog.global.JSON === undefined) {
- return '' +
- 'goog.loadModule(function(exports) {' +
- '"use strict";' + contents +
- '\n' + // terminate any trailing single line comment.
- ';return exports' +
- '});' +
- '\n//# sourceURL=' + this.path + '\n';
- } else {
- return '' +
- 'goog.loadModule(' +
- goog.global.JSON.stringify(
- contents + '\n//# sourceURL=' + this.path + '\n') +
- ');';
- }
- };
- /**
- * Whether the browser is IE9 or earlier, which needs special handling
- * for deferred modules.
- * @const @private {boolean}
- */
- goog.DebugLoader_.IS_OLD_IE_ = !!(
- !goog.global.atob && goog.global.document && goog.global.document['all']);
- /**
- * @param {string} relPath
- * @param {!Array<string>|undefined} provides
- * @param {!Array<string>} requires
- * @param {boolean|!Object<string>=} opt_loadFlags
- * @see goog.addDependency
- */
- goog.DebugLoader_.prototype.addDependency = function(
- relPath, provides, requires, opt_loadFlags) {
- provides = provides || [];
- relPath = relPath.replace(/\\/g, '/');
- var path = goog.normalizePath_(goog.basePath + relPath);
- if (!opt_loadFlags || typeof opt_loadFlags === 'boolean') {
- opt_loadFlags = opt_loadFlags ? {'module': goog.ModuleType.GOOG} : {};
- }
- var dep = this.factory_.createDependency(
- path, relPath, provides, requires, opt_loadFlags,
- goog.transpiler_.needsTranspile(
- opt_loadFlags['lang'] || 'es3', opt_loadFlags['module']));
- this.dependencies_[path] = dep;
- for (var i = 0; i < provides.length; i++) {
- this.idToPath_[provides[i]] = path;
- }
- this.idToPath_[relPath] = path;
- };
- /**
- * Creates goog.Dependency instances for the debug loader to load.
- *
- * Should be overridden to have the debug loader use custom subclasses of
- * goog.Dependency.
- *
- * @param {!goog.Transpiler} transpiler
- * @struct @constructor
- */
- goog.DependencyFactory = function(transpiler) {
- /** @protected @const */
- this.transpiler = transpiler;
- };
- /**
- * @param {string} path Absolute path of the file.
- * @param {string} relativePath Path relative to closure’s base.js.
- * @param {!Array<string>} provides Array of provided goog.provide/module ids.
- * @param {!Array<string>} requires Array of required goog.provide/module /
- * relative ES6 module paths.
- * @param {!Object<string, string>} loadFlags
- * @param {boolean} needsTranspile True if the file needs to be transpiled
- * per the goog.Transpiler.
- * @return {!goog.Dependency}
- */
- goog.DependencyFactory.prototype.createDependency = function(
- path, relativePath, provides, requires, loadFlags, needsTranspile) {
- if (loadFlags['module'] == goog.ModuleType.GOOG) {
- return new goog.GoogModuleDependency(
- path, relativePath, provides, requires, loadFlags, needsTranspile,
- this.transpiler);
- } else if (needsTranspile) {
- return new goog.TranspiledDependency(
- path, relativePath, provides, requires, loadFlags, this.transpiler);
- } else {
- if (loadFlags['module'] == goog.ModuleType.ES6) {
- if (goog.TRANSPILE == 'never' && goog.ASSUME_ES_MODULES_TRANSPILED) {
- return new goog.PreTranspiledEs6ModuleDependency(
- path, relativePath, provides, requires, loadFlags);
- } else {
- return new goog.Es6ModuleDependency(
- path, relativePath, provides, requires, loadFlags);
- }
- } else {
- return new goog.Dependency(
- path, relativePath, provides, requires, loadFlags);
- }
- }
- };
- /** @private @const */
- goog.debugLoader_ = new goog.DebugLoader_();
- /**
- * Loads the Closure Dependency file.
- *
- * Exposed a public function so CLOSURE_NO_DEPS can be set to false, base
- * loaded, setDependencyFactory called, and then this called. i.e. allows
- * custom loading of the deps file.
- */
- goog.loadClosureDeps = function() {
- goog.debugLoader_.loadClosureDeps();
- };
- /**
- * Sets the dependency factory, which can be used to create custom
- * goog.Dependency implementations to control how dependencies are loaded.
- *
- * Note: if you wish to call this function and provide your own implemnetation
- * it is a wise idea to set CLOSURE_NO_DEPS to true, otherwise the dependency
- * file and all of its goog.addDependency calls will use the default factory.
- * You can call goog.loadClosureDeps to load the Closure dependency file
- * later, after your factory is injected.
- *
- * @param {!goog.DependencyFactory} factory
- */
- goog.setDependencyFactory = function(factory) {
- goog.debugLoader_.setDependencyFactory(factory);
- };
- if (!goog.global.CLOSURE_NO_DEPS) {
- goog.debugLoader_.loadClosureDeps();
- }
- /**
- * Bootstraps the given namespaces and calls the callback once they are
- * available either via goog.require. This is a replacement for using
- * `goog.require` to bootstrap Closure JavaScript. Previously a `goog.require`
- * in an HTML file would guarantee that the require'd namespace was available
- * in the next immediate script tag. With ES6 modules this no longer a
- * guarantee.
- *
- * @param {!Array<string>} namespaces
- * @param {function(): ?} callback Function to call once all the namespaces
- * have loaded. Always called asynchronously.
- */
- goog.bootstrap = function(namespaces, callback) {
- goog.debugLoader_.bootstrap(namespaces, callback);
- };
- }
- /**
- * @define {string} Trusted Types policy name. If non-empty then Closure will
- * use Trusted Types.
- */
- goog.TRUSTED_TYPES_POLICY_NAME =
- goog.define('goog.TRUSTED_TYPES_POLICY_NAME', '');
- /**
- * Returns the parameter.
- * @param {string} s
- * @return {string}
- * @private
- */
- goog.identity_ = function(s) {
- return s;
- };
- /**
- * Creates Trusted Types policy if Trusted Types are supported by the browser.
- * The policy just blesses any string as a Trusted Type. It is not visibility
- * restricted because anyone can also call TrustedTypes.createPolicy directly.
- * However, the allowed names should be restricted by a HTTP header and the
- * reference to the created policy should be visibility restricted.
- * @param {string} name
- * @return {?TrustedTypePolicy}
- */
- goog.createTrustedTypesPolicy = function(name) {
- var policy = null;
- // TODO(koto): Remove window.TrustedTypes variant when the newer API ships.
- var policyFactory = goog.global.trustedTypes || goog.global.TrustedTypes;
- if (!policyFactory || !policyFactory.createPolicy) {
- return policy;
- }
- // TrustedTypes.createPolicy throws if called with a name that is already
- // registered, even in report-only mode. Until the API changes, catch the
- // error not to break the applications functionally. In such case, the code
- // will fall back to using regular Safe Types.
- // TODO(koto): Remove catching once createPolicy API stops throwing.
- try {
- policy = policyFactory.createPolicy(name, {
- createHTML: goog.identity_,
- createScript: goog.identity_,
- createScriptURL: goog.identity_,
- createURL: goog.identity_
- });
- } catch (e) {
- goog.logToConsole_(e.message);
- }
- return policy;
- };
- /** @private @const {?TrustedTypePolicy} */
- goog.TRUSTED_TYPES_POLICY_ = goog.TRUSTED_TYPES_POLICY_NAME ?
- goog.createTrustedTypesPolicy(goog.TRUSTED_TYPES_POLICY_NAME + '#base') :
- null;
|