From 2b4757367470d8e36bc00901dac567e375796ed4 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 13 Nov 2018 00:24:09 -0500 Subject: update viz 2 to use the newest version, which has some performance improvements and is easier to read the code for. also update the description --- assets/viz/2/goog/base.js | 622 ++++++++++++++++++++++++++++++---------------- 1 file changed, 408 insertions(+), 214 deletions(-) (limited to 'assets/viz/2/goog/base.js') diff --git a/assets/viz/2/goog/base.js b/assets/viz/2/goog/base.js index 97a9947..46b2f09 100644 --- a/assets/viz/2/goog/base.js +++ b/assets/viz/2/goog/base.js @@ -15,19 +15,19 @@ /** * @fileoverview Bootstrap for the Google JS Library (Closure). * - * In uncompiled mode base.js will write out Closure's deps file, unless the - * global CLOSURE_NO_DEPS is set to true. This allows projects to - * include their own deps file(s) from different locations. + * In uncompiled mode base.js will attempt to load Closure's deps file, unless + * the global CLOSURE_NO_DEPS is set to true. This allows projects + * to include their own deps file(s) from different locations. * - * @author arv@google.com (Erik Arvidsson) + * Avoid including base.js more than once. This is strictly discouraged and not + * supported. goog.require(...) won't work properly in that case. * * @provideGoog */ /** - * @define {boolean} Overridden to true by the compiler when - * --process_closure_primitives is specified. + * @define {boolean} Overridden to true by the compiler. */ var COMPILED = false; @@ -90,8 +90,6 @@ goog.global.CLOSURE_DEFINES; /** * Returns true if the specified value is not undefined. - * WARNING: Do not use this to test if an object has a property. Use the in - * operator instead. * * @param {?} val Variable to test. * @return {boolean} Whether variable is defined. @@ -102,6 +100,35 @@ goog.isDef = function(val) { return val !== void 0; }; +/** + * Returns true if the specified value is a string. + * @param {?} val Variable to test. + * @return {boolean} Whether variable is a string. + */ +goog.isString = function(val) { + return typeof val == 'string'; +}; + + +/** + * Returns true if the specified value is a boolean. + * @param {?} val Variable to test. + * @return {boolean} Whether variable is boolean. + */ +goog.isBoolean = function(val) { + return typeof val == 'boolean'; +}; + + +/** + * Returns true if the specified value is a number. + * @param {?} val Variable to test. + * @return {boolean} Whether variable is a number. + */ +goog.isNumber = function(val) { + return typeof val == 'number'; +}; + /** * Builds an object structure for the provided namespace path, ensuring that @@ -111,7 +138,7 @@ goog.isDef = function(val) { * @param {string} name name of the object that this file defines. * @param {*=} opt_object the object to expose at the end of the path. * @param {Object=} opt_objectToExportTo The object to add the path to; default - * is |goog.global|. + * is `goog.global`. * @private */ goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { @@ -125,17 +152,11 @@ goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { cur.execScript('var ' + parts[0]); } - // Certain browsers cannot parse code in the form for((a in b); c;); - // This pattern is produced by the JSCompiler when it collapses the - // statement above into the conditional loop below. To prevent this from - // happening, use a for-loop and reserve the init logic as below. - - // Parentheses added to eliminate strict JS warning in Firefox. for (var part; parts.length && (part = parts.shift());) { if (!parts.length && goog.isDef(opt_object)) { // last part and we have an object; use it cur[part] = opt_object; - } else if (cur[part]) { + } else if (cur[part] && cur[part] !== Object.prototype[part]) { cur = cur[part]; } else { cur = cur[part] = {}; @@ -158,11 +179,16 @@ goog.define = function(name, defaultValue) { var value = defaultValue; if (!COMPILED) { if (goog.global.CLOSURE_UNCOMPILED_DEFINES && + // Anti DOM-clobbering runtime check (b/37736576). + /** @type {?} */ (goog.global.CLOSURE_UNCOMPILED_DEFINES).nodeType === + undefined && Object.prototype.hasOwnProperty.call( goog.global.CLOSURE_UNCOMPILED_DEFINES, name)) { value = goog.global.CLOSURE_UNCOMPILED_DEFINES[name]; } else if ( goog.global.CLOSURE_DEFINES && + // Anti DOM-clobbering runtime check (b/37736576). + /** @type {?} */ (goog.global.CLOSURE_DEFINES).nodeType === undefined && Object.prototype.hasOwnProperty.call( goog.global.CLOSURE_DEFINES, name)) { value = goog.global.CLOSURE_DEFINES[name]; @@ -174,11 +200,12 @@ goog.define = function(name, defaultValue) { /** * @define {boolean} DEBUG is provided as a convenience so that debugging code - * that should not be included in a production js_binary can be easily stripped - * by specifying --define goog.DEBUG=false to the JSCompiler. For example, most - * toString() methods should be declared inside an "if (goog.DEBUG)" conditional - * because they are generally used for debugging purposes and it is difficult - * for the JSCompiler to statically determine whether they are used. + * that should not be included in a production. It can be easily stripped + * by specifying --define goog.DEBUG=false to the Closure Compiler aka + * JSCompiler. For example, most toString() methods should be declared inside an + * "if (goog.DEBUG)" conditional because they are generally used for debugging + * purposes and it is difficult for the JSCompiler to statically determine + * whether they are used. */ goog.define('goog.DEBUG', true); @@ -186,7 +213,7 @@ goog.define('goog.DEBUG', true); /** * @define {string} LOCALE defines the locale being used for compilation. It is * used to select locale specific data to be compiled in js binary. BUILD rule - * can specify this value by "--define goog.LOCALE=" as JSCompiler + * can specify this value by "--define goog.LOCALE=" as a compiler * option. * * Take into account that the locale code format is important. You should use @@ -200,7 +227,8 @@ goog.define('goog.DEBUG', true); * For language codes you should use values defined by ISO 693-1. See it here * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from * this rule: the Hebrew language. For legacy reasons the old code (iw) should - * be used instead of the new code (he), see http://wiki/Main/IIISynonyms. + * be used instead of the new code (he). + * */ goog.define('goog.LOCALE', 'en'); // default to en @@ -214,7 +242,7 @@ goog.define('goog.LOCALE', 'en'); // default to en * * If your JavaScript can be loaded by a third party site and you are wary about * relying on non-standard implementations, specify - * "--define goog.TRUSTED_SITE=false" to the JSCompiler. + * "--define goog.TRUSTED_SITE=false" to the compiler. */ goog.define('goog.TRUSTED_SITE', true); @@ -345,6 +373,7 @@ goog.VALID_MODULE_RE_ = /^[a-zA-Z_$][a-zA-Z0-9._$]*$/; * * @param {string} name Namespace provided by this file in the form * "goog.package.part", is expected but not required. + * @return {void} */ goog.module = function(name) { if (!goog.isString(name) || !name || @@ -352,7 +381,13 @@ goog.module = function(name) { throw Error('Invalid module identifier'); } if (!goog.isInModuleLoader_()) { - throw Error('Module ' + name + ' has been loaded incorrectly.'); + throw Error( + 'Module ' + name + ' has been loaded incorrectly. Note, ' + + 'modules cannot be loaded as normal scripts. They require some kind of ' + + 'pre-processing step. You\'re likely trying to load a module via a ' + + 'script tag or as a part of a concatenated bundle without rewriting the ' + + 'module. For more info see: ' + + 'https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.'); } if (goog.moduleLoaderState_.moduleName) { throw Error('goog.module may only be called once per module.'); @@ -393,14 +428,14 @@ goog.module.get = function(name) { */ goog.module.getInternal_ = function(name) { if (!COMPILED) { - if (goog.isProvided_(name)) { - // goog.require only return a value with-in goog.module files. - return name in goog.loadedModules_ ? goog.loadedModules_[name] : - goog.getObjectByName(name); - } else { - return null; + if (name in goog.loadedModules_) { + return goog.loadedModules_[name]; + } else if (!goog.implicitNamespaces_[name]) { + var ns = goog.getObjectByName(name); + return ns != null ? ns : null; } } + return null; }; @@ -473,6 +508,9 @@ goog.setTestOnly = function(opt_message) { * into the JavaScript binary. If it is required elsewhere, it will be type * checked as normal. * + * Before using goog.forwardDeclare, please read the documentation at + * https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation to + * understand the options and tradeoffs when working with forward declarations. * * @param {string} name The namespace to forward declare in the form of * "goog.package.part". @@ -612,7 +650,7 @@ goog.addDependency = function(relPath, provides, requires, opt_loadFlags) { // Externally: https://developers.google.com/closure/library/docs/depswriter // // Because of legacy clients, the DOM loader can't be easily removed from -// base.js. Work is being done to make it disableable or replaceable for +// base.js. Work was done to make it disableable or replaceable for // different environments (DOM-less JavaScript interpreters like Rhino or V8, // for example). See bootstrap/ for more information. @@ -644,8 +682,7 @@ goog.logToConsole_ = function(msg) { /** * Implements a system for the dynamic resolution of dependencies that works in * parallel with the BUILD system. Note that all calls to goog.require will be - * stripped by the JSCompiler when the --process_closure_primitives option is - * used. + * stripped by the compiler. * @see goog.provide * @param {string} name Namespace to include (as was given in goog.provide()) in * the form "goog.package.part". @@ -653,7 +690,7 @@ goog.logToConsole_ = function(msg) { * module otherwise null. */ goog.require = function(name) { - // If the object already exists we do not need do do anything. + // If the object already exists we do not need to do anything. if (!COMPILED) { if (goog.ENABLE_DEBUG_LOADER && goog.IS_OLD_IE_) { goog.maybeProcessDeferredDep_(name); @@ -662,23 +699,20 @@ goog.require = function(name) { if (goog.isProvided_(name)) { if (goog.isInModuleLoader_()) { return goog.module.getInternal_(name); - } else { - return null; } - } - - if (goog.ENABLE_DEBUG_LOADER) { + } else if (goog.ENABLE_DEBUG_LOADER) { var path = goog.getPathFromDeps_(name); if (path) { goog.writeScripts_(path); - return null; + } else { + var errorMessage = 'goog.require could not find: ' + name; + goog.logToConsole_(errorMessage); + + throw Error(errorMessage); } } - var errorMessage = 'goog.require could not find: ' + name; - goog.logToConsole_(errorMessage); - - throw Error(errorMessage); + return null; } }; @@ -698,7 +732,8 @@ goog.global.CLOSURE_BASE_PATH; /** - * Whether to write out Closure's deps file. By default, the deps are written. + * Whether to attempt to load Closure's deps file. By default, when uncompiled, + * deps files will attempt to be loaded. * @type {boolean|undefined} */ goog.global.CLOSURE_NO_DEPS; @@ -731,9 +766,6 @@ goog.nullFunction = function() {}; * Now if a subclass of Foo fails to override bar(), an error will be thrown * when bar() is invoked. * - * Note: This does not take the name of the function to override as an argument - * because that would make it more difficult to obfuscate our JavaScript code. - * * @type {!Function} * @throws {Error} when invoked to indicate the method should be overridden. */ @@ -749,6 +781,10 @@ goog.abstractMethod = function() { * method to. */ goog.addSingletonGetter = function(ctor) { + // instance_ is immediately set to prevent issues with sealed constructors + // such as are encountered when a constructor is returned as the export object + // of a goog.module in unoptimized code. + ctor.instance_ = undefined; ctor.getInstance = function() { if (ctor.instance_) { return ctor.instance_; @@ -870,7 +906,9 @@ if (goog.DEPENDENCIES_ENABLED) { * @private */ goog.findBasePath_ = function() { - if (goog.isDef(goog.global.CLOSURE_BASE_PATH)) { + if (goog.isDef(goog.global.CLOSURE_BASE_PATH) && + // Anti DOM-clobbering runtime check (b/37736576). + goog.isString(goog.global.CLOSURE_BASE_PATH)) { goog.basePath = goog.global.CLOSURE_BASE_PATH; return; } else if (!goog.inHtmlDocument_()) { @@ -878,7 +916,13 @@ if (goog.DEPENDENCIES_ENABLED) { } /** @type {Document} */ var doc = goog.global.document; - var scripts = doc.getElementsByTagName('SCRIPT'); + // If we have a currentScript available, use it exclusively. + var currentScript = doc.currentScript; + if (currentScript) { + var scripts = [currentScript]; + } else { + var scripts = doc.getElementsByTagName('SCRIPT'); + } // Search backwards since the current script is in almost all cases the one // that has base.js. for (var i = scripts.length - 1; i >= 0; --i) { @@ -919,6 +963,17 @@ if (goog.DEPENDENCIES_ENABLED) { !!(!goog.global.atob && goog.global.document && goog.global.document.all); + /** + * Whether IE9 or earlier is waiting on a dependency. This ensures that + * deferred modules that have no non-deferred dependencies actually get + * loaded, since if we defer them and then never pull in a non-deferred + * script, then `goog.loadQueuedModules_` will never be called. Instead, + * if not waiting on anything we simply don't defer in the first place. + * @private {boolean} + */ + goog.oldIeWaiting_ = false; + + /** * Given a URL initiate retrieval and execution of a script that needs * pre-processing. @@ -1003,6 +1058,7 @@ if (goog.DEPENDENCIES_ENABLED) { goog.maybeProcessDeferredPath_(path); } } + goog.oldIeWaiting_ = false; }; @@ -1028,8 +1084,9 @@ if (goog.DEPENDENCIES_ENABLED) { goog.isDeferredModule_ = function(name) { var path = goog.getPathFromDeps_(name); var loadFlags = path && goog.dependencies_.loadFlags[path] || {}; + var languageLevel = loadFlags['lang'] || 'es3'; if (path && (loadFlags['module'] == 'goog' || - goog.needsTranspile_(loadFlags['lang']))) { + goog.needsTranspile_(languageLevel))) { var abspath = goog.basePath + path; return (abspath) in goog.dependencies_.deferred; } @@ -1097,68 +1154,6 @@ if (goog.DEPENDENCIES_ENABLED) { }; - /** - * @param {function(?):?|string} moduleDef The module definition. - */ - goog.loadModule = function(moduleDef) { - // NOTE: we allow function definitions to be either in the from - // of a string to eval (which keeps the original source intact) or - // in a eval forbidden environment (CSP) we allow a function definition - // which in its body must call {@code goog.module}, and return the exports - // of the module. - var previousState = goog.moduleLoaderState_; - try { - goog.moduleLoaderState_ = { - moduleName: undefined, - declareLegacyNamespace: false - }; - var exports; - if (goog.isFunction(moduleDef)) { - exports = moduleDef.call(goog.global, {}); - } else if (goog.isString(moduleDef)) { - exports = goog.loadModuleFromSource_.call(goog.global, moduleDef); - } else { - throw Error('Invalid module definition'); - } - - var moduleName = goog.moduleLoaderState_.moduleName; - if (!goog.isString(moduleName) || !moduleName) { - throw Error('Invalid module name \"' + moduleName + '\"'); - } - - // Don't seal legacy namespaces as they may be uses as a parent of - // another namespace - if (goog.moduleLoaderState_.declareLegacyNamespace) { - goog.constructNamespace_(moduleName, exports); - } else if (goog.SEAL_MODULE_EXPORTS && Object.seal) { - Object.seal(exports); - } - - goog.loadedModules_[moduleName] = exports; - } finally { - goog.moduleLoaderState_ = previousState; - } - }; - - - /** - * @private @const {function(string):?} - * - * The new type inference warns because this function has no formal - * parameters, but its jsdoc says that it takes one argument. - * (The argument is used via arguments[0], but NTI does not detect this.) - * @suppress {newCheckTypes} - */ - goog.loadModuleFromSource_ = function() { - // NOTE: we avoid declaring parameters or local variables here to avoid - // masking globals or leaking values into the module definition. - 'use strict'; - var exports = {}; - eval(arguments[0]); - return exports; - }; - - /** * Writes a new script pointing to {@code src} directly into the DOM. * @@ -1246,8 +1241,9 @@ if (goog.DEPENDENCIES_ENABLED) { goog.writeScriptSrcNode_(src); } } else { - var state = " onreadystatechange='goog.onScriptLoad_(this, " + - ++goog.lastNonModuleScriptIndex_ + ")' "; + goog.oldIeWaiting_ = true; + var state = ' onreadystatechange=\'goog.onScriptLoad_(this, ' + + ++goog.lastNonModuleScriptIndex_ + ')\' '; doc.write( '