closure-base.js 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547
  1. // Copyright 2006 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Bootstrap for the Google JS Library (Closure).
  16. *
  17. * In uncompiled mode base.js will write out Closure's deps file, unless the
  18. * global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects to
  19. * include their own deps file(s) from different locations.
  20. *
  21. * @author arv@google.com (Erik Arvidsson)
  22. *
  23. * @provideGoog
  24. */
  25. /**
  26. * @define {boolean} Overridden to true by the compiler when --closure_pass
  27. * or --mark_as_compiled is specified.
  28. */
  29. var COMPILED = false;
  30. /**
  31. * Base namespace for the Closure library. Checks to see goog is already
  32. * defined in the current scope before assigning to prevent clobbering if
  33. * base.js is loaded more than once.
  34. *
  35. * @const
  36. */
  37. var goog = goog || {};
  38. /**
  39. * Reference to the global context. In most cases this will be 'window'.
  40. */
  41. goog.global = this;
  42. /**
  43. * A hook for overriding the define values in uncompiled mode.
  44. *
  45. * In uncompiled mode, {@code CLOSURE_UNCOMPILED_DEFINES} may be defined before
  46. * loading base.js. If a key is defined in {@code CLOSURE_UNCOMPILED_DEFINES},
  47. * {@code goog.define} will use the value instead of the default value. This
  48. * allows flags to be overwritten without compilation (this is normally
  49. * accomplished with the compiler's "define" flag).
  50. *
  51. * Example:
  52. * <pre>
  53. * var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false};
  54. * </pre>
  55. *
  56. * @type {Object<string, (string|number|boolean)>|undefined}
  57. */
  58. goog.global.CLOSURE_UNCOMPILED_DEFINES;
  59. /**
  60. * A hook for overriding the define values in uncompiled or compiled mode,
  61. * like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In
  62. * uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence.
  63. *
  64. * Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or
  65. * string literals or the compiler will emit an error.
  66. *
  67. * While any @define value may be set, only those set with goog.define will be
  68. * effective for uncompiled code.
  69. *
  70. * Example:
  71. * <pre>
  72. * var CLOSURE_DEFINES = {'goog.DEBUG': false} ;
  73. * </pre>
  74. *
  75. * @type {Object<string, (string|number|boolean)>|undefined}
  76. */
  77. goog.global.CLOSURE_DEFINES;
  78. /**
  79. * Returns true if the specified value is not undefined.
  80. * WARNING: Do not use this to test if an object has a property. Use the in
  81. * operator instead.
  82. *
  83. * @param {?} val Variable to test.
  84. * @return {boolean} Whether variable is defined.
  85. */
  86. goog.isDef = function(val) {
  87. // void 0 always evaluates to undefined and hence we do not need to depend on
  88. // the definition of the global variable named 'undefined'.
  89. return val !== void 0;
  90. };
  91. /**
  92. * Builds an object structure for the provided namespace path, ensuring that
  93. * names that already exist are not overwritten. For example:
  94. * "a.b.c" -> a = {};a.b={};a.b.c={};
  95. * Used by goog.provide and goog.exportSymbol.
  96. * @param {string} name name of the object that this file defines.
  97. * @param {*=} opt_object the object to expose at the end of the path.
  98. * @param {Object=} opt_objectToExportTo The object to add the path to; default
  99. * is |goog.global|.
  100. * @private
  101. */
  102. goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) {
  103. var parts = name.split('.');
  104. var cur = opt_objectToExportTo || goog.global;
  105. // Internet Explorer exhibits strange behavior when throwing errors from
  106. // methods externed in this manner. See the testExportSymbolExceptions in
  107. // base_test.html for an example.
  108. if (!(parts[0] in cur) && cur.execScript) {
  109. cur.execScript('var ' + parts[0]);
  110. }
  111. // Certain browsers cannot parse code in the form for((a in b); c;);
  112. // This pattern is produced by the JSCompiler when it collapses the
  113. // statement above into the conditional loop below. To prevent this from
  114. // happening, use a for-loop and reserve the init logic as below.
  115. // Parentheses added to eliminate strict JS warning in Firefox.
  116. for (var part; parts.length && (part = parts.shift());) {
  117. if (!parts.length && goog.isDef(opt_object)) {
  118. // last part and we have an object; use it
  119. cur[part] = opt_object;
  120. } else if (cur[part]) {
  121. cur = cur[part];
  122. } else {
  123. cur = cur[part] = {};
  124. }
  125. }
  126. };
  127. /**
  128. * Defines a named value. In uncompiled mode, the value is retrieved from
  129. * CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and
  130. * has the property specified, and otherwise used the defined defaultValue.
  131. * When compiled the default can be overridden using the compiler
  132. * options or the value set in the CLOSURE_DEFINES object.
  133. *
  134. * @param {string} name The distinguished name to provide.
  135. * @param {string|number|boolean} defaultValue
  136. */
  137. goog.define = function(name, defaultValue) {
  138. var value = defaultValue;
  139. if (!COMPILED) {
  140. if (goog.global.CLOSURE_UNCOMPILED_DEFINES &&
  141. Object.prototype.hasOwnProperty.call(
  142. goog.global.CLOSURE_UNCOMPILED_DEFINES, name)) {
  143. value = goog.global.CLOSURE_UNCOMPILED_DEFINES[name];
  144. } else if (goog.global.CLOSURE_DEFINES &&
  145. Object.prototype.hasOwnProperty.call(
  146. goog.global.CLOSURE_DEFINES, name)) {
  147. value = goog.global.CLOSURE_DEFINES[name];
  148. }
  149. }
  150. goog.exportPath_(name, value);
  151. };
  152. /**
  153. * @define {boolean} DEBUG is provided as a convenience so that debugging code
  154. * that should not be included in a production js_binary can be easily stripped
  155. * by specifying --define goog.DEBUG=false to the JSCompiler. For example, most
  156. * toString() methods should be declared inside an "if (goog.DEBUG)" conditional
  157. * because they are generally used for debugging purposes and it is difficult
  158. * for the JSCompiler to statically determine whether they are used.
  159. */
  160. goog.define('goog.DEBUG', true);
  161. /**
  162. * @define {string} LOCALE defines the locale being used for compilation. It is
  163. * used to select locale specific data to be compiled in js binary. BUILD rule
  164. * can specify this value by "--define goog.LOCALE=<locale_name>" as JSCompiler
  165. * option.
  166. *
  167. * Take into account that the locale code format is important. You should use
  168. * the canonical Unicode format with hyphen as a delimiter. Language must be
  169. * lowercase, Language Script - Capitalized, Region - UPPERCASE.
  170. * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN.
  171. *
  172. * See more info about locale codes here:
  173. * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers
  174. *
  175. * For language codes you should use values defined by ISO 693-1. See it here
  176. * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from
  177. * this rule: the Hebrew language. For legacy reasons the old code (iw) should
  178. * be used instead of the new code (he), see http://wiki/Main/IIISynonyms.
  179. */
  180. goog.define('goog.LOCALE', 'en'); // default to en
  181. /**
  182. * @define {boolean} Whether this code is running on trusted sites.
  183. *
  184. * On untrusted sites, several native functions can be defined or overridden by
  185. * external libraries like Prototype, Datejs, and JQuery and setting this flag
  186. * to false forces closure to use its own implementations when possible.
  187. *
  188. * If your JavaScript can be loaded by a third party site and you are wary about
  189. * relying on non-standard implementations, specify
  190. * "--define goog.TRUSTED_SITE=false" to the JSCompiler.
  191. */
  192. goog.define('goog.TRUSTED_SITE', true);
  193. /**
  194. * @define {boolean} Whether a project is expected to be running in strict mode.
  195. *
  196. * This define can be used to trigger alternate implementations compatible with
  197. * running in EcmaScript Strict mode or warn about unavailable functionality.
  198. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode
  199. *
  200. */
  201. goog.define('goog.STRICT_MODE_COMPATIBLE', false);
  202. /**
  203. * @define {boolean} Whether code that calls {@link goog.setTestOnly} should
  204. * be disallowed in the compilation unit.
  205. */
  206. goog.define('goog.DISALLOW_TEST_ONLY_CODE', COMPILED && !goog.DEBUG);
  207. /**
  208. * @define {boolean} Whether to use a Chrome app CSP-compliant method for
  209. * loading scripts via goog.require. @see appendScriptSrcNode_.
  210. */
  211. goog.define('goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING', false);
  212. /**
  213. * Defines a namespace in Closure.
  214. *
  215. * A namespace may only be defined once in a codebase. It may be defined using
  216. * goog.provide() or goog.module().
  217. *
  218. * The presence of one or more goog.provide() calls in a file indicates
  219. * that the file defines the given objects/namespaces.
  220. * Provided symbols must not be null or undefined.
  221. *
  222. * In addition, goog.provide() creates the object stubs for a namespace
  223. * (for example, goog.provide("goog.foo.bar") will create the object
  224. * goog.foo.bar if it does not already exist).
  225. *
  226. * Build tools also scan for provide/require/module statements
  227. * to discern dependencies, build dependency files (see deps.js), etc.
  228. *
  229. * @see goog.require
  230. * @see goog.module
  231. * @param {string} name Namespace provided by this file in the form
  232. * "goog.package.part".
  233. */
  234. goog.provide = function(name) {
  235. if (!COMPILED) {
  236. // Ensure that the same namespace isn't provided twice.
  237. // A goog.module/goog.provide maps a goog.require to a specific file
  238. if (goog.isProvided_(name)) {
  239. throw Error('Namespace "' + name + '" already declared.');
  240. }
  241. }
  242. goog.constructNamespace_(name);
  243. };
  244. /**
  245. * @param {string} name Namespace provided by this file in the form
  246. * "goog.package.part".
  247. * @param {Object=} opt_obj The object to embed in the namespace.
  248. * @private
  249. */
  250. goog.constructNamespace_ = function(name, opt_obj) {
  251. if (!COMPILED) {
  252. delete goog.implicitNamespaces_[name];
  253. var namespace = name;
  254. while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) {
  255. if (goog.getObjectByName(namespace)) {
  256. break;
  257. }
  258. goog.implicitNamespaces_[namespace] = true;
  259. }
  260. }
  261. goog.exportPath_(name, opt_obj);
  262. };
  263. /**
  264. * Module identifier validation regexp.
  265. * Note: This is a conservative check, it is very possible to be more lenient,
  266. * the primary exclusion here is "/" and "\" and a leading ".", these
  267. * restrictions are intended to leave the door open for using goog.require
  268. * with relative file paths rather than module identifiers.
  269. * @private
  270. */
  271. goog.VALID_MODULE_RE_ = /^[a-zA-Z_$][a-zA-Z0-9._$]*$/;
  272. /**
  273. * Defines a module in Closure.
  274. *
  275. * Marks that this file must be loaded as a module and claims the namespace.
  276. *
  277. * A namespace may only be defined once in a codebase. It may be defined using
  278. * goog.provide() or goog.module().
  279. *
  280. * goog.module() has three requirements:
  281. * - goog.module may not be used in the same file as goog.provide.
  282. * - goog.module must be the first statement in the file.
  283. * - only one goog.module is allowed per file.
  284. *
  285. * When a goog.module annotated file is loaded, it is enclosed in
  286. * a strict function closure. This means that:
  287. * - any variables declared in a goog.module file are private to the file
  288. * (not global), though the compiler is expected to inline the module.
  289. * - The code must obey all the rules of "strict" JavaScript.
  290. * - the file will be marked as "use strict"
  291. *
  292. * NOTE: unlike goog.provide, goog.module does not declare any symbols by
  293. * itself. If declared symbols are desired, use
  294. * goog.module.declareLegacyNamespace().
  295. *
  296. *
  297. * See the public goog.module proposal: http://goo.gl/Va1hin
  298. *
  299. * @param {string} name Namespace provided by this file in the form
  300. * "goog.package.part", is expected but not required.
  301. */
  302. goog.module = function(name) {
  303. if (!goog.isString(name) ||
  304. !name ||
  305. name.search(goog.VALID_MODULE_RE_) == -1) {
  306. throw Error('Invalid module identifier');
  307. }
  308. if (!goog.isInModuleLoader_()) {
  309. throw Error('Module ' + name + ' has been loaded incorrectly.');
  310. }
  311. if (goog.moduleLoaderState_.moduleName) {
  312. throw Error('goog.module may only be called once per module.');
  313. }
  314. // Store the module name for the loader.
  315. goog.moduleLoaderState_.moduleName = name;
  316. if (!COMPILED) {
  317. // Ensure that the same namespace isn't provided twice.
  318. // A goog.module/goog.provide maps a goog.require to a specific file
  319. if (goog.isProvided_(name)) {
  320. throw Error('Namespace "' + name + '" already declared.');
  321. }
  322. delete goog.implicitNamespaces_[name];
  323. }
  324. };
  325. /**
  326. * @param {string} name The module identifier.
  327. * @return {?} The module exports for an already loaded module or null.
  328. *
  329. * Note: This is not an alternative to goog.require, it does not
  330. * indicate a hard dependency, instead it is used to indicate
  331. * an optional dependency or to access the exports of a module
  332. * that has already been loaded.
  333. * @suppress {missingProvide}
  334. */
  335. goog.module.get = function(name) {
  336. return goog.module.getInternal_(name);
  337. };
  338. /**
  339. * @param {string} name The module identifier.
  340. * @return {?} The module exports for an already loaded module or null.
  341. * @private
  342. */
  343. goog.module.getInternal_ = function(name) {
  344. if (!COMPILED) {
  345. if (goog.isProvided_(name)) {
  346. // goog.require only return a value with-in goog.module files.
  347. return name in goog.loadedModules_ ?
  348. goog.loadedModules_[name] :
  349. goog.getObjectByName(name);
  350. } else {
  351. return null;
  352. }
  353. }
  354. };
  355. /**
  356. * @private {?{
  357. * moduleName: (string|undefined),
  358. * declareTestMethods: boolean
  359. * }}
  360. */
  361. goog.moduleLoaderState_ = null;
  362. /**
  363. * @private
  364. * @return {boolean} Whether a goog.module is currently being initialized.
  365. */
  366. goog.isInModuleLoader_ = function() {
  367. return goog.moduleLoaderState_ != null;
  368. };
  369. /**
  370. * Indicate that a module's exports that are known test methods should
  371. * be copied to the global object. This makes the test methods visible to
  372. * test runners that inspect the global object.
  373. *
  374. * TODO(johnlenz): Make the test framework aware of goog.module so
  375. * that this isn't necessary. Alternately combine this with goog.setTestOnly
  376. * to minimize boiler plate.
  377. * @suppress {missingProvide}
  378. * @deprecated This approach does not translate to ES6 module syntax, instead
  379. * use goog.testing.testSuite to declare the test methods.
  380. */
  381. goog.module.declareTestMethods = function() {
  382. if (!goog.isInModuleLoader_()) {
  383. throw new Error('goog.module.declareTestMethods must be called from ' +
  384. 'within a goog.module');
  385. }
  386. goog.moduleLoaderState_.declareTestMethods = true;
  387. };
  388. /**
  389. * Provide the module's exports as a globally accessible object under the
  390. * module's declared name. This is intended to ease migration to goog.module
  391. * for files that have existing usages.
  392. * @suppress {missingProvide}
  393. */
  394. goog.module.declareLegacyNamespace = function() {
  395. if (!COMPILED && !goog.isInModuleLoader_()) {
  396. throw new Error('goog.module.declareLegacyNamespace must be called from ' +
  397. 'within a goog.module');
  398. }
  399. if (!COMPILED && !goog.moduleLoaderState_.moduleName) {
  400. throw Error('goog.module must be called prior to ' +
  401. 'goog.module.declareLegacyNamespace.');
  402. }
  403. goog.moduleLoaderState_.declareLegacyNamespace = true;
  404. };
  405. /**
  406. * Marks that the current file should only be used for testing, and never for
  407. * live code in production.
  408. *
  409. * In the case of unit tests, the message may optionally be an exact namespace
  410. * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra
  411. * provide (if not explicitly defined in the code).
  412. *
  413. * @param {string=} opt_message Optional message to add to the error that's
  414. * raised when used in production code.
  415. */
  416. goog.setTestOnly = function(opt_message) {
  417. if (goog.DISALLOW_TEST_ONLY_CODE) {
  418. opt_message = opt_message || '';
  419. throw Error('Importing test-only code into non-debug environment' +
  420. (opt_message ? ': ' + opt_message : '.'));
  421. }
  422. };
  423. /**
  424. * Forward declares a symbol. This is an indication to the compiler that the
  425. * symbol may be used in the source yet is not required and may not be provided
  426. * in compilation.
  427. *
  428. * The most common usage of forward declaration is code that takes a type as a
  429. * function parameter but does not need to require it. By forward declaring
  430. * instead of requiring, no hard dependency is made, and (if not required
  431. * elsewhere) the namespace may never be required and thus, not be pulled
  432. * into the JavaScript binary. If it is required elsewhere, it will be type
  433. * checked as normal.
  434. *
  435. *
  436. * @param {string} name The namespace to forward declare in the form of
  437. * "goog.package.part".
  438. */
  439. goog.forwardDeclare = function(name) {};
  440. if (!COMPILED) {
  441. /**
  442. * Check if the given name has been goog.provided. This will return false for
  443. * names that are available only as implicit namespaces.
  444. * @param {string} name name of the object to look for.
  445. * @return {boolean} Whether the name has been provided.
  446. * @private
  447. */
  448. goog.isProvided_ = function(name) {
  449. return (name in goog.loadedModules_) ||
  450. (!goog.implicitNamespaces_[name] &&
  451. goog.isDefAndNotNull(goog.getObjectByName(name)));
  452. };
  453. /**
  454. * Namespaces implicitly defined by goog.provide. For example,
  455. * goog.provide('goog.events.Event') implicitly declares that 'goog' and
  456. * 'goog.events' must be namespaces.
  457. *
  458. * @type {!Object<string, (boolean|undefined)>}
  459. * @private
  460. */
  461. goog.implicitNamespaces_ = {'goog.module': true};
  462. // NOTE: We add goog.module as an implicit namespace as goog.module is defined
  463. // here and because the existing module package has not been moved yet out of
  464. // the goog.module namespace. This satisifies both the debug loader and
  465. // ahead-of-time dependency management.
  466. }
  467. /**
  468. * Returns an object based on its fully qualified external name. The object
  469. * is not found if null or undefined. If you are using a compilation pass that
  470. * renames property names beware that using this function will not find renamed
  471. * properties.
  472. *
  473. * @param {string} name The fully qualified name.
  474. * @param {Object=} opt_obj The object within which to look; default is
  475. * |goog.global|.
  476. * @return {?} The value (object or primitive) or, if not found, null.
  477. */
  478. goog.getObjectByName = function(name, opt_obj) {
  479. var parts = name.split('.');
  480. var cur = opt_obj || goog.global;
  481. for (var part; part = parts.shift(); ) {
  482. if (goog.isDefAndNotNull(cur[part])) {
  483. cur = cur[part];
  484. } else {
  485. return null;
  486. }
  487. }
  488. return cur;
  489. };
  490. /**
  491. * Globalizes a whole namespace, such as goog or goog.lang.
  492. *
  493. * @param {!Object} obj The namespace to globalize.
  494. * @param {Object=} opt_global The object to add the properties to.
  495. * @deprecated Properties may be explicitly exported to the global scope, but
  496. * this should no longer be done in bulk.
  497. */
  498. goog.globalize = function(obj, opt_global) {
  499. var global = opt_global || goog.global;
  500. for (var x in obj) {
  501. global[x] = obj[x];
  502. }
  503. };
  504. /**
  505. * Adds a dependency from a file to the files it requires.
  506. * @param {string} relPath The path to the js file.
  507. * @param {!Array<string>} provides An array of strings with
  508. * the names of the objects this file provides.
  509. * @param {!Array<string>} requires An array of strings with
  510. * the names of the objects this file requires.
  511. * @param {boolean=} opt_isModule Whether this dependency must be loaded as
  512. * a module as declared by goog.module.
  513. */
  514. goog.addDependency = function(relPath, provides, requires, opt_isModule) {
  515. if (goog.DEPENDENCIES_ENABLED) {
  516. var provide, require;
  517. var path = relPath.replace(/\\/g, '/');
  518. var deps = goog.dependencies_;
  519. for (var i = 0; provide = provides[i]; i++) {
  520. deps.nameToPath[provide] = path;
  521. deps.pathIsModule[path] = !!opt_isModule;
  522. }
  523. for (var j = 0; require = requires[j]; j++) {
  524. if (!(path in deps.requires)) {
  525. deps.requires[path] = {};
  526. }
  527. deps.requires[path][require] = true;
  528. }
  529. }
  530. };
  531. // NOTE(nnaze): The debug DOM loader was included in base.js as an original way
  532. // to do "debug-mode" development. The dependency system can sometimes be
  533. // confusing, as can the debug DOM loader's asynchronous nature.
  534. //
  535. // With the DOM loader, a call to goog.require() is not blocking -- the script
  536. // will not load until some point after the current script. If a namespace is
  537. // needed at runtime, it needs to be defined in a previous script, or loaded via
  538. // require() with its registered dependencies.
  539. // User-defined namespaces may need their own deps file. See http://go/js_deps,
  540. // http://go/genjsdeps, or, externally, DepsWriter.
  541. // https://developers.google.com/closure/library/docs/depswriter
  542. //
  543. // Because of legacy clients, the DOM loader can't be easily removed from
  544. // base.js. Work is being done to make it disableable or replaceable for
  545. // different environments (DOM-less JavaScript interpreters like Rhino or V8,
  546. // for example). See bootstrap/ for more information.
  547. /**
  548. * @define {boolean} Whether to enable the debug loader.
  549. *
  550. * If enabled, a call to goog.require() will attempt to load the namespace by
  551. * appending a script tag to the DOM (if the namespace has been registered).
  552. *
  553. * If disabled, goog.require() will simply assert that the namespace has been
  554. * provided (and depend on the fact that some outside tool correctly ordered
  555. * the script).
  556. */
  557. goog.define('goog.ENABLE_DEBUG_LOADER', true);
  558. /**
  559. * @param {string} msg
  560. * @private
  561. */
  562. goog.logToConsole_ = function(msg) {
  563. if (goog.global.console) {
  564. goog.global.console['error'](msg);
  565. }
  566. };
  567. /**
  568. * Implements a system for the dynamic resolution of dependencies that works in
  569. * parallel with the BUILD system. Note that all calls to goog.require will be
  570. * stripped by the JSCompiler when the --closure_pass option is used.
  571. * @see goog.provide
  572. * @param {string} name Namespace to include (as was given in goog.provide()) in
  573. * the form "goog.package.part".
  574. * @return {?} If called within a goog.module file, the associated namespace or
  575. * module otherwise null.
  576. */
  577. goog.require = function(name) {
  578. // If the object already exists we do not need do do anything.
  579. if (!COMPILED) {
  580. if (goog.ENABLE_DEBUG_LOADER && goog.IS_OLD_IE_) {
  581. goog.maybeProcessDeferredDep_(name);
  582. }
  583. if (goog.isProvided_(name)) {
  584. if (goog.isInModuleLoader_()) {
  585. return goog.module.getInternal_(name);
  586. } else {
  587. return null;
  588. }
  589. }
  590. if (goog.ENABLE_DEBUG_LOADER) {
  591. var path = goog.getPathFromDeps_(name);
  592. if (path) {
  593. goog.included_[path] = true;
  594. goog.writeScripts_();
  595. return null;
  596. }
  597. }
  598. var errorMessage = 'goog.require could not find: ' + name;
  599. goog.logToConsole_(errorMessage);
  600. throw Error(errorMessage);
  601. }
  602. };
  603. /**
  604. * Path for included scripts.
  605. * @type {string}
  606. */
  607. goog.basePath = '';
  608. /**
  609. * A hook for overriding the base path.
  610. * @type {string|undefined}
  611. */
  612. goog.global.CLOSURE_BASE_PATH;
  613. /**
  614. * Whether to write out Closure's deps file. By default, the deps are written.
  615. * @type {boolean|undefined}
  616. */
  617. goog.global.CLOSURE_NO_DEPS;
  618. /**
  619. * A function to import a single script. This is meant to be overridden when
  620. * Closure is being run in non-HTML contexts, such as web workers. It's defined
  621. * in the global scope so that it can be set before base.js is loaded, which
  622. * allows deps.js to be imported properly.
  623. *
  624. * The function is passed the script source, which is a relative URI. It should
  625. * return true if the script was imported, false otherwise.
  626. * @type {(function(string): boolean)|undefined}
  627. */
  628. goog.global.CLOSURE_IMPORT_SCRIPT;
  629. /**
  630. * Null function used for default values of callbacks, etc.
  631. * @return {void} Nothing.
  632. */
  633. goog.nullFunction = function() {};
  634. /**
  635. * When defining a class Foo with an abstract method bar(), you can do:
  636. * Foo.prototype.bar = goog.abstractMethod
  637. *
  638. * Now if a subclass of Foo fails to override bar(), an error will be thrown
  639. * when bar() is invoked.
  640. *
  641. * Note: This does not take the name of the function to override as an argument
  642. * because that would make it more difficult to obfuscate our JavaScript code.
  643. *
  644. * @type {!Function}
  645. * @throws {Error} when invoked to indicate the method should be overridden.
  646. */
  647. goog.abstractMethod = function() {
  648. throw Error('unimplemented abstract method');
  649. };
  650. /**
  651. * Adds a {@code getInstance} static method that always returns the same
  652. * instance object.
  653. * @param {!Function} ctor The constructor for the class to add the static
  654. * method to.
  655. */
  656. goog.addSingletonGetter = function(ctor) {
  657. ctor.getInstance = function() {
  658. if (ctor.instance_) {
  659. return ctor.instance_;
  660. }
  661. if (goog.DEBUG) {
  662. // NOTE: JSCompiler can't optimize away Array#push.
  663. goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor;
  664. }
  665. return ctor.instance_ = new ctor;
  666. };
  667. };
  668. /**
  669. * All singleton classes that have been instantiated, for testing. Don't read
  670. * it directly, use the {@code goog.testing.singleton} module. The compiler
  671. * removes this variable if unused.
  672. * @type {!Array<!Function>}
  673. * @private
  674. */
  675. goog.instantiatedSingletons_ = [];
  676. /**
  677. * @define {boolean} Whether to load goog.modules using {@code eval} when using
  678. * the debug loader. This provides a better debugging experience as the
  679. * source is unmodified and can be edited using Chrome Workspaces or similar.
  680. * However in some environments the use of {@code eval} is banned
  681. * so we provide an alternative.
  682. */
  683. goog.define('goog.LOAD_MODULE_USING_EVAL', true);
  684. /**
  685. * @define {boolean} Whether the exports of goog.modules should be sealed when
  686. * possible.
  687. */
  688. goog.define('goog.SEAL_MODULE_EXPORTS', goog.DEBUG);
  689. /**
  690. * The registry of initialized modules:
  691. * the module identifier to module exports map.
  692. * @private @const {!Object<string, ?>}
  693. */
  694. goog.loadedModules_ = {};
  695. /**
  696. * True if goog.dependencies_ is available.
  697. * @const {boolean}
  698. */
  699. goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER;
  700. if (goog.DEPENDENCIES_ENABLED) {
  701. /**
  702. * Object used to keep track of urls that have already been added. This record
  703. * allows the prevention of circular dependencies.
  704. * @private {!Object<string, boolean>}
  705. */
  706. goog.included_ = {};
  707. /**
  708. * This object is used to keep track of dependencies and other data that is
  709. * used for loading scripts.
  710. * @private
  711. * @type {{
  712. * pathIsModule: !Object<string, boolean>,
  713. * nameToPath: !Object<string, string>,
  714. * requires: !Object<string, !Object<string, boolean>>,
  715. * visited: !Object<string, boolean>,
  716. * written: !Object<string, boolean>,
  717. * deferred: !Object<string, string>
  718. * }}
  719. */
  720. goog.dependencies_ = {
  721. pathIsModule: {}, // 1 to 1
  722. nameToPath: {}, // 1 to 1
  723. requires: {}, // 1 to many
  724. // Used when resolving dependencies to prevent us from visiting file twice.
  725. visited: {},
  726. written: {}, // Used to keep track of script files we have written.
  727. deferred: {} // Used to track deferred module evaluations in old IEs
  728. };
  729. /**
  730. * Tries to detect whether is in the context of an HTML document.
  731. * @return {boolean} True if it looks like HTML document.
  732. * @private
  733. */
  734. goog.inHtmlDocument_ = function() {
  735. var doc = goog.global.document;
  736. return typeof doc != 'undefined' &&
  737. 'write' in doc; // XULDocument misses write.
  738. };
  739. /**
  740. * Tries to detect the base path of base.js script that bootstraps Closure.
  741. * @private
  742. */
  743. goog.findBasePath_ = function() {
  744. if (goog.global.CLOSURE_BASE_PATH) {
  745. goog.basePath = goog.global.CLOSURE_BASE_PATH;
  746. return;
  747. } else if (!goog.inHtmlDocument_()) {
  748. return;
  749. }
  750. var doc = goog.global.document;
  751. var scripts = doc.getElementsByTagName('SCRIPT');
  752. // Search backwards since the current script is in almost all cases the one
  753. // that has base.js.
  754. for (var i = scripts.length - 1; i >= 0; --i) {
  755. var script = /** @type {!HTMLScriptElement} */ (scripts[i]);
  756. var src = script.src;
  757. var qmark = src.lastIndexOf('?');
  758. var l = qmark == -1 ? src.length : qmark;
  759. if (src.substr(l - 7, 7) == 'base.js') {
  760. goog.basePath = src.substr(0, l - 7);
  761. return;
  762. }
  763. }
  764. };
  765. /**
  766. * Imports a script if, and only if, that script hasn't already been imported.
  767. * (Must be called at execution time)
  768. * @param {string} src Script source.
  769. * @param {string=} opt_sourceText The optionally source text to evaluate
  770. * @private
  771. */
  772. goog.importScript_ = function(src, opt_sourceText) {
  773. var importScript = goog.global.CLOSURE_IMPORT_SCRIPT ||
  774. goog.writeScriptTag_;
  775. if (importScript(src, opt_sourceText)) {
  776. goog.dependencies_.written[src] = true;
  777. }
  778. };
  779. /** @const @private {boolean} */
  780. goog.IS_OLD_IE_ = !goog.global.atob && goog.global.document &&
  781. goog.global.document.all;
  782. /**
  783. * Given a URL initiate retrieval and execution of the module.
  784. * @param {string} src Script source URL.
  785. * @private
  786. */
  787. goog.importModule_ = function(src) {
  788. // In an attempt to keep browsers from timing out loading scripts using
  789. // synchronous XHRs, put each load in its own script block.
  790. var bootstrap = 'goog.retrieveAndExecModule_("' + src + '");';
  791. if (goog.importScript_('', bootstrap)) {
  792. goog.dependencies_.written[src] = true;
  793. }
  794. };
  795. /** @private {!Array<string>} */
  796. goog.queuedModules_ = [];
  797. /**
  798. * Return an appropriate module text. Suitable to insert into
  799. * a script tag (that is unescaped).
  800. * @param {string} srcUrl
  801. * @param {string} scriptText
  802. * @return {string}
  803. * @private
  804. */
  805. goog.wrapModule_ = function(srcUrl, scriptText) {
  806. if (!goog.LOAD_MODULE_USING_EVAL || !goog.isDef(goog.global.JSON)) {
  807. return '' +
  808. 'goog.loadModule(function(exports) {' +
  809. '"use strict";' +
  810. scriptText +
  811. '\n' + // terminate any trailing single line comment.
  812. ';return exports' +
  813. '});' +
  814. '\n//# sourceURL=' + srcUrl + '\n';
  815. } else {
  816. return '' +
  817. 'goog.loadModule(' +
  818. goog.global.JSON.stringify(
  819. scriptText + '\n//# sourceURL=' + srcUrl + '\n') +
  820. ');';
  821. }
  822. };
  823. // On IE9 and earlier, it is necessary to handle
  824. // deferred module loads. In later browsers, the
  825. // code to be evaluated is simply inserted as a script
  826. // block in the correct order. To eval deferred
  827. // code at the right time, we piggy back on goog.require to call
  828. // goog.maybeProcessDeferredDep_.
  829. //
  830. // The goog.requires are used both to bootstrap
  831. // the loading process (when no deps are available) and
  832. // declare that they should be available.
  833. //
  834. // Here we eval the sources, if all the deps are available
  835. // either already eval'd or goog.require'd. This will
  836. // be the case when all the dependencies have already
  837. // been loaded, and the dependent module is loaded.
  838. //
  839. // But this alone isn't sufficient because it is also
  840. // necessary to handle the case where there is no root
  841. // that is not deferred. For that there we register for an event
  842. // and trigger goog.loadQueuedModules_ handle any remaining deferred
  843. // evaluations.
  844. /**
  845. * Handle any remaining deferred goog.module evals.
  846. * @private
  847. */
  848. goog.loadQueuedModules_ = function() {
  849. var count = goog.queuedModules_.length;
  850. if (count > 0) {
  851. var queue = goog.queuedModules_;
  852. goog.queuedModules_ = [];
  853. for (var i = 0; i < count; i++) {
  854. var path = queue[i];
  855. goog.maybeProcessDeferredPath_(path);
  856. }
  857. }
  858. };
  859. /**
  860. * Eval the named module if its dependencies are
  861. * available.
  862. * @param {string} name The module to load.
  863. * @private
  864. */
  865. goog.maybeProcessDeferredDep_ = function(name) {
  866. if (goog.isDeferredModule_(name) &&
  867. goog.allDepsAreAvailable_(name)) {
  868. var path = goog.getPathFromDeps_(name);
  869. goog.maybeProcessDeferredPath_(goog.basePath + path);
  870. }
  871. };
  872. /**
  873. * @param {string} name The module to check.
  874. * @return {boolean} Whether the name represents a
  875. * module whose evaluation has been deferred.
  876. * @private
  877. */
  878. goog.isDeferredModule_ = function(name) {
  879. var path = goog.getPathFromDeps_(name);
  880. if (path && goog.dependencies_.pathIsModule[path]) {
  881. var abspath = goog.basePath + path;
  882. return (abspath) in goog.dependencies_.deferred;
  883. }
  884. return false;
  885. };
  886. /**
  887. * @param {string} name The module to check.
  888. * @return {boolean} Whether the name represents a
  889. * module whose declared dependencies have all been loaded
  890. * (eval'd or a deferred module load)
  891. * @private
  892. */
  893. goog.allDepsAreAvailable_ = function(name) {
  894. var path = goog.getPathFromDeps_(name);
  895. if (path && (path in goog.dependencies_.requires)) {
  896. for (var requireName in goog.dependencies_.requires[path]) {
  897. if (!goog.isProvided_(requireName) &&
  898. !goog.isDeferredModule_(requireName)) {
  899. return false;
  900. }
  901. }
  902. }
  903. return true;
  904. };
  905. /**
  906. * @param {string} abspath
  907. * @private
  908. */
  909. goog.maybeProcessDeferredPath_ = function(abspath) {
  910. if (abspath in goog.dependencies_.deferred) {
  911. var src = goog.dependencies_.deferred[abspath];
  912. delete goog.dependencies_.deferred[abspath];
  913. goog.globalEval(src);
  914. }
  915. };
  916. /**
  917. * @param {function(?):?|string} moduleDef The module definition.
  918. */
  919. goog.loadModule = function(moduleDef) {
  920. // NOTE: we allow function definitions to be either in the from
  921. // of a string to eval (which keeps the original source intact) or
  922. // in a eval forbidden environment (CSP) we allow a function definition
  923. // which in its body must call {@code goog.module}, and return the exports
  924. // of the module.
  925. var previousState = goog.moduleLoaderState_;
  926. try {
  927. goog.moduleLoaderState_ = {
  928. moduleName: undefined, declareTestMethods: false};
  929. var exports;
  930. if (goog.isFunction(moduleDef)) {
  931. exports = moduleDef.call(goog.global, {});
  932. } else if (goog.isString(moduleDef)) {
  933. exports = goog.loadModuleFromSource_.call(goog.global, moduleDef);
  934. } else {
  935. throw Error('Invalid module definition');
  936. }
  937. var moduleName = goog.moduleLoaderState_.moduleName;
  938. if (!goog.isString(moduleName) || !moduleName) {
  939. throw Error('Invalid module name \"' + moduleName + '\"');
  940. }
  941. // Don't seal legacy namespaces as they may be uses as a parent of
  942. // another namespace
  943. if (goog.moduleLoaderState_.declareLegacyNamespace) {
  944. goog.constructNamespace_(moduleName, exports);
  945. } else if (goog.SEAL_MODULE_EXPORTS && Object.seal) {
  946. Object.seal(exports);
  947. }
  948. goog.loadedModules_[moduleName] = exports;
  949. if (goog.moduleLoaderState_.declareTestMethods) {
  950. for (var entry in exports) {
  951. if (entry.indexOf('test', 0) === 0 ||
  952. entry == 'tearDown' ||
  953. entry == 'setUp' ||
  954. entry == 'setUpPage' ||
  955. entry == 'tearDownPage') {
  956. goog.global[entry] = exports[entry];
  957. }
  958. }
  959. }
  960. } finally {
  961. goog.moduleLoaderState_ = previousState;
  962. }
  963. };
  964. /**
  965. * @param {string} source
  966. * @return {!Object}
  967. * @private
  968. */
  969. goog.loadModuleFromSource_ = function(source) {
  970. // NOTE: we avoid declaring parameters or local variables here to avoid
  971. // masking globals or leaking values into the module definition.
  972. 'use strict';
  973. var exports = {};
  974. eval(arguments[0]);
  975. return exports;
  976. };
  977. /**
  978. * Writes a new script pointing to {@code src} directly into the DOM.
  979. *
  980. * NOTE: This method is not CSP-compliant. @see goog.appendScriptSrcNode_ for
  981. * the fallback mechanism.
  982. *
  983. * @param {string} src The script URL.
  984. * @private
  985. */
  986. goog.writeScriptSrcNode_ = function(src) {
  987. goog.global.document.write(
  988. '<script type="text/javascript" src="' + src + '"></' + 'script>');
  989. };
  990. /**
  991. * Appends a new script node to the DOM using a CSP-compliant mechanism. This
  992. * method exists as a fallback for document.write (which is not allowed in a
  993. * strict CSP context, e.g., Chrome apps).
  994. *
  995. * NOTE: This method is not analogous to using document.write to insert a
  996. * <script> tag; specifically, the user agent will execute a script added by
  997. * document.write immediately after the current script block finishes
  998. * executing, whereas the DOM-appended script node will not be executed until
  999. * the entire document is parsed and executed. That is to say, this script is
  1000. * added to the end of the script execution queue.
  1001. *
  1002. * The page must not attempt to call goog.required entities until after the
  1003. * document has loaded, e.g., in or after the window.onload callback.
  1004. *
  1005. * @param {string} src The script URL.
  1006. * @private
  1007. */
  1008. goog.appendScriptSrcNode_ = function(src) {
  1009. var doc = goog.global.document;
  1010. var scriptEl = doc.createElement('script');
  1011. scriptEl.type = 'text/javascript';
  1012. scriptEl.src = src;
  1013. scriptEl.defer = false;
  1014. scriptEl.async = false;
  1015. doc.head.appendChild(scriptEl);
  1016. };
  1017. /**
  1018. * The default implementation of the import function. Writes a script tag to
  1019. * import the script.
  1020. *
  1021. * @param {string} src The script url.
  1022. * @param {string=} opt_sourceText The optionally source text to evaluate
  1023. * @return {boolean} True if the script was imported, false otherwise.
  1024. * @private
  1025. */
  1026. goog.writeScriptTag_ = function(src, opt_sourceText) {
  1027. if (goog.inHtmlDocument_()) {
  1028. var doc = goog.global.document;
  1029. // If the user tries to require a new symbol after document load,
  1030. // something has gone terribly wrong. Doing a document.write would
  1031. // wipe out the page. This does not apply to the CSP-compliant method
  1032. // of writing script tags.
  1033. if (!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING &&
  1034. doc.readyState == 'complete') {
  1035. // Certain test frameworks load base.js multiple times, which tries
  1036. // to write deps.js each time. If that happens, just fail silently.
  1037. // These frameworks wipe the page between each load of base.js, so this
  1038. // is OK.
  1039. var isDeps = /\bdeps.js$/.test(src);
  1040. if (isDeps) {
  1041. return false;
  1042. } else {
  1043. throw Error('Cannot write "' + src + '" after document load');
  1044. }
  1045. }
  1046. var isOldIE = goog.IS_OLD_IE_;
  1047. if (opt_sourceText === undefined) {
  1048. if (!isOldIE) {
  1049. if (goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING) {
  1050. goog.appendScriptSrcNode_(src);
  1051. } else {
  1052. goog.writeScriptSrcNode_(src);
  1053. }
  1054. } else {
  1055. var state = " onreadystatechange='goog.onScriptLoad_(this, " +
  1056. ++goog.lastNonModuleScriptIndex_ + ")' ";
  1057. doc.write(
  1058. '<script type="text/javascript" src="' +
  1059. src + '"' + state + '></' + 'script>');
  1060. }
  1061. } else {
  1062. doc.write(
  1063. '<script type="text/javascript">' +
  1064. opt_sourceText +
  1065. '</' + 'script>');
  1066. }
  1067. return true;
  1068. } else {
  1069. return false;
  1070. }
  1071. };
  1072. /** @private {number} */
  1073. goog.lastNonModuleScriptIndex_ = 0;
  1074. /**
  1075. * A readystatechange handler for legacy IE
  1076. * @param {!HTMLScriptElement} script
  1077. * @param {number} scriptIndex
  1078. * @return {boolean}
  1079. * @private
  1080. */
  1081. goog.onScriptLoad_ = function(script, scriptIndex) {
  1082. // for now load the modules when we reach the last script,
  1083. // later allow more inter-mingling.
  1084. if (script.readyState == 'complete' &&
  1085. goog.lastNonModuleScriptIndex_ == scriptIndex) {
  1086. goog.loadQueuedModules_();
  1087. }
  1088. return true;
  1089. };
  1090. /**
  1091. * Resolves dependencies based on the dependencies added using addDependency
  1092. * and calls importScript_ in the correct order.
  1093. * @private
  1094. */
  1095. goog.writeScripts_ = function() {
  1096. /** @type {!Array<string>} The scripts we need to write this time. */
  1097. var scripts = [];
  1098. var seenScript = {};
  1099. var deps = goog.dependencies_;
  1100. /** @param {string} path */
  1101. function visitNode(path) {
  1102. if (path in deps.written) {
  1103. return;
  1104. }
  1105. // We have already visited this one. We can get here if we have cyclic
  1106. // dependencies.
  1107. if (path in deps.visited) {
  1108. if (!(path in seenScript)) {
  1109. seenScript[path] = true;
  1110. scripts.push(path);
  1111. }
  1112. return;
  1113. }
  1114. deps.visited[path] = true;
  1115. if (path in deps.requires) {
  1116. for (var requireName in deps.requires[path]) {
  1117. // If the required name is defined, we assume that it was already
  1118. // bootstrapped by other means.
  1119. if (!goog.isProvided_(requireName)) {
  1120. if (requireName in deps.nameToPath) {
  1121. visitNode(deps.nameToPath[requireName]);
  1122. } else {
  1123. throw Error('Undefined nameToPath for ' + requireName);
  1124. }
  1125. }
  1126. }
  1127. }
  1128. if (!(path in seenScript)) {
  1129. seenScript[path] = true;
  1130. scripts.push(path);
  1131. }
  1132. }
  1133. for (var path in goog.included_) {
  1134. if (!deps.written[path]) {
  1135. visitNode(path);
  1136. }
  1137. }
  1138. // record that we are going to load all these scripts.
  1139. for (var i = 0; i < scripts.length; i++) {
  1140. var path = scripts[i];
  1141. goog.dependencies_.written[path] = true;
  1142. }
  1143. // If a module is loaded synchronously then we need to
  1144. // clear the current inModuleLoader value, and restore it when we are
  1145. // done loading the current "requires".
  1146. var moduleState = goog.moduleLoaderState_;
  1147. goog.moduleLoaderState_ = null;
  1148. var loadingModule = false;
  1149. for (var i = 0; i < scripts.length; i++) {
  1150. var path = scripts[i];
  1151. if (path) {
  1152. if (!deps.pathIsModule[path]) {
  1153. goog.importScript_(goog.basePath + path);
  1154. } else {
  1155. loadingModule = true;
  1156. goog.importModule_(goog.basePath + path);
  1157. }
  1158. } else {
  1159. goog.moduleLoaderState_ = moduleState;
  1160. throw Error('Undefined script input');
  1161. }
  1162. }
  1163. // restore the current "module loading state"
  1164. goog.moduleLoaderState_ = moduleState;
  1165. };
  1166. /**
  1167. * Looks at the dependency rules and tries to determine the script file that
  1168. * fulfills a particular rule.
  1169. * @param {string} rule In the form goog.namespace.Class or project.script.
  1170. * @return {?string} Url corresponding to the rule, or null.
  1171. * @private
  1172. */
  1173. goog.getPathFromDeps_ = function(rule) {
  1174. if (rule in goog.dependencies_.nameToPath) {
  1175. return goog.dependencies_.nameToPath[rule];
  1176. } else {
  1177. return null;
  1178. }
  1179. };
  1180. goog.findBasePath_();
  1181. // Allow projects to manage the deps files themselves.
  1182. if (!goog.global.CLOSURE_NO_DEPS) {
  1183. goog.importScript_(goog.basePath + 'deps.js');
  1184. }
  1185. }
  1186. /**
  1187. * Normalize a file path by removing redundant ".." and extraneous "." file
  1188. * path components.
  1189. * @param {string} path
  1190. * @return {string}
  1191. * @private
  1192. */
  1193. goog.normalizePath_ = function(path) {
  1194. var components = path.split('/');
  1195. var i = 0;
  1196. while (i < components.length) {
  1197. if (components[i] == '.') {
  1198. components.splice(i, 1);
  1199. } else if (i && components[i] == '..' &&
  1200. components[i - 1] && components[i - 1] != '..') {
  1201. components.splice(--i, 2);
  1202. } else {
  1203. i++;
  1204. }
  1205. }
  1206. return components.join('/');
  1207. };
  1208. /**
  1209. * Loads file by synchronous XHR. Should not be used in production environments.
  1210. * @param {string} src Source URL.
  1211. * @return {string} File contents.
  1212. * @private
  1213. */
  1214. goog.loadFileSync_ = function(src) {
  1215. if (goog.global.CLOSURE_LOAD_FILE_SYNC) {
  1216. return goog.global.CLOSURE_LOAD_FILE_SYNC(src);
  1217. } else {
  1218. var xhr = new goog.global['XMLHttpRequest']();
  1219. xhr.open('get', src, false);
  1220. xhr.send();
  1221. return xhr.responseText;
  1222. }
  1223. };
  1224. /**
  1225. * Retrieve and execute a module.
  1226. * @param {string} src Script source URL.
  1227. * @private
  1228. */
  1229. goog.retrieveAndExecModule_ = function(src) {
  1230. if (!COMPILED) {
  1231. // The full but non-canonicalized URL for later use.
  1232. var originalPath = src;
  1233. // Canonicalize the path, removing any /./ or /../ since Chrome's debugging
  1234. // console doesn't auto-canonicalize XHR loads as it does <script> srcs.
  1235. src = goog.normalizePath_(src);
  1236. var importScript = goog.global.CLOSURE_IMPORT_SCRIPT ||
  1237. goog.writeScriptTag_;
  1238. var scriptText = goog.loadFileSync_(src);
  1239. if (scriptText != null) {
  1240. var execModuleScript = goog.wrapModule_(src, scriptText);
  1241. var isOldIE = goog.IS_OLD_IE_;
  1242. if (isOldIE) {
  1243. goog.dependencies_.deferred[originalPath] = execModuleScript;
  1244. goog.queuedModules_.push(originalPath);
  1245. } else {
  1246. importScript(src, execModuleScript);
  1247. }
  1248. } else {
  1249. throw new Error('load of ' + src + 'failed');
  1250. }
  1251. }
  1252. };
  1253. //==============================================================================
  1254. // Language Enhancements
  1255. //==============================================================================
  1256. /**
  1257. * This is a "fixed" version of the typeof operator. It differs from the typeof
  1258. * operator in such a way that null returns 'null' and arrays return 'array'.
  1259. * @param {*} value The value to get the type of.
  1260. * @return {string} The name of the type.
  1261. */
  1262. goog.typeOf = function(value) {
  1263. var s = typeof value;
  1264. if (s == 'object') {
  1265. if (value) {
  1266. // Check these first, so we can avoid calling Object.prototype.toString if
  1267. // possible.
  1268. //
  1269. // IE improperly marshals tyepof across execution contexts, but a
  1270. // cross-context object will still return false for "instanceof Object".
  1271. if (value instanceof Array) {
  1272. return 'array';
  1273. } else if (value instanceof Object) {
  1274. return s;
  1275. }
  1276. // HACK: In order to use an Object prototype method on the arbitrary
  1277. // value, the compiler requires the value be cast to type Object,
  1278. // even though the ECMA spec explicitly allows it.
  1279. var className = Object.prototype.toString.call(
  1280. /** @type {Object} */ (value));
  1281. // In Firefox 3.6, attempting to access iframe window objects' length
  1282. // property throws an NS_ERROR_FAILURE, so we need to special-case it
  1283. // here.
  1284. if (className == '[object Window]') {
  1285. return 'object';
  1286. }
  1287. // We cannot always use constructor == Array or instanceof Array because
  1288. // different frames have different Array objects. In IE6, if the iframe
  1289. // where the array was created is destroyed, the array loses its
  1290. // prototype. Then dereferencing val.splice here throws an exception, so
  1291. // we can't use goog.isFunction. Calling typeof directly returns 'unknown'
  1292. // so that will work. In this case, this function will return false and
  1293. // most array functions will still work because the array is still
  1294. // array-like (supports length and []) even though it has lost its
  1295. // prototype.
  1296. // Mark Miller noticed that Object.prototype.toString
  1297. // allows access to the unforgeable [[Class]] property.
  1298. // 15.2.4.2 Object.prototype.toString ( )
  1299. // When the toString method is called, the following steps are taken:
  1300. // 1. Get the [[Class]] property of this object.
  1301. // 2. Compute a string value by concatenating the three strings
  1302. // "[object ", Result(1), and "]".
  1303. // 3. Return Result(2).
  1304. // and this behavior survives the destruction of the execution context.
  1305. if ((className == '[object Array]' ||
  1306. // In IE all non value types are wrapped as objects across window
  1307. // boundaries (not iframe though) so we have to do object detection
  1308. // for this edge case.
  1309. typeof value.length == 'number' &&
  1310. typeof value.splice != 'undefined' &&
  1311. typeof value.propertyIsEnumerable != 'undefined' &&
  1312. !value.propertyIsEnumerable('splice')
  1313. )) {
  1314. return 'array';
  1315. }
  1316. // HACK: There is still an array case that fails.
  1317. // function ArrayImpostor() {}
  1318. // ArrayImpostor.prototype = [];
  1319. // var impostor = new ArrayImpostor;
  1320. // this can be fixed by getting rid of the fast path
  1321. // (value instanceof Array) and solely relying on
  1322. // (value && Object.prototype.toString.vall(value) === '[object Array]')
  1323. // but that would require many more function calls and is not warranted
  1324. // unless closure code is receiving objects from untrusted sources.
  1325. // IE in cross-window calls does not correctly marshal the function type
  1326. // (it appears just as an object) so we cannot use just typeof val ==
  1327. // 'function'. However, if the object has a call property, it is a
  1328. // function.
  1329. if ((className == '[object Function]' ||
  1330. typeof value.call != 'undefined' &&
  1331. typeof value.propertyIsEnumerable != 'undefined' &&
  1332. !value.propertyIsEnumerable('call'))) {
  1333. return 'function';
  1334. }
  1335. } else {
  1336. return 'null';
  1337. }
  1338. } else if (s == 'function' && typeof value.call == 'undefined') {
  1339. // In Safari typeof nodeList returns 'function', and on Firefox typeof
  1340. // behaves similarly for HTML{Applet,Embed,Object}, Elements and RegExps. We
  1341. // would like to return object for those and we can detect an invalid
  1342. // function by making sure that the function object has a call method.
  1343. return 'object';
  1344. }
  1345. return s;
  1346. };
  1347. /**
  1348. * Returns true if the specified value is null.
  1349. * @param {?} val Variable to test.
  1350. * @return {boolean} Whether variable is null.
  1351. */
  1352. goog.isNull = function(val) {
  1353. return val === null;
  1354. };
  1355. /**
  1356. * Returns true if the specified value is defined and not null.
  1357. * @param {?} val Variable to test.
  1358. * @return {boolean} Whether variable is defined and not null.
  1359. */
  1360. goog.isDefAndNotNull = function(val) {
  1361. // Note that undefined == null.
  1362. return val != null;
  1363. };
  1364. /**
  1365. * Returns true if the specified value is an array.
  1366. * @param {?} val Variable to test.
  1367. * @return {boolean} Whether variable is an array.
  1368. */
  1369. goog.isArray = function(val) {
  1370. return goog.typeOf(val) == 'array';
  1371. };
  1372. /**
  1373. * Returns true if the object looks like an array. To qualify as array like
  1374. * the value needs to be either a NodeList or an object with a Number length
  1375. * property. As a special case, a function value is not array like, because its
  1376. * length property is fixed to correspond to the number of expected arguments.
  1377. * @param {?} val Variable to test.
  1378. * @return {boolean} Whether variable is an array.
  1379. */
  1380. goog.isArrayLike = function(val) {
  1381. var type = goog.typeOf(val);
  1382. // We do not use goog.isObject here in order to exclude function values.
  1383. return type == 'array' || type == 'object' && typeof val.length == 'number';
  1384. };
  1385. /**
  1386. * Returns true if the object looks like a Date. To qualify as Date-like the
  1387. * value needs to be an object and have a getFullYear() function.
  1388. * @param {?} val Variable to test.
  1389. * @return {boolean} Whether variable is a like a Date.
  1390. */
  1391. goog.isDateLike = function(val) {
  1392. return goog.isObject(val) && typeof val.getFullYear == 'function';
  1393. };
  1394. /**
  1395. * Returns true if the specified value is a string.
  1396. * @param {?} val Variable to test.
  1397. * @return {boolean} Whether variable is a string.
  1398. */
  1399. goog.isString = function(val) {
  1400. return typeof val == 'string';
  1401. };
  1402. /**
  1403. * Returns true if the specified value is a boolean.
  1404. * @param {?} val Variable to test.
  1405. * @return {boolean} Whether variable is boolean.
  1406. */
  1407. goog.isBoolean = function(val) {
  1408. return typeof val == 'boolean';
  1409. };
  1410. /**
  1411. * Returns true if the specified value is a number.
  1412. * @param {?} val Variable to test.
  1413. * @return {boolean} Whether variable is a number.
  1414. */
  1415. goog.isNumber = function(val) {
  1416. return typeof val == 'number';
  1417. };
  1418. /**
  1419. * Returns true if the specified value is a function.
  1420. * @param {?} val Variable to test.
  1421. * @return {boolean} Whether variable is a function.
  1422. */
  1423. goog.isFunction = function(val) {
  1424. return goog.typeOf(val) == 'function';
  1425. };
  1426. /**
  1427. * Returns true if the specified value is an object. This includes arrays and
  1428. * functions.
  1429. * @param {?} val Variable to test.
  1430. * @return {boolean} Whether variable is an object.
  1431. */
  1432. goog.isObject = function(val) {
  1433. var type = typeof val;
  1434. return type == 'object' && val != null || type == 'function';
  1435. // return Object(val) === val also works, but is slower, especially if val is
  1436. // not an object.
  1437. };
  1438. /**
  1439. * Gets a unique ID for an object. This mutates the object so that further calls
  1440. * with the same object as a parameter returns the same value. The unique ID is
  1441. * guaranteed to be unique across the current session amongst objects that are
  1442. * passed into {@code getUid}. There is no guarantee that the ID is unique or
  1443. * consistent across sessions. It is unsafe to generate unique ID for function
  1444. * prototypes.
  1445. *
  1446. * @param {Object} obj The object to get the unique ID for.
  1447. * @return {number} The unique ID for the object.
  1448. */
  1449. goog.getUid = function(obj) {
  1450. // TODO(arv): Make the type stricter, do not accept null.
  1451. // In Opera window.hasOwnProperty exists but always returns false so we avoid
  1452. // using it. As a consequence the unique ID generated for BaseClass.prototype
  1453. // and SubClass.prototype will be the same.
  1454. return obj[goog.UID_PROPERTY_] ||
  1455. (obj[goog.UID_PROPERTY_] = ++goog.uidCounter_);
  1456. };
  1457. /**
  1458. * Whether the given object is already assigned a unique ID.
  1459. *
  1460. * This does not modify the object.
  1461. *
  1462. * @param {!Object} obj The object to check.
  1463. * @return {boolean} Whether there is an assigned unique id for the object.
  1464. */
  1465. goog.hasUid = function(obj) {
  1466. return !!obj[goog.UID_PROPERTY_];
  1467. };
  1468. /**
  1469. * Removes the unique ID from an object. This is useful if the object was
  1470. * previously mutated using {@code goog.getUid} in which case the mutation is
  1471. * undone.
  1472. * @param {Object} obj The object to remove the unique ID field from.
  1473. */
  1474. goog.removeUid = function(obj) {
  1475. // TODO(arv): Make the type stricter, do not accept null.
  1476. // In IE, DOM nodes are not instances of Object and throw an exception if we
  1477. // try to delete. Instead we try to use removeAttribute.
  1478. if ('removeAttribute' in obj) {
  1479. obj.removeAttribute(goog.UID_PROPERTY_);
  1480. }
  1481. /** @preserveTry */
  1482. try {
  1483. delete obj[goog.UID_PROPERTY_];
  1484. } catch (ex) {
  1485. }
  1486. };
  1487. /**
  1488. * Name for unique ID property. Initialized in a way to help avoid collisions
  1489. * with other closure JavaScript on the same page.
  1490. * @type {string}
  1491. * @private
  1492. */
  1493. goog.UID_PROPERTY_ = 'closure_uid_' + ((Math.random() * 1e9) >>> 0);
  1494. /**
  1495. * Counter for UID.
  1496. * @type {number}
  1497. * @private
  1498. */
  1499. goog.uidCounter_ = 0;
  1500. /**
  1501. * Adds a hash code field to an object. The hash code is unique for the
  1502. * given object.
  1503. * @param {Object} obj The object to get the hash code for.
  1504. * @return {number} The hash code for the object.
  1505. * @deprecated Use goog.getUid instead.
  1506. */
  1507. goog.getHashCode = goog.getUid;
  1508. /**
  1509. * Removes the hash code field from an object.
  1510. * @param {Object} obj The object to remove the field from.
  1511. * @deprecated Use goog.removeUid instead.
  1512. */
  1513. goog.removeHashCode = goog.removeUid;
  1514. /**
  1515. * Clones a value. The input may be an Object, Array, or basic type. Objects and
  1516. * arrays will be cloned recursively.
  1517. *
  1518. * WARNINGS:
  1519. * <code>goog.cloneObject</code> does not detect reference loops. Objects that
  1520. * refer to themselves will cause infinite recursion.
  1521. *
  1522. * <code>goog.cloneObject</code> is unaware of unique identifiers, and copies
  1523. * UIDs created by <code>getUid</code> into cloned results.
  1524. *
  1525. * @param {*} obj The value to clone.
  1526. * @return {*} A clone of the input value.
  1527. * @deprecated goog.cloneObject is unsafe. Prefer the goog.object methods.
  1528. */
  1529. goog.cloneObject = function(obj) {
  1530. var type = goog.typeOf(obj);
  1531. if (type == 'object' || type == 'array') {
  1532. if (obj.clone) {
  1533. return obj.clone();
  1534. }
  1535. var clone = type == 'array' ? [] : {};
  1536. for (var key in obj) {
  1537. clone[key] = goog.cloneObject(obj[key]);
  1538. }
  1539. return clone;
  1540. }
  1541. return obj;
  1542. };
  1543. /**
  1544. * A native implementation of goog.bind.
  1545. * @param {Function} fn A function to partially apply.
  1546. * @param {Object|undefined} selfObj Specifies the object which this should
  1547. * point to when the function is run.
  1548. * @param {...*} var_args Additional arguments that are partially applied to the
  1549. * function.
  1550. * @return {!Function} A partially-applied form of the function bind() was
  1551. * invoked as a method of.
  1552. * @private
  1553. * @suppress {deprecated} The compiler thinks that Function.prototype.bind is
  1554. * deprecated because some people have declared a pure-JS version.
  1555. * Only the pure-JS version is truly deprecated.
  1556. */
  1557. goog.bindNative_ = function(fn, selfObj, var_args) {
  1558. return /** @type {!Function} */ (fn.call.apply(fn.bind, arguments));
  1559. };
  1560. /**
  1561. * A pure-JS implementation of goog.bind.
  1562. * @param {Function} fn A function to partially apply.
  1563. * @param {Object|undefined} selfObj Specifies the object which this should
  1564. * point to when the function is run.
  1565. * @param {...*} var_args Additional arguments that are partially applied to the
  1566. * function.
  1567. * @return {!Function} A partially-applied form of the function bind() was
  1568. * invoked as a method of.
  1569. * @private
  1570. */
  1571. goog.bindJs_ = function(fn, selfObj, var_args) {
  1572. if (!fn) {
  1573. throw new Error();
  1574. }
  1575. if (arguments.length > 2) {
  1576. var boundArgs = Array.prototype.slice.call(arguments, 2);
  1577. return function() {
  1578. // Prepend the bound arguments to the current arguments.
  1579. var newArgs = Array.prototype.slice.call(arguments);
  1580. Array.prototype.unshift.apply(newArgs, boundArgs);
  1581. return fn.apply(selfObj, newArgs);
  1582. };
  1583. } else {
  1584. return function() {
  1585. return fn.apply(selfObj, arguments);
  1586. };
  1587. }
  1588. };
  1589. /**
  1590. * Partially applies this function to a particular 'this object' and zero or
  1591. * more arguments. The result is a new function with some arguments of the first
  1592. * function pre-filled and the value of this 'pre-specified'.
  1593. *
  1594. * Remaining arguments specified at call-time are appended to the pre-specified
  1595. * ones.
  1596. *
  1597. * Also see: {@link #partial}.
  1598. *
  1599. * Usage:
  1600. * <pre>var barMethBound = bind(myFunction, myObj, 'arg1', 'arg2');
  1601. * barMethBound('arg3', 'arg4');</pre>
  1602. *
  1603. * @param {?function(this:T, ...)} fn A function to partially apply.
  1604. * @param {T} selfObj Specifies the object which this should point to when the
  1605. * function is run.
  1606. * @param {...*} var_args Additional arguments that are partially applied to the
  1607. * function.
  1608. * @return {!Function} A partially-applied form of the function bind() was
  1609. * invoked as a method of.
  1610. * @template T
  1611. * @suppress {deprecated} See above.
  1612. */
  1613. goog.bind = function(fn, selfObj, var_args) {
  1614. // TODO(nicksantos): narrow the type signature.
  1615. if (Function.prototype.bind &&
  1616. // NOTE(nicksantos): Somebody pulled base.js into the default Chrome
  1617. // extension environment. This means that for Chrome extensions, they get
  1618. // the implementation of Function.prototype.bind that calls goog.bind
  1619. // instead of the native one. Even worse, we don't want to introduce a
  1620. // circular dependency between goog.bind and Function.prototype.bind, so
  1621. // we have to hack this to make sure it works correctly.
  1622. Function.prototype.bind.toString().indexOf('native code') != -1) {
  1623. goog.bind = goog.bindNative_;
  1624. } else {
  1625. goog.bind = goog.bindJs_;
  1626. }
  1627. return goog.bind.apply(null, arguments);
  1628. };
  1629. /**
  1630. * Like bind(), except that a 'this object' is not required. Useful when the
  1631. * target function is already bound.
  1632. *
  1633. * Usage:
  1634. * var g = partial(f, arg1, arg2);
  1635. * g(arg3, arg4);
  1636. *
  1637. * @param {Function} fn A function to partially apply.
  1638. * @param {...*} var_args Additional arguments that are partially applied to fn.
  1639. * @return {!Function} A partially-applied form of the function bind() was
  1640. * invoked as a method of.
  1641. */
  1642. goog.partial = function(fn, var_args) {
  1643. var args = Array.prototype.slice.call(arguments, 1);
  1644. return function() {
  1645. // Clone the array (with slice()) and append additional arguments
  1646. // to the existing arguments.
  1647. var newArgs = args.slice();
  1648. newArgs.push.apply(newArgs, arguments);
  1649. return fn.apply(this, newArgs);
  1650. };
  1651. };
  1652. /**
  1653. * Copies all the members of a source object to a target object. This method
  1654. * does not work on all browsers for all objects that contain keys such as
  1655. * toString or hasOwnProperty. Use goog.object.extend for this purpose.
  1656. * @param {Object} target Target.
  1657. * @param {Object} source Source.
  1658. */
  1659. goog.mixin = function(target, source) {
  1660. for (var x in source) {
  1661. target[x] = source[x];
  1662. }
  1663. // For IE7 or lower, the for-in-loop does not contain any properties that are
  1664. // not enumerable on the prototype object (for example, isPrototypeOf from
  1665. // Object.prototype) but also it will not include 'replace' on objects that
  1666. // extend String and change 'replace' (not that it is common for anyone to
  1667. // extend anything except Object).
  1668. };
  1669. /**
  1670. * @return {number} An integer value representing the number of milliseconds
  1671. * between midnight, January 1, 1970 and the current time.
  1672. */
  1673. goog.now = (goog.TRUSTED_SITE && Date.now) || (function() {
  1674. // Unary plus operator converts its operand to a number which in the case of
  1675. // a date is done by calling getTime().
  1676. return +new Date();
  1677. });
  1678. /**
  1679. * Evals JavaScript in the global scope. In IE this uses execScript, other
  1680. * browsers use goog.global.eval. If goog.global.eval does not evaluate in the
  1681. * global scope (for example, in Safari), appends a script tag instead.
  1682. * Throws an exception if neither execScript or eval is defined.
  1683. * @param {string} script JavaScript string.
  1684. */
  1685. goog.globalEval = function(script) {
  1686. if (goog.global.execScript) {
  1687. goog.global.execScript(script, 'JavaScript');
  1688. } else if (goog.global.eval) {
  1689. // Test to see if eval works
  1690. if (goog.evalWorksForGlobals_ == null) {
  1691. goog.global.eval('var _et_ = 1;');
  1692. if (typeof goog.global['_et_'] != 'undefined') {
  1693. delete goog.global['_et_'];
  1694. goog.evalWorksForGlobals_ = true;
  1695. } else {
  1696. goog.evalWorksForGlobals_ = false;
  1697. }
  1698. }
  1699. if (goog.evalWorksForGlobals_) {
  1700. goog.global.eval(script);
  1701. } else {
  1702. var doc = goog.global.document;
  1703. var scriptElt = doc.createElement('SCRIPT');
  1704. scriptElt.type = 'text/javascript';
  1705. scriptElt.defer = false;
  1706. // Note(user): can't use .innerHTML since "t('<test>')" will fail and
  1707. // .text doesn't work in Safari 2. Therefore we append a text node.
  1708. scriptElt.appendChild(doc.createTextNode(script));
  1709. doc.body.appendChild(scriptElt);
  1710. doc.body.removeChild(scriptElt);
  1711. }
  1712. } else {
  1713. throw Error('goog.globalEval not available');
  1714. }
  1715. };
  1716. /**
  1717. * Indicates whether or not we can call 'eval' directly to eval code in the
  1718. * global scope. Set to a Boolean by the first call to goog.globalEval (which
  1719. * empirically tests whether eval works for globals). @see goog.globalEval
  1720. * @type {?boolean}
  1721. * @private
  1722. */
  1723. goog.evalWorksForGlobals_ = null;
  1724. /**
  1725. * Optional map of CSS class names to obfuscated names used with
  1726. * goog.getCssName().
  1727. * @private {!Object<string, string>|undefined}
  1728. * @see goog.setCssNameMapping
  1729. */
  1730. goog.cssNameMapping_;
  1731. /**
  1732. * Optional obfuscation style for CSS class names. Should be set to either
  1733. * 'BY_WHOLE' or 'BY_PART' if defined.
  1734. * @type {string|undefined}
  1735. * @private
  1736. * @see goog.setCssNameMapping
  1737. */
  1738. goog.cssNameMappingStyle_;
  1739. /**
  1740. * Handles strings that are intended to be used as CSS class names.
  1741. *
  1742. * This function works in tandem with @see goog.setCssNameMapping.
  1743. *
  1744. * Without any mapping set, the arguments are simple joined with a hyphen and
  1745. * passed through unaltered.
  1746. *
  1747. * When there is a mapping, there are two possible styles in which these
  1748. * mappings are used. In the BY_PART style, each part (i.e. in between hyphens)
  1749. * of the passed in css name is rewritten according to the map. In the BY_WHOLE
  1750. * style, the full css name is looked up in the map directly. If a rewrite is
  1751. * not specified by the map, the compiler will output a warning.
  1752. *
  1753. * When the mapping is passed to the compiler, it will replace calls to
  1754. * goog.getCssName with the strings from the mapping, e.g.
  1755. * var x = goog.getCssName('foo');
  1756. * var y = goog.getCssName(this.baseClass, 'active');
  1757. * becomes:
  1758. * var x= 'foo';
  1759. * var y = this.baseClass + '-active';
  1760. *
  1761. * If one argument is passed it will be processed, if two are passed only the
  1762. * modifier will be processed, as it is assumed the first argument was generated
  1763. * as a result of calling goog.getCssName.
  1764. *
  1765. * @param {string} className The class name.
  1766. * @param {string=} opt_modifier A modifier to be appended to the class name.
  1767. * @return {string} The class name or the concatenation of the class name and
  1768. * the modifier.
  1769. */
  1770. goog.getCssName = function(className, opt_modifier) {
  1771. var getMapping = function(cssName) {
  1772. return goog.cssNameMapping_[cssName] || cssName;
  1773. };
  1774. var renameByParts = function(cssName) {
  1775. // Remap all the parts individually.
  1776. var parts = cssName.split('-');
  1777. var mapped = [];
  1778. for (var i = 0; i < parts.length; i++) {
  1779. mapped.push(getMapping(parts[i]));
  1780. }
  1781. return mapped.join('-');
  1782. };
  1783. var rename;
  1784. if (goog.cssNameMapping_) {
  1785. rename = goog.cssNameMappingStyle_ == 'BY_WHOLE' ?
  1786. getMapping : renameByParts;
  1787. } else {
  1788. rename = function(a) {
  1789. return a;
  1790. };
  1791. }
  1792. if (opt_modifier) {
  1793. return className + '-' + rename(opt_modifier);
  1794. } else {
  1795. return rename(className);
  1796. }
  1797. };
  1798. /**
  1799. * Sets the map to check when returning a value from goog.getCssName(). Example:
  1800. * <pre>
  1801. * goog.setCssNameMapping({
  1802. * "goog": "a",
  1803. * "disabled": "b",
  1804. * });
  1805. *
  1806. * var x = goog.getCssName('goog');
  1807. * // The following evaluates to: "a a-b".
  1808. * goog.getCssName('goog') + ' ' + goog.getCssName(x, 'disabled')
  1809. * </pre>
  1810. * When declared as a map of string literals to string literals, the JSCompiler
  1811. * will replace all calls to goog.getCssName() using the supplied map if the
  1812. * --closure_pass flag is set.
  1813. *
  1814. * @param {!Object} mapping A map of strings to strings where keys are possible
  1815. * arguments to goog.getCssName() and values are the corresponding values
  1816. * that should be returned.
  1817. * @param {string=} opt_style The style of css name mapping. There are two valid
  1818. * options: 'BY_PART', and 'BY_WHOLE'.
  1819. * @see goog.getCssName for a description.
  1820. */
  1821. goog.setCssNameMapping = function(mapping, opt_style) {
  1822. goog.cssNameMapping_ = mapping;
  1823. goog.cssNameMappingStyle_ = opt_style;
  1824. };
  1825. /**
  1826. * To use CSS renaming in compiled mode, one of the input files should have a
  1827. * call to goog.setCssNameMapping() with an object literal that the JSCompiler
  1828. * can extract and use to replace all calls to goog.getCssName(). In uncompiled
  1829. * mode, JavaScript code should be loaded before this base.js file that declares
  1830. * a global variable, CLOSURE_CSS_NAME_MAPPING, which is used below. This is
  1831. * to ensure that the mapping is loaded before any calls to goog.getCssName()
  1832. * are made in uncompiled mode.
  1833. *
  1834. * A hook for overriding the CSS name mapping.
  1835. * @type {!Object<string, string>|undefined}
  1836. */
  1837. goog.global.CLOSURE_CSS_NAME_MAPPING;
  1838. if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) {
  1839. // This does not call goog.setCssNameMapping() because the JSCompiler
  1840. // requires that goog.setCssNameMapping() be called with an object literal.
  1841. goog.cssNameMapping_ = goog.global.CLOSURE_CSS_NAME_MAPPING;
  1842. }
  1843. /**
  1844. * Gets a localized message.
  1845. *
  1846. * This function is a compiler primitive. If you give the compiler a localized
  1847. * message bundle, it will replace the string at compile-time with a localized
  1848. * version, and expand goog.getMsg call to a concatenated string.
  1849. *
  1850. * Messages must be initialized in the form:
  1851. * <code>
  1852. * var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'});
  1853. * </code>
  1854. *
  1855. * @param {string} str Translatable string, places holders in the form {$foo}.
  1856. * @param {Object<string, string>=} opt_values Maps place holder name to value.
  1857. * @return {string} message with placeholders filled.
  1858. */
  1859. goog.getMsg = function(str, opt_values) {
  1860. if (opt_values) {
  1861. str = str.replace(/\{\$([^}]+)}/g, function(match, key) {
  1862. return key in opt_values ? opt_values[key] : match;
  1863. });
  1864. }
  1865. return str;
  1866. };
  1867. /**
  1868. * Gets a localized message. If the message does not have a translation, gives a
  1869. * fallback message.
  1870. *
  1871. * This is useful when introducing a new message that has not yet been
  1872. * translated into all languages.
  1873. *
  1874. * This function is a compiler primitive. Must be used in the form:
  1875. * <code>var x = goog.getMsgWithFallback(MSG_A, MSG_B);</code>
  1876. * where MSG_A and MSG_B were initialized with goog.getMsg.
  1877. *
  1878. * @param {string} a The preferred message.
  1879. * @param {string} b The fallback message.
  1880. * @return {string} The best translated message.
  1881. */
  1882. goog.getMsgWithFallback = function(a, b) {
  1883. return a;
  1884. };
  1885. /**
  1886. * Exposes an unobfuscated global namespace path for the given object.
  1887. * Note that fields of the exported object *will* be obfuscated, unless they are
  1888. * exported in turn via this function or goog.exportProperty.
  1889. *
  1890. * Also handy for making public items that are defined in anonymous closures.
  1891. *
  1892. * ex. goog.exportSymbol('public.path.Foo', Foo);
  1893. *
  1894. * ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction);
  1895. * public.path.Foo.staticFunction();
  1896. *
  1897. * ex. goog.exportSymbol('public.path.Foo.prototype.myMethod',
  1898. * Foo.prototype.myMethod);
  1899. * new public.path.Foo().myMethod();
  1900. *
  1901. * @param {string} publicPath Unobfuscated name to export.
  1902. * @param {*} object Object the name should point to.
  1903. * @param {Object=} opt_objectToExportTo The object to add the path to; default
  1904. * is goog.global.
  1905. */
  1906. goog.exportSymbol = function(publicPath, object, opt_objectToExportTo) {
  1907. goog.exportPath_(publicPath, object, opt_objectToExportTo);
  1908. };
  1909. /**
  1910. * Exports a property unobfuscated into the object's namespace.
  1911. * ex. goog.exportProperty(Foo, 'staticFunction', Foo.staticFunction);
  1912. * ex. goog.exportProperty(Foo.prototype, 'myMethod', Foo.prototype.myMethod);
  1913. * @param {Object} object Object whose static property is being exported.
  1914. * @param {string} publicName Unobfuscated name to export.
  1915. * @param {*} symbol Object the name should point to.
  1916. */
  1917. goog.exportProperty = function(object, publicName, symbol) {
  1918. object[publicName] = symbol;
  1919. };
  1920. /**
  1921. * Inherit the prototype methods from one constructor into another.
  1922. *
  1923. * Usage:
  1924. * <pre>
  1925. * function ParentClass(a, b) { }
  1926. * ParentClass.prototype.foo = function(a) { };
  1927. *
  1928. * function ChildClass(a, b, c) {
  1929. * ChildClass.base(this, 'constructor', a, b);
  1930. * }
  1931. * goog.inherits(ChildClass, ParentClass);
  1932. *
  1933. * var child = new ChildClass('a', 'b', 'see');
  1934. * child.foo(); // This works.
  1935. * </pre>
  1936. *
  1937. * @param {Function} childCtor Child class.
  1938. * @param {Function} parentCtor Parent class.
  1939. */
  1940. goog.inherits = function(childCtor, parentCtor) {
  1941. /** @constructor */
  1942. function tempCtor() {};
  1943. tempCtor.prototype = parentCtor.prototype;
  1944. childCtor.superClass_ = parentCtor.prototype;
  1945. childCtor.prototype = new tempCtor();
  1946. /** @override */
  1947. childCtor.prototype.constructor = childCtor;
  1948. /**
  1949. * Calls superclass constructor/method.
  1950. *
  1951. * This function is only available if you use goog.inherits to
  1952. * express inheritance relationships between classes.
  1953. *
  1954. * NOTE: This is a replacement for goog.base and for superClass_
  1955. * property defined in childCtor.
  1956. *
  1957. * @param {!Object} me Should always be "this".
  1958. * @param {string} methodName The method name to call. Calling
  1959. * superclass constructor can be done with the special string
  1960. * 'constructor'.
  1961. * @param {...*} var_args The arguments to pass to superclass
  1962. * method/constructor.
  1963. * @return {*} The return value of the superclass method/constructor.
  1964. */
  1965. childCtor.base = function(me, methodName, var_args) {
  1966. // Copying using loop to avoid deop due to passing arguments object to
  1967. // function. This is faster in many JS engines as of late 2014.
  1968. var args = new Array(arguments.length - 2);
  1969. for (var i = 2; i < arguments.length; i++) {
  1970. args[i - 2] = arguments[i];
  1971. }
  1972. return parentCtor.prototype[methodName].apply(me, args);
  1973. };
  1974. };
  1975. /**
  1976. * Call up to the superclass.
  1977. *
  1978. * If this is called from a constructor, then this calls the superclass
  1979. * constructor with arguments 1-N.
  1980. *
  1981. * If this is called from a prototype method, then you must pass the name of the
  1982. * method as the second argument to this function. If you do not, you will get a
  1983. * runtime error. This calls the superclass' method with arguments 2-N.
  1984. *
  1985. * This function only works if you use goog.inherits to express inheritance
  1986. * relationships between your classes.
  1987. *
  1988. * This function is a compiler primitive. At compile-time, the compiler will do
  1989. * macro expansion to remove a lot of the extra overhead that this function
  1990. * introduces. The compiler will also enforce a lot of the assumptions that this
  1991. * function makes, and treat it as a compiler error if you break them.
  1992. *
  1993. * @param {!Object} me Should always be "this".
  1994. * @param {*=} opt_methodName The method name if calling a super method.
  1995. * @param {...*} var_args The rest of the arguments.
  1996. * @return {*} The return value of the superclass method.
  1997. * @suppress {es5Strict} This method can not be used in strict mode, but
  1998. * all Closure Library consumers must depend on this file.
  1999. */
  2000. goog.base = function(me, opt_methodName, var_args) {
  2001. var caller = arguments.callee.caller;
  2002. if (goog.STRICT_MODE_COMPATIBLE || (goog.DEBUG && !caller)) {
  2003. throw Error('arguments.caller not defined. goog.base() cannot be used ' +
  2004. 'with strict mode code. See ' +
  2005. 'http://www.ecma-international.org/ecma-262/5.1/#sec-C');
  2006. }
  2007. if (caller.superClass_) {
  2008. // Copying using loop to avoid deop due to passing arguments object to
  2009. // function. This is faster in many JS engines as of late 2014.
  2010. var ctorArgs = new Array(arguments.length - 1);
  2011. for (var i = 1; i < arguments.length; i++) {
  2012. ctorArgs[i - 1] = arguments[i];
  2013. }
  2014. // This is a constructor. Call the superclass constructor.
  2015. return caller.superClass_.constructor.apply(me, ctorArgs);
  2016. }
  2017. // Copying using loop to avoid deop due to passing arguments object to
  2018. // function. This is faster in many JS engines as of late 2014.
  2019. var args = new Array(arguments.length - 2);
  2020. for (var i = 2; i < arguments.length; i++) {
  2021. args[i - 2] = arguments[i];
  2022. }
  2023. var foundCaller = false;
  2024. for (var ctor = me.constructor;
  2025. ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
  2026. if (ctor.prototype[opt_methodName] === caller) {
  2027. foundCaller = true;
  2028. } else if (foundCaller) {
  2029. return ctor.prototype[opt_methodName].apply(me, args);
  2030. }
  2031. }
  2032. // If we did not find the caller in the prototype chain, then one of two
  2033. // things happened:
  2034. // 1) The caller is an instance method.
  2035. // 2) This method was not called by the right caller.
  2036. if (me[opt_methodName] === caller) {
  2037. return me.constructor.prototype[opt_methodName].apply(me, args);
  2038. } else {
  2039. throw Error(
  2040. 'goog.base called from a method of one name ' +
  2041. 'to a method of a different name');
  2042. }
  2043. };
  2044. /**
  2045. * Allow for aliasing within scope functions. This function exists for
  2046. * uncompiled code - in compiled code the calls will be inlined and the aliases
  2047. * applied. In uncompiled code the function is simply run since the aliases as
  2048. * written are valid JavaScript.
  2049. *
  2050. *
  2051. * @param {function()} fn Function to call. This function can contain aliases
  2052. * to namespaces (e.g. "var dom = goog.dom") or classes
  2053. * (e.g. "var Timer = goog.Timer").
  2054. */
  2055. goog.scope = function(fn) {
  2056. fn.call(goog.global);
  2057. };
  2058. /*
  2059. * To support uncompiled, strict mode bundles that use eval to divide source
  2060. * like so:
  2061. * eval('someSource;//# sourceUrl sourcefile.js');
  2062. * We need to export the globally defined symbols "goog" and "COMPILED".
  2063. * Exporting "goog" breaks the compiler optimizations, so we required that
  2064. * be defined externally.
  2065. * NOTE: We don't use goog.exportSymbol here because we don't want to trigger
  2066. * extern generation when that compiler option is enabled.
  2067. */
  2068. if (!COMPILED) {
  2069. goog.global['COMPILED'] = COMPILED;
  2070. }
  2071. //==============================================================================
  2072. // goog.defineClass implementation
  2073. //==============================================================================
  2074. /**
  2075. * Creates a restricted form of a Closure "class":
  2076. * - from the compiler's perspective, the instance returned from the
  2077. * constructor is sealed (no new properties may be added). This enables
  2078. * better checks.
  2079. * - the compiler will rewrite this definition to a form that is optimal
  2080. * for type checking and optimization (initially this will be a more
  2081. * traditional form).
  2082. *
  2083. * @param {Function} superClass The superclass, Object or null.
  2084. * @param {goog.defineClass.ClassDescriptor} def
  2085. * An object literal describing
  2086. * the class. It may have the following properties:
  2087. * "constructor": the constructor function
  2088. * "statics": an object literal containing methods to add to the constructor
  2089. * as "static" methods or a function that will receive the constructor
  2090. * function as its only parameter to which static properties can
  2091. * be added.
  2092. * all other properties are added to the prototype.
  2093. * @return {!Function} The class constructor.
  2094. */
  2095. goog.defineClass = function(superClass, def) {
  2096. // TODO(johnlenz): consider making the superClass an optional parameter.
  2097. var constructor = def.constructor;
  2098. var statics = def.statics;
  2099. // Wrap the constructor prior to setting up the prototype and static methods.
  2100. if (!constructor || constructor == Object.prototype.constructor) {
  2101. constructor = function() {
  2102. throw Error('cannot instantiate an interface (no constructor defined).');
  2103. };
  2104. }
  2105. var cls = goog.defineClass.createSealingConstructor_(constructor, superClass);
  2106. if (superClass) {
  2107. goog.inherits(cls, superClass);
  2108. }
  2109. // Remove all the properties that should not be copied to the prototype.
  2110. delete def.constructor;
  2111. delete def.statics;
  2112. goog.defineClass.applyProperties_(cls.prototype, def);
  2113. if (statics != null) {
  2114. if (statics instanceof Function) {
  2115. statics(cls);
  2116. } else {
  2117. goog.defineClass.applyProperties_(cls, statics);
  2118. }
  2119. }
  2120. return cls;
  2121. };
  2122. /**
  2123. * @typedef {
  2124. * !Object|
  2125. * {constructor:!Function}|
  2126. * {constructor:!Function, statics:(Object|function(Function):void)}}
  2127. * @suppress {missingProvide}
  2128. */
  2129. goog.defineClass.ClassDescriptor;
  2130. /**
  2131. * @define {boolean} Whether the instances returned by
  2132. * goog.defineClass should be sealed when possible.
  2133. */
  2134. goog.define('goog.defineClass.SEAL_CLASS_INSTANCES', goog.DEBUG);
  2135. /**
  2136. * If goog.defineClass.SEAL_CLASS_INSTANCES is enabled and Object.seal is
  2137. * defined, this function will wrap the constructor in a function that seals the
  2138. * results of the provided constructor function.
  2139. *
  2140. * @param {!Function} ctr The constructor whose results maybe be sealed.
  2141. * @param {Function} superClass The superclass constructor.
  2142. * @return {!Function} The replacement constructor.
  2143. * @private
  2144. */
  2145. goog.defineClass.createSealingConstructor_ = function(ctr, superClass) {
  2146. if (goog.defineClass.SEAL_CLASS_INSTANCES &&
  2147. Object.seal instanceof Function) {
  2148. // Don't seal subclasses of unsealable-tagged legacy classes.
  2149. if (superClass && superClass.prototype &&
  2150. superClass.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_]) {
  2151. return ctr;
  2152. }
  2153. /**
  2154. * @this {Object}
  2155. * @return {?}
  2156. */
  2157. var wrappedCtr = function() {
  2158. // Don't seal an instance of a subclass when it calls the constructor of
  2159. // its super class as there is most likely still setup to do.
  2160. var instance = ctr.apply(this, arguments) || this;
  2161. instance[goog.UID_PROPERTY_] = instance[goog.UID_PROPERTY_];
  2162. if (this.constructor === wrappedCtr) {
  2163. Object.seal(instance);
  2164. }
  2165. return instance;
  2166. };
  2167. return wrappedCtr;
  2168. }
  2169. return ctr;
  2170. };
  2171. // TODO(johnlenz): share these values with the goog.object
  2172. /**
  2173. * The names of the fields that are defined on Object.prototype.
  2174. * @type {!Array<string>}
  2175. * @private
  2176. * @const
  2177. */
  2178. goog.defineClass.OBJECT_PROTOTYPE_FIELDS_ = [
  2179. 'constructor',
  2180. 'hasOwnProperty',
  2181. 'isPrototypeOf',
  2182. 'propertyIsEnumerable',
  2183. 'toLocaleString',
  2184. 'toString',
  2185. 'valueOf'
  2186. ];
  2187. // TODO(johnlenz): share this function with the goog.object
  2188. /**
  2189. * @param {!Object} target The object to add properties to.
  2190. * @param {!Object} source The object to copy properties from.
  2191. * @private
  2192. */
  2193. goog.defineClass.applyProperties_ = function(target, source) {
  2194. // TODO(johnlenz): update this to support ES5 getters/setters
  2195. var key;
  2196. for (key in source) {
  2197. if (Object.prototype.hasOwnProperty.call(source, key)) {
  2198. target[key] = source[key];
  2199. }
  2200. }
  2201. // For IE the for-in-loop does not contain any properties that are not
  2202. // enumerable on the prototype object (for example isPrototypeOf from
  2203. // Object.prototype) and it will also not include 'replace' on objects that
  2204. // extend String and change 'replace' (not that it is common for anyone to
  2205. // extend anything except Object).
  2206. for (var i = 0; i < goog.defineClass.OBJECT_PROTOTYPE_FIELDS_.length; i++) {
  2207. key = goog.defineClass.OBJECT_PROTOTYPE_FIELDS_[i];
  2208. if (Object.prototype.hasOwnProperty.call(source, key)) {
  2209. target[key] = source[key];
  2210. }
  2211. }
  2212. };
  2213. /**
  2214. * Sealing classes breaks the older idiom of assigning properties on the
  2215. * prototype rather than in the constructor. As such, goog.defineClass
  2216. * must not seal subclasses of these old-style classes until they are fixed.
  2217. * Until then, this marks a class as "broken", instructing defineClass
  2218. * not to seal subclasses.
  2219. * @param {!Function} ctr The legacy constructor to tag as unsealable.
  2220. */
  2221. goog.tagUnsealableClass = function(ctr) {
  2222. if (!COMPILED && goog.defineClass.SEAL_CLASS_INSTANCES) {
  2223. ctr.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_] = true;
  2224. }
  2225. };
  2226. /**
  2227. * Name for unsealable tag property.
  2228. * @const @private {string}
  2229. */
  2230. goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_ = 'goog_defineClass_legacy_unsealable';