| Index: tools/telemetry/third_party/gsutilz/third_party/protorpc/experimental/javascript/closure/base.js
|
| diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/base.js b/tools/telemetry/third_party/gsutilz/third_party/protorpc/experimental/javascript/closure/base.js
|
| similarity index 66%
|
| copy from chrome/third_party/chromevox/third_party/closure-library/closure/goog/base.js
|
| copy to tools/telemetry/third_party/gsutilz/third_party/protorpc/experimental/javascript/closure/base.js
|
| index 469414cbb8534762eff467fbe16de89bb4b8b991..e1e353d3e7924f18ec2a278c5d9048cca9acb0e3 100644
|
| --- a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/base.js
|
| +++ b/tools/telemetry/third_party/gsutilz/third_party/protorpc/experimental/javascript/closure/base.js
|
| @@ -19,8 +19,6 @@
|
| * global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects to
|
| * include their own deps file(s) from different locations.
|
| *
|
| - *
|
| - * @provideGoog
|
| */
|
|
|
|
|
| @@ -32,13 +30,13 @@ var COMPILED = false;
|
|
|
|
|
| /**
|
| - * Base namespace for the Closure library. Checks to see goog is already
|
| - * defined in the current scope before assigning to prevent clobbering if
|
| - * base.js is loaded more than once.
|
| + * Base namespace for the Closure library. Checks to see goog is
|
| + * already defined in the current scope before assigning to prevent
|
| + * clobbering if base.js is loaded more than once.
|
| *
|
| * @const
|
| */
|
| -var goog = goog || {};
|
| +var goog = goog || {}; // Identifies this file as the Closure base.
|
|
|
|
|
| /**
|
| @@ -48,129 +46,6 @@ goog.global = this;
|
|
|
|
|
| /**
|
| - * A hook for overriding the define values in uncompiled mode.
|
| - *
|
| - * In uncompiled mode, {@code CLOSURE_UNCOMPILED_DEFINES} may be defined before
|
| - * loading base.js. If a key is defined in {@code CLOSURE_UNCOMPILED_DEFINES},
|
| - * {@code goog.define} will use the value instead of the default value. This
|
| - * allows flags to be overwritten without compilation (this is normally
|
| - * accomplished with the compiler's "define" flag).
|
| - *
|
| - * Example:
|
| - * <pre>
|
| - * var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false};
|
| - * </pre>
|
| - *
|
| - * @type {Object<string, (string|number|boolean)>|undefined}
|
| - */
|
| -goog.global.CLOSURE_UNCOMPILED_DEFINES;
|
| -
|
| -
|
| -/**
|
| - * A hook for overriding the define values in uncompiled or compiled mode,
|
| - * like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In
|
| - * uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence.
|
| - *
|
| - * Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or
|
| - * string literals or the compiler will emit an error.
|
| - *
|
| - * While any @define value may be set, only those set with goog.define will be
|
| - * effective for uncompiled code.
|
| - *
|
| - * Example:
|
| - * <pre>
|
| - * var CLOSURE_DEFINES = {'goog.DEBUG': false};
|
| - * </pre>
|
| - *
|
| - * @type {Object<string, (string|number|boolean)>|undefined}
|
| - */
|
| -goog.global.CLOSURE_DEFINES;
|
| -
|
| -
|
| -/**
|
| - * 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.
|
| - */
|
| -goog.isDef = function(val) {
|
| - // void 0 always evaluates to undefined and hence we do not need to depend on
|
| - // the definition of the global variable named 'undefined'.
|
| - return val !== void 0;
|
| -};
|
| -
|
| -
|
| -/**
|
| - * Builds an object structure for the provided namespace path, ensuring that
|
| - * names that already exist are not overwritten. For example:
|
| - * "a.b.c" -> a = {};a.b={};a.b.c={};
|
| - * Used by goog.provide and goog.exportSymbol.
|
| - * @param {string} name name of the object that this file defines.
|
| - * @param {*=} opt_object the object to expose at the end of the path.
|
| - * @param {Object=} opt_objectToExportTo The object to add the path to; default
|
| - * is |goog.global|.
|
| - * @private
|
| - */
|
| -goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) {
|
| - var parts = name.split('.');
|
| - var cur = opt_objectToExportTo || goog.global;
|
| -
|
| - // Internet Explorer exhibits strange behavior when throwing errors from
|
| - // methods externed in this manner. See the testExportSymbolExceptions in
|
| - // base_test.html for an example.
|
| - if (!(parts[0] in cur) && cur.execScript) {
|
| - 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]) {
|
| - cur = cur[part];
|
| - } else {
|
| - cur = cur[part] = {};
|
| - }
|
| - }
|
| -};
|
| -
|
| -
|
| -/**
|
| - * Defines a named value. In uncompiled mode, the value is retreived from
|
| - * CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and
|
| - * has the property specified, and otherwise used the defined defaultValue.
|
| - * When compiled, the default can be overridden using compiler command-line
|
| - * options.
|
| - *
|
| - * @param {string} name The distinguished name to provide.
|
| - * @param {string|number|boolean} defaultValue
|
| - */
|
| -goog.define = function(name, defaultValue) {
|
| - var value = defaultValue;
|
| - if (!COMPILED) {
|
| - if (goog.global.CLOSURE_UNCOMPILED_DEFINES &&
|
| - Object.prototype.hasOwnProperty.call(
|
| - goog.global.CLOSURE_UNCOMPILED_DEFINES, name)) {
|
| - value = goog.global.CLOSURE_UNCOMPILED_DEFINES[name];
|
| - } else if (goog.global.CLOSURE_DEFINES &&
|
| - Object.prototype.hasOwnProperty.call(
|
| - goog.global.CLOSURE_DEFINES, name)) {
|
| - value = goog.global.CLOSURE_DEFINES[name];
|
| - }
|
| - }
|
| - goog.exportPath_(name, value);
|
| -};
|
| -
|
| -
|
| -/**
|
| * @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
|
| @@ -200,38 +75,13 @@ goog.DEBUG = true;
|
| * 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.
|
| */
|
| -goog.define('goog.LOCALE', 'en'); // default to en
|
| -
|
| -
|
| -/**
|
| - * @define {boolean} Whether this code is running on trusted sites.
|
| - *
|
| - * On untrusted sites, several native functions can be defined or overridden by
|
| - * external libraries like Prototype, Datejs, and JQuery and setting this flag
|
| - * to false forces closure to use its own implementations when possible.
|
| - *
|
| - * If your JavaScript can be loaded by a third party site and you are wary about
|
| - * relying on non-standard implementations, specify
|
| - * "--define goog.TRUSTED_SITE=false" to the JSCompiler.
|
| - */
|
| -goog.define('goog.TRUSTED_SITE', true);
|
| -
|
| -
|
| -/**
|
| - * @define {boolean} Whether a project is expected to be running in strict mode.
|
| - *
|
| - * This define can be used to trigger alternate implementations compatible with
|
| - * running in EcmaScript Strict mode or warn about unavailable functionality.
|
| - * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode
|
| - */
|
| -goog.define('goog.STRICT_MODE_COMPATIBLE', false);
|
| +goog.LOCALE = 'en'; // default to en
|
|
|
|
|
| /**
|
| * Creates object stubs for a namespace. The presence of one or more
|
| * goog.provide() calls indicate that the file defines the given
|
| - * objects/namespaces. Provided objects must not be null or undefined.
|
| - * Build tools also scan for provide/require statements
|
| + * objects/namespaces. Build tools also scan for provide/require statements
|
| * to discern dependencies, build dependency files (see deps.js), etc.
|
| * @see goog.require
|
| * @param {string} name Namespace provided by this file in the form
|
| @@ -265,11 +115,6 @@ goog.provide = function(name) {
|
| /**
|
| * Marks that the current file should only be used for testing, and never for
|
| * live code in production.
|
| - *
|
| - * In the case of unit tests, the message may optionally be an exact namespace
|
| - * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra
|
| - * provide (if not explicitly defined in the code).
|
| - *
|
| * @param {string=} opt_message Optional message to add to the error that's
|
| * raised when used in production code.
|
| */
|
| @@ -282,25 +127,6 @@ goog.setTestOnly = function(opt_message) {
|
| };
|
|
|
|
|
| -/**
|
| - * Forward declares a symbol. This is an indication to the compiler that the
|
| - * symbol may be used in the source yet is not required and may not be provided
|
| - * in compilation.
|
| - *
|
| - * The most common usage of forward declaration is code that takes a type as a
|
| - * function parameter but does not need to require it. By forward declaring
|
| - * instead of requiring, no hard dependency is made, and (if not required
|
| - * elsewhere) the namespace may never be required and thus, not be pulled
|
| - * into the JavaScript binary. If it is required elsewhere, it will be type
|
| - * checked as normal.
|
| - *
|
| - *
|
| - * @param {string} name The namespace to forward declare in the form of
|
| - * "goog.package.part".
|
| - */
|
| -goog.forwardDeclare = function(name) {};
|
| -
|
| -
|
| if (!COMPILED) {
|
|
|
| /**
|
| @@ -311,14 +137,13 @@ if (!COMPILED) {
|
| * @private
|
| */
|
| goog.isProvided_ = function(name) {
|
| - return !goog.implicitNamespaces_[name] &&
|
| - goog.isDefAndNotNull(goog.getObjectByName(name));
|
| + return !goog.implicitNamespaces_[name] && !!goog.getObjectByName(name);
|
| };
|
|
|
| /**
|
| * Namespaces implicitly defined by goog.provide. For example,
|
| - * goog.provide('goog.events.Event') implicitly declares that 'goog' and
|
| - * 'goog.events' must be namespaces.
|
| + * goog.provide('goog.events.Event') implicitly declares
|
| + * that 'goog' and 'goog.events' must be namespaces.
|
| *
|
| * @type {Object}
|
| * @private
|
| @@ -328,15 +153,56 @@ if (!COMPILED) {
|
|
|
|
|
| /**
|
| - * Returns an object based on its fully qualified external name. The object
|
| - * is not found if null or undefined. If you are using a compilation pass that
|
| - * renames property names beware that using this function will not find renamed
|
| - * properties.
|
| + * Builds an object structure for the provided namespace path,
|
| + * ensuring that names that already exist are not overwritten. For
|
| + * example:
|
| + * "a.b.c" -> a = {};a.b={};a.b.c={};
|
| + * Used by goog.provide and goog.exportSymbol.
|
| + * @param {string} name name of the object that this file defines.
|
| + * @param {*=} opt_object the object to expose at the end of the path.
|
| + * @param {Object=} opt_objectToExportTo The object to add the path to; default
|
| + * is |goog.global|.
|
| + * @private
|
| + */
|
| +goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) {
|
| + var parts = name.split('.');
|
| + var cur = opt_objectToExportTo || goog.global;
|
| +
|
| + // Internet Explorer exhibits strange behavior when throwing errors from
|
| + // methods externed in this manner. See the testExportSymbolExceptions in
|
| + // base_test.html for an example.
|
| + if (!(parts[0] in cur) && cur.execScript) {
|
| + 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]) {
|
| + cur = cur[part];
|
| + } else {
|
| + cur = cur[part] = {};
|
| + }
|
| + }
|
| +};
|
| +
|
| +
|
| +/**
|
| + * Returns an object based on its fully qualified external name. If you are
|
| + * using a compilation pass that renames property names beware that using this
|
| + * function will not find renamed properties.
|
| *
|
| * @param {string} name The fully qualified name.
|
| * @param {Object=} opt_obj The object within which to look; default is
|
| * |goog.global|.
|
| - * @return {?} The value (object or primitive) or, if not found, null.
|
| + * @return {Object} The object or, if not found, null.
|
| */
|
| goog.getObjectByName = function(name, opt_obj) {
|
| var parts = name.split('.');
|
| @@ -377,7 +243,7 @@ goog.globalize = function(obj, opt_global) {
|
| * this file requires.
|
| */
|
| goog.addDependency = function(relPath, provides, requires) {
|
| - if (goog.DEPENDENCIES_ENABLED) {
|
| + if (!COMPILED) {
|
| var provide, require;
|
| var path = relPath.replace(/\\/g, '/');
|
| var deps = goog.dependencies_;
|
| @@ -400,14 +266,14 @@ goog.addDependency = function(relPath, provides, requires) {
|
|
|
|
|
|
|
| -// NOTE(nnaze): The debug DOM loader was included in base.js as an original way
|
| -// to do "debug-mode" development. The dependency system can sometimes be
|
| -// confusing, as can the debug DOM loader's asynchronous nature.
|
| +// NOTE(user): The debug DOM loader was included in base.js as an orignal
|
| +// way to do "debug-mode" development. The dependency system can sometimes
|
| +// be confusing, as can the debug DOM loader's asyncronous nature.
|
| //
|
| -// With the DOM loader, a call to goog.require() is not blocking -- the script
|
| -// will not load until some point after the current script. If a namespace is
|
| -// needed at runtime, it needs to be defined in a previous script, or loaded via
|
| -// require() with its registered dependencies.
|
| +// With the DOM loader, a call to goog.require() is not blocking -- the
|
| +// script will not load until some point after the current script. If a
|
| +// namespace is needed at runtime, it needs to be defined in a previous
|
| +// script, or loaded via require() with its registered dependencies.
|
| // User-defined namespaces may need their own deps file. See http://go/js_deps,
|
| // http://go/genjsdeps, or, externally, DepsWriter.
|
| // http://code.google.com/closure/library/docs/depswriter.html
|
| @@ -428,25 +294,26 @@ goog.addDependency = function(relPath, provides, requires) {
|
| * provided (and depend on the fact that some outside tool correctly ordered
|
| * the script).
|
| */
|
| -goog.define('goog.ENABLE_DEBUG_LOADER', true);
|
| +goog.ENABLE_DEBUG_LOADER = true;
|
|
|
|
|
| /**
|
| - * 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 --closure_pass option is used.
|
| + * 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
|
| + * --closure_pass option is used.
|
| * @see goog.provide
|
| - * @param {string} name Namespace to include (as was given in goog.provide()) in
|
| - * the form "goog.package.part".
|
| + * @param {string} name Namespace to include (as was given in goog.provide())
|
| + * in the form "goog.package.part".
|
| */
|
| goog.require = function(name) {
|
|
|
| - // If the object already exists we do not need do do anything.
|
| - // TODO(arv): If we start to support require based on file name this has to
|
| - // change.
|
| - // TODO(arv): If we allow goog.foo.* this has to change.
|
| - // TODO(arv): If we implement dynamic load after page load we should probably
|
| - // not remove this code for the compiled output.
|
| + // if the object already exists we do not need do do anything
|
| + // TODO(user): If we start to support require based on file name this has
|
| + // to change
|
| + // TODO(user): If we allow goog.foo.* this has to change
|
| + // TODO(user): If we implement dynamic load after page load we should probably
|
| + // not remove this code for the compiled output
|
| if (!COMPILED) {
|
| if (goog.isProvided_(name)) {
|
| return;
|
| @@ -474,7 +341,7 @@ goog.require = function(name) {
|
|
|
|
|
| /**
|
| - * Path for included scripts.
|
| + * Path for included scripts
|
| * @type {string}
|
| */
|
| goog.basePath = '';
|
| @@ -488,7 +355,8 @@ goog.global.CLOSURE_BASE_PATH;
|
|
|
|
|
| /**
|
| - * Whether to write out Closure's deps file. By default, the deps are written.
|
| + * Whether to write out Closure's deps file. By default,
|
| + * the deps are written.
|
| * @type {boolean|undefined}
|
| */
|
| goog.global.CLOSURE_NO_DEPS;
|
| @@ -502,7 +370,6 @@ goog.global.CLOSURE_NO_DEPS;
|
| *
|
| * The function is passed the script source, which is a relative URI. It should
|
| * return true if the script was imported, false otherwise.
|
| - * @type {(function(string): boolean)|undefined}
|
| */
|
| goog.global.CLOSURE_IMPORT_SCRIPT;
|
|
|
| @@ -517,29 +384,30 @@ goog.nullFunction = function() {};
|
| /**
|
| * The identity function. Returns its first argument.
|
| *
|
| - * @param {*=} opt_returnValue The single value that will be returned.
|
| - * @param {...*} var_args Optional trailing arguments. These are ignored.
|
| - * @return {?} The first argument. We can't know the type -- just pass it along
|
| - * without type.
|
| + * @param {...*} var_args The arguments of the function.
|
| + * @return {*} The first argument.
|
| * @deprecated Use goog.functions.identity instead.
|
| */
|
| -goog.identityFunction = function(opt_returnValue, var_args) {
|
| - return opt_returnValue;
|
| +goog.identityFunction = function(var_args) {
|
| + return arguments[0];
|
| };
|
|
|
|
|
| /**
|
| * When defining a class Foo with an abstract method bar(), you can do:
|
| + *
|
| * Foo.prototype.bar = goog.abstractMethod
|
| *
|
| - * Now if a subclass of Foo fails to override bar(), an error will be thrown
|
| - * when bar() is invoked.
|
| + * 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.
|
| + * 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.
|
| + * @throws {Error} when invoked to indicate the method should be
|
| + * overridden.
|
| */
|
| goog.abstractMethod = function() {
|
| throw Error('unimplemented abstract method');
|
| @@ -547,46 +415,22 @@ goog.abstractMethod = function() {
|
|
|
|
|
| /**
|
| - * Adds a {@code getInstance} static method that always returns the same
|
| - * instance object.
|
| + * Adds a {@code getInstance} static method that always return the same instance
|
| + * object.
|
| * @param {!Function} ctor The constructor for the class to add the static
|
| * method to.
|
| */
|
| goog.addSingletonGetter = function(ctor) {
|
| ctor.getInstance = function() {
|
| - if (ctor.instance_) {
|
| - return ctor.instance_;
|
| - }
|
| - if (goog.DEBUG) {
|
| - // NOTE: JSCompiler can't optimize away Array#push.
|
| - goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor;
|
| - }
|
| - return ctor.instance_ = new ctor;
|
| + return ctor.instance_ || (ctor.instance_ = new ctor());
|
| };
|
| };
|
|
|
|
|
| -/**
|
| - * All singleton classes that have been instantiated, for testing. Don't read
|
| - * it directly, use the {@code goog.testing.singleton} module. The compiler
|
| - * removes this variable if unused.
|
| - * @type {!Array<!Function>}
|
| - * @private
|
| - */
|
| -goog.instantiatedSingletons_ = [];
|
| -
|
| -
|
| -/**
|
| - * True if goog.dependencies_ is available.
|
| - * @const {boolean}
|
| - */
|
| -goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER;
|
| -
|
| -
|
| -if (goog.DEPENDENCIES_ENABLED) {
|
| +if (!COMPILED && goog.ENABLE_DEBUG_LOADER) {
|
| /**
|
| - * Object used to keep track of urls that have already been added. This record
|
| - * allows the prevention of circular dependencies.
|
| + * Object used to keep track of urls that have already been added. This
|
| + * record allows the prevention of circular dependencies.
|
| * @type {Object}
|
| * @private
|
| */
|
| @@ -595,7 +439,7 @@ if (goog.DEPENDENCIES_ENABLED) {
|
|
|
| /**
|
| * This object is used to keep track of dependencies and other data that is
|
| - * used for loading scripts.
|
| + * used for loading scripts
|
| * @private
|
| * @type {Object}
|
| */
|
| @@ -603,9 +447,10 @@ if (goog.DEPENDENCIES_ENABLED) {
|
| pathToNames: {}, // 1 to many
|
| nameToPath: {}, // 1 to 1
|
| requires: {}, // 1 to many
|
| - // Used when resolving dependencies to prevent us from visiting file twice.
|
| + // used when resolving dependencies to prevent us from
|
| + // visiting the file twice
|
| visited: {},
|
| - written: {} // Used to keep track of script files we have written.
|
| + written: {} // used to keep track of script files we have written
|
| };
|
|
|
|
|
| @@ -622,7 +467,7 @@ if (goog.DEPENDENCIES_ENABLED) {
|
|
|
|
|
| /**
|
| - * Tries to detect the base path of base.js script that bootstraps Closure.
|
| + * Tries to detect the base path of the base.js script that bootstraps Closure
|
| * @private
|
| */
|
| goog.findBasePath_ = function() {
|
| @@ -674,23 +519,6 @@ if (goog.DEPENDENCIES_ENABLED) {
|
| goog.writeScriptTag_ = function(src) {
|
| if (goog.inHtmlDocument_()) {
|
| var doc = goog.global.document;
|
| -
|
| - // If the user tries to require a new symbol after document load,
|
| - // something has gone terribly wrong. Doing a document.write would
|
| - // wipe out the page.
|
| - if (doc.readyState == 'complete') {
|
| - // Certain test frameworks load base.js multiple times, which tries
|
| - // to write deps.js each time. If that happens, just fail silently.
|
| - // These frameworks wipe the page between each load of base.js, so this
|
| - // is OK.
|
| - var isDeps = /\bdeps.js$/.test(src);
|
| - if (isDeps) {
|
| - return false;
|
| - } else {
|
| - throw Error('Cannot write "' + src + '" after document load');
|
| - }
|
| - }
|
| -
|
| doc.write(
|
| '<script type="text/javascript" src="' + src + '"></' + 'script>');
|
| return true;
|
| @@ -706,7 +534,7 @@ if (goog.DEPENDENCIES_ENABLED) {
|
| * @private
|
| */
|
| goog.writeScripts_ = function() {
|
| - // The scripts we need to write this time.
|
| + // the scripts we need to write this time
|
| var scripts = [];
|
| var seenScript = {};
|
| var deps = goog.dependencies_;
|
| @@ -716,8 +544,8 @@ if (goog.DEPENDENCIES_ENABLED) {
|
| return;
|
| }
|
|
|
| - // We have already visited this one. We can get here if we have cyclic
|
| - // dependencies.
|
| + // we have already visited this one. We can get here if we have cyclic
|
| + // dependencies
|
| if (path in deps.visited) {
|
| if (!(path in seenScript)) {
|
| seenScript[path] = true;
|
| @@ -848,7 +676,7 @@ goog.typeOf = function(value) {
|
| if ((className == '[object Array]' ||
|
| // In IE all non value types are wrapped as objects across window
|
| // boundaries (not iframe though) so we have to do object detection
|
| - // for this edge case.
|
| + // for this edge case
|
| typeof value.length == 'number' &&
|
| typeof value.splice != 'undefined' &&
|
| typeof value.propertyIsEnumerable != 'undefined' &&
|
| @@ -878,15 +706,17 @@ goog.typeOf = function(value) {
|
| return 'function';
|
| }
|
|
|
| +
|
| } else {
|
| return 'null';
|
| }
|
|
|
| } else if (s == 'function' && typeof value.call == 'undefined') {
|
| - // In Safari typeof nodeList returns 'function', and on Firefox typeof
|
| - // behaves similarly for HTML{Applet,Embed,Object}, Elements and RegExps. We
|
| - // would like to return object for those and we can detect an invalid
|
| - // function by making sure that the function object has a call method.
|
| + // In Safari typeof nodeList returns 'function', and on Firefox
|
| + // typeof behaves similarly for HTML{Applet,Embed,Object}Elements
|
| + // and RegExps. We would like to return object for those and we can
|
| + // detect an invalid function by making sure that the function
|
| + // object has a call method.
|
| return 'object';
|
| }
|
| return s;
|
| @@ -894,8 +724,67 @@ goog.typeOf = function(value) {
|
|
|
|
|
| /**
|
| - * Returns true if the specified value is null.
|
| - * @param {?} val Variable to test.
|
| + * Safe way to test whether a property is enumarable. It allows testing
|
| + * for enumerable on objects where 'propertyIsEnumerable' is overridden or
|
| + * does not exist (like DOM nodes in IE). Does not use browser native
|
| + * Object.propertyIsEnumerable.
|
| + * @param {Object} object The object to test if the property is enumerable.
|
| + * @param {string} propName The property name to check for.
|
| + * @return {boolean} True if the property is enumarable.
|
| + * @private
|
| + */
|
| +goog.propertyIsEnumerableCustom_ = function(object, propName) {
|
| + // KJS in Safari 2 is not ECMAScript compatible and lacks crucial methods
|
| + // such as propertyIsEnumerable. We therefore use a workaround.
|
| + // Does anyone know a more efficient work around?
|
| + if (propName in object) {
|
| + for (var key in object) {
|
| + if (key == propName &&
|
| + Object.prototype.hasOwnProperty.call(object, propName)) {
|
| + return true;
|
| + }
|
| + }
|
| + }
|
| + return false;
|
| +};
|
| +
|
| +
|
| +/**
|
| + * Safe way to test whether a property is enumarable. It allows testing
|
| + * for enumerable on objects where 'propertyIsEnumerable' is overridden or
|
| + * does not exist (like DOM nodes in IE).
|
| + * @param {Object} object The object to test if the property is enumerable.
|
| + * @param {string} propName The property name to check for.
|
| + * @return {boolean} True if the property is enumarable.
|
| + * @private
|
| + */
|
| +goog.propertyIsEnumerable_ = function(object, propName) {
|
| + // In IE if object is from another window, cannot use propertyIsEnumerable
|
| + // from this window's Object. Will raise a 'JScript object expected' error.
|
| + if (object instanceof Object) {
|
| + return Object.prototype.propertyIsEnumerable.call(object, propName);
|
| + } else {
|
| + return goog.propertyIsEnumerableCustom_(object, propName);
|
| + }
|
| +};
|
| +
|
| +
|
| +/**
|
| + * 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. Additionally, this function assumes that the global
|
| + * undefined variable has not been redefined.
|
| + * @param {*} val Variable to test.
|
| + * @return {boolean} Whether variable is defined.
|
| + */
|
| +goog.isDef = function(val) {
|
| + return val !== undefined;
|
| +};
|
| +
|
| +
|
| +/**
|
| + * Returns true if the specified value is |null|
|
| + * @param {*} val Variable to test.
|
| * @return {boolean} Whether variable is null.
|
| */
|
| goog.isNull = function(val) {
|
| @@ -904,8 +793,8 @@ goog.isNull = function(val) {
|
|
|
|
|
| /**
|
| - * Returns true if the specified value is defined and not null.
|
| - * @param {?} val Variable to test.
|
| + * Returns true if the specified value is defined and not null
|
| + * @param {*} val Variable to test.
|
| * @return {boolean} Whether variable is defined and not null.
|
| */
|
| goog.isDefAndNotNull = function(val) {
|
| @@ -915,8 +804,8 @@ goog.isDefAndNotNull = function(val) {
|
|
|
|
|
| /**
|
| - * Returns true if the specified value is an array.
|
| - * @param {?} val Variable to test.
|
| + * Returns true if the specified value is an array
|
| + * @param {*} val Variable to test.
|
| * @return {boolean} Whether variable is an array.
|
| */
|
| goog.isArray = function(val) {
|
| @@ -928,7 +817,7 @@ goog.isArray = function(val) {
|
| * Returns true if the object looks like an array. To qualify as array like
|
| * the value needs to be either a NodeList or an object with a Number length
|
| * property.
|
| - * @param {?} val Variable to test.
|
| + * @param {*} val Variable to test.
|
| * @return {boolean} Whether variable is an array.
|
| */
|
| goog.isArrayLike = function(val) {
|
| @@ -938,9 +827,9 @@ goog.isArrayLike = function(val) {
|
|
|
|
|
| /**
|
| - * Returns true if the object looks like a Date. To qualify as Date-like the
|
| - * value needs to be an object and have a getFullYear() function.
|
| - * @param {?} val Variable to test.
|
| + * Returns true if the object looks like a Date. To qualify as Date-like
|
| + * the value needs to be an object and have a getFullYear() function.
|
| + * @param {*} val Variable to test.
|
| * @return {boolean} Whether variable is a like a Date.
|
| */
|
| goog.isDateLike = function(val) {
|
| @@ -949,8 +838,8 @@ goog.isDateLike = function(val) {
|
|
|
|
|
| /**
|
| - * Returns true if the specified value is a string.
|
| - * @param {?} val Variable to test.
|
| + * 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) {
|
| @@ -959,8 +848,8 @@ goog.isString = function(val) {
|
|
|
|
|
| /**
|
| - * Returns true if the specified value is a boolean.
|
| - * @param {?} val Variable to test.
|
| + * Returns true if the specified value is a boolean
|
| + * @param {*} val Variable to test.
|
| * @return {boolean} Whether variable is boolean.
|
| */
|
| goog.isBoolean = function(val) {
|
| @@ -969,8 +858,8 @@ goog.isBoolean = function(val) {
|
|
|
|
|
| /**
|
| - * Returns true if the specified value is a number.
|
| - * @param {?} val Variable to test.
|
| + * 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) {
|
| @@ -979,8 +868,8 @@ goog.isNumber = function(val) {
|
|
|
|
|
| /**
|
| - * Returns true if the specified value is a function.
|
| - * @param {?} val Variable to test.
|
| + * Returns true if the specified value is a function
|
| + * @param {*} val Variable to test.
|
| * @return {boolean} Whether variable is a function.
|
| */
|
| goog.isFunction = function(val) {
|
| @@ -989,32 +878,30 @@ goog.isFunction = function(val) {
|
|
|
|
|
| /**
|
| - * Returns true if the specified value is an object. This includes arrays and
|
| - * functions.
|
| - * @param {?} val Variable to test.
|
| + * Returns true if the specified value is an object. This includes arrays
|
| + * and functions.
|
| + * @param {*} val Variable to test.
|
| * @return {boolean} Whether variable is an object.
|
| */
|
| goog.isObject = function(val) {
|
| - var type = typeof val;
|
| - return type == 'object' && val != null || type == 'function';
|
| - // return Object(val) === val also works, but is slower, especially if val is
|
| - // not an object.
|
| + var type = goog.typeOf(val);
|
| + return type == 'object' || type == 'array' || type == 'function';
|
| };
|
|
|
|
|
| /**
|
| - * Gets a unique ID for an object. This mutates the object so that further calls
|
| - * with the same object as a parameter returns the same value. The unique ID is
|
| - * guaranteed to be unique across the current session amongst objects that are
|
| - * passed into {@code getUid}. There is no guarantee that the ID is unique or
|
| - * consistent across sessions. It is unsafe to generate unique ID for function
|
| - * prototypes.
|
| + * Gets a unique ID for an object. This mutates the object so that further
|
| + * calls with the same object as a parameter returns the same value. The unique
|
| + * ID is guaranteed to be unique across the current session amongst objects that
|
| + * are passed into {@code getUid}. There is no guarantee that the ID is unique
|
| + * or consistent across sessions. It is unsafe to generate unique ID for
|
| + * function prototypes.
|
| *
|
| * @param {Object} obj The object to get the unique ID for.
|
| * @return {number} The unique ID for the object.
|
| */
|
| goog.getUid = function(obj) {
|
| - // TODO(arv): Make the type stricter, do not accept null.
|
| + // TODO(user): Make the type stricter, do not accept null.
|
|
|
| // In Opera window.hasOwnProperty exists but always returns false so we avoid
|
| // using it. As a consequence the unique ID generated for BaseClass.prototype
|
| @@ -1025,29 +912,16 @@ goog.getUid = function(obj) {
|
|
|
|
|
| /**
|
| - * Whether the given object is alreay assigned a unique ID.
|
| - *
|
| - * This does not modify the object.
|
| - *
|
| - * @param {Object} obj The object to check.
|
| - * @return {boolean} Whether there an assigned unique id for the object.
|
| - */
|
| -goog.hasUid = function(obj) {
|
| - return !!obj[goog.UID_PROPERTY_];
|
| -};
|
| -
|
| -
|
| -/**
|
| * Removes the unique ID from an object. This is useful if the object was
|
| * previously mutated using {@code goog.getUid} in which case the mutation is
|
| * undone.
|
| * @param {Object} obj The object to remove the unique ID field from.
|
| */
|
| goog.removeUid = function(obj) {
|
| - // TODO(arv): Make the type stricter, do not accept null.
|
| + // TODO(user): Make the type stricter, do not accept null.
|
|
|
| - // In IE, DOM nodes are not instances of Object and throw an exception if we
|
| - // try to delete. Instead we try to use removeAttribute.
|
| + // DOM nodes in IE are not instance of Object and throws exception
|
| + // for delete. Instead we try to use removeAttribute
|
| if ('removeAttribute' in obj) {
|
| obj.removeAttribute(goog.UID_PROPERTY_);
|
| }
|
| @@ -1061,11 +935,12 @@ goog.removeUid = function(obj) {
|
|
|
| /**
|
| * Name for unique ID property. Initialized in a way to help avoid collisions
|
| - * with other closure JavaScript on the same page.
|
| + * with other closure javascript on the same page.
|
| * @type {string}
|
| * @private
|
| */
|
| -goog.UID_PROPERTY_ = 'closure_uid_' + ((Math.random() * 1e9) >>> 0);
|
| +goog.UID_PROPERTY_ = 'closure_uid_' +
|
| + Math.floor(Math.random() * 2147483648).toString(36);
|
|
|
|
|
| /**
|
| @@ -1127,17 +1002,31 @@ goog.cloneObject = function(obj) {
|
|
|
|
|
| /**
|
| + * Forward declaration for the clone method. This is necessary until the
|
| + * compiler can better support duck-typing constructs as used in
|
| + * goog.cloneObject.
|
| + *
|
| + * TODO(user): Remove once the JSCompiler can infer that the check for
|
| + * proto.clone is safe in goog.cloneObject.
|
| + *
|
| + * @type {Function}
|
| + */
|
| +Object.prototype.clone;
|
| +
|
| +
|
| +/**
|
| * A native implementation of goog.bind.
|
| * @param {Function} fn A function to partially apply.
|
| - * @param {Object|undefined} selfObj Specifies the object which this should
|
| - * point to when the function is run.
|
| - * @param {...*} var_args Additional arguments that are partially applied to the
|
| - * function.
|
| + * @param {Object|undefined} selfObj Specifies the object which |this| should
|
| + * point to when the function is run. If the value is null or undefined, it
|
| + * will default to the global object.
|
| + * @param {...*} var_args Additional arguments that are partially
|
| + * applied to the function.
|
| * @return {!Function} A partially-applied form of the function bind() was
|
| * invoked as a method of.
|
| * @private
|
| - * @suppress {deprecated} The compiler thinks that Function.prototype.bind is
|
| - * deprecated because some people have declared a pure-JS version.
|
| + * @suppress {deprecated} The compiler thinks that Function.prototype.bind
|
| + * is deprecated because some people have declared a pure-JS version.
|
| * Only the pure-JS version is truly deprecated.
|
| */
|
| goog.bindNative_ = function(fn, selfObj, var_args) {
|
| @@ -1148,18 +1037,17 @@ goog.bindNative_ = function(fn, selfObj, var_args) {
|
| /**
|
| * A pure-JS implementation of goog.bind.
|
| * @param {Function} fn A function to partially apply.
|
| - * @param {Object|undefined} selfObj Specifies the object which this should
|
| - * point to when the function is run.
|
| - * @param {...*} var_args Additional arguments that are partially applied to the
|
| - * function.
|
| + * @param {Object|undefined} selfObj Specifies the object which |this| should
|
| + * point to when the function is run. If the value is null or undefined, it
|
| + * will default to the global object.
|
| + * @param {...*} var_args Additional arguments that are partially
|
| + * applied to the function.
|
| * @return {!Function} A partially-applied form of the function bind() was
|
| * invoked as a method of.
|
| * @private
|
| */
|
| goog.bindJs_ = function(fn, selfObj, var_args) {
|
| - if (!fn) {
|
| - throw new Error();
|
| - }
|
| + var context = selfObj || goog.global;
|
|
|
| if (arguments.length > 2) {
|
| var boundArgs = Array.prototype.slice.call(arguments, 2);
|
| @@ -1167,12 +1055,12 @@ goog.bindJs_ = function(fn, selfObj, var_args) {
|
| // Prepend the bound arguments to the current arguments.
|
| var newArgs = Array.prototype.slice.call(arguments);
|
| Array.prototype.unshift.apply(newArgs, boundArgs);
|
| - return fn.apply(selfObj, newArgs);
|
| + return fn.apply(context, newArgs);
|
| };
|
|
|
| } else {
|
| return function() {
|
| - return fn.apply(selfObj, arguments);
|
| + return fn.apply(context, arguments);
|
| };
|
| }
|
| };
|
| @@ -1181,36 +1069,37 @@ goog.bindJs_ = function(fn, selfObj, var_args) {
|
| /**
|
| * Partially applies this function to a particular 'this object' and zero or
|
| * more arguments. The result is a new function with some arguments of the first
|
| - * function pre-filled and the value of this 'pre-specified'.
|
| + * function pre-filled and the value of |this| 'pre-specified'.<br><br>
|
| *
|
| - * Remaining arguments specified at call-time are appended to the pre-specified
|
| - * ones.
|
| + * Remaining arguments specified at call-time are appended to the pre-
|
| + * specified ones.<br><br>
|
| *
|
| - * Also see: {@link #partial}.
|
| + * Also see: {@link #partial}.<br><br>
|
| *
|
| * Usage:
|
| * <pre>var barMethBound = bind(myFunction, myObj, 'arg1', 'arg2');
|
| * barMethBound('arg3', 'arg4');</pre>
|
| *
|
| - * @param {?function(this:T, ...)} fn A function to partially apply.
|
| - * @param {T} selfObj Specifies the object which this should point to when the
|
| - * function is run.
|
| - * @param {...*} var_args Additional arguments that are partially applied to the
|
| - * function.
|
| + * @param {Function} fn A function to partially apply.
|
| + * @param {Object|undefined} selfObj Specifies the object which |this| should
|
| + * point to when the function is run. If the value is null or undefined, it
|
| + * will default to the global object.
|
| + * @param {...*} var_args Additional arguments that are partially
|
| + * applied to the function.
|
| * @return {!Function} A partially-applied form of the function bind() was
|
| * invoked as a method of.
|
| - * @template T
|
| * @suppress {deprecated} See above.
|
| */
|
| goog.bind = function(fn, selfObj, var_args) {
|
| // TODO(nicksantos): narrow the type signature.
|
| if (Function.prototype.bind &&
|
| - // NOTE(nicksantos): Somebody pulled base.js into the default Chrome
|
| - // extension environment. This means that for Chrome extensions, they get
|
| - // the implementation of Function.prototype.bind that calls goog.bind
|
| - // instead of the native one. Even worse, we don't want to introduce a
|
| - // circular dependency between goog.bind and Function.prototype.bind, so
|
| - // we have to hack this to make sure it works correctly.
|
| + // NOTE(nicksantos): Somebody pulled base.js into the default
|
| + // Chrome extension environment. This means that for Chrome extensions,
|
| + // they get the implementation of Function.prototype.bind that
|
| + // calls goog.bind instead of the native one. Even worse, we don't want
|
| + // to introduce a circular dependency between goog.bind and
|
| + // Function.prototype.bind, so we have to hack this to make sure it
|
| + // works correctly.
|
| Function.prototype.bind.toString().indexOf('native code') != -1) {
|
| goog.bind = goog.bindNative_;
|
| } else {
|
| @@ -1229,17 +1118,17 @@ goog.bind = function(fn, selfObj, var_args) {
|
| * g(arg3, arg4);
|
| *
|
| * @param {Function} fn A function to partially apply.
|
| - * @param {...*} var_args Additional arguments that are partially applied to fn.
|
| + * @param {...*} var_args Additional arguments that are partially
|
| + * applied to fn.
|
| * @return {!Function} A partially-applied form of the function bind() was
|
| * invoked as a method of.
|
| */
|
| goog.partial = function(fn, var_args) {
|
| var args = Array.prototype.slice.call(arguments, 1);
|
| return function() {
|
| - // Clone the array (with slice()) and append additional arguments
|
| - // to the existing arguments.
|
| - var newArgs = args.slice();
|
| - newArgs.push.apply(newArgs, arguments);
|
| + // Prepend the bound arguments to the current arguments.
|
| + var newArgs = Array.prototype.slice.call(arguments);
|
| + newArgs.unshift.apply(newArgs, args);
|
| return fn.apply(this, newArgs);
|
| };
|
| };
|
| @@ -1269,7 +1158,7 @@ goog.mixin = function(target, source) {
|
| * @return {number} An integer value representing the number of milliseconds
|
| * between midnight, January 1, 1970 and the current time.
|
| */
|
| -goog.now = (goog.TRUSTED_SITE && Date.now) || (function() {
|
| +goog.now = Date.now || (function() {
|
| // Unary plus operator converts its operand to a number which in the case of
|
| // a date is done by calling getTime().
|
| return +new Date();
|
| @@ -1277,7 +1166,7 @@ goog.now = (goog.TRUSTED_SITE && Date.now) || (function() {
|
|
|
|
|
| /**
|
| - * Evals JavaScript in the global scope. In IE this uses execScript, other
|
| + * Evals javascript in the global scope. In IE this uses execScript, other
|
| * browsers use goog.global.eval. If goog.global.eval does not evaluate in the
|
| * global scope (for example, in Safari), appends a script tag instead.
|
| * Throws an exception if neither execScript or eval is defined.
|
| @@ -1352,26 +1241,27 @@ goog.cssNameMappingStyle_;
|
| *
|
| * This function works in tandem with @see goog.setCssNameMapping.
|
| *
|
| - * Without any mapping set, the arguments are simple joined with a hyphen and
|
| - * passed through unaltered.
|
| + * Without any mapping set, the arguments are simple joined with a
|
| + * hyphen and passed through unaltered.
|
| *
|
| - * When there is a mapping, there are two possible styles in which these
|
| - * mappings are used. In the BY_PART style, each part (i.e. in between hyphens)
|
| - * of the passed in css name is rewritten according to the map. In the BY_WHOLE
|
| - * style, the full css name is looked up in the map directly. If a rewrite is
|
| - * not specified by the map, the compiler will output a warning.
|
| + * When there is a mapping, there are two possible styles in which
|
| + * these mappings are used. In the BY_PART style, each part (i.e. in
|
| + * between hyphens) of the passed in css name is rewritten according
|
| + * to the map. In the BY_WHOLE style, the full css name is looked up in
|
| + * the map directly. If a rewrite is not specified by the map, the
|
| + * compiler will output a warning.
|
| *
|
| - * When the mapping is passed to the compiler, it will replace calls to
|
| - * goog.getCssName with the strings from the mapping, e.g.
|
| + * When the mapping is passed to the compiler, it will replace calls
|
| + * to goog.getCssName with the strings from the mapping, e.g.
|
| * var x = goog.getCssName('foo');
|
| * var y = goog.getCssName(this.baseClass, 'active');
|
| * becomes:
|
| * var x= 'foo';
|
| * var y = this.baseClass + '-active';
|
| *
|
| - * If one argument is passed it will be processed, if two are passed only the
|
| - * modifier will be processed, as it is assumed the first argument was generated
|
| - * as a result of calling goog.getCssName.
|
| + * If one argument is passed it will be processed, if two are passed
|
| + * only the modifier will be processed, as it is assumed the first
|
| + * argument was generated as a result of calling goog.getCssName.
|
| *
|
| * @param {string} className The class name.
|
| * @param {string=} opt_modifier A modifier to be appended to the class name.
|
| @@ -1430,50 +1320,18 @@ goog.getCssName = function(className, opt_modifier) {
|
| * @param {!Object} mapping A map of strings to strings where keys are possible
|
| * arguments to goog.getCssName() and values are the corresponding values
|
| * that should be returned.
|
| - * @param {string=} opt_style The style of css name mapping. There are two valid
|
| + * @param {string=} style The style of css name mapping. There are two valid
|
| * options: 'BY_PART', and 'BY_WHOLE'.
|
| * @see goog.getCssName for a description.
|
| */
|
| -goog.setCssNameMapping = function(mapping, opt_style) {
|
| +goog.setCssNameMapping = function(mapping, style) {
|
| goog.cssNameMapping_ = mapping;
|
| - goog.cssNameMappingStyle_ = opt_style;
|
| + goog.cssNameMappingStyle_ = style;
|
| };
|
|
|
|
|
| /**
|
| - * To use CSS renaming in compiled mode, one of the input files should have a
|
| - * call to goog.setCssNameMapping() with an object literal that the JSCompiler
|
| - * can extract and use to replace all calls to goog.getCssName(). In uncompiled
|
| - * mode, JavaScript code should be loaded before this base.js file that declares
|
| - * a global variable, CLOSURE_CSS_NAME_MAPPING, which is used below. This is
|
| - * to ensure that the mapping is loaded before any calls to goog.getCssName()
|
| - * are made in uncompiled mode.
|
| - *
|
| - * A hook for overriding the CSS name mapping.
|
| - * @type {Object|undefined}
|
| - */
|
| -goog.global.CLOSURE_CSS_NAME_MAPPING;
|
| -
|
| -
|
| -if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) {
|
| - // This does not call goog.setCssNameMapping() because the JSCompiler
|
| - // requires that goog.setCssNameMapping() be called with an object literal.
|
| - goog.cssNameMapping_ = goog.global.CLOSURE_CSS_NAME_MAPPING;
|
| -}
|
| -
|
| -
|
| -/**
|
| - * Gets a localized message.
|
| - *
|
| - * This function is a compiler primitive. If you give the compiler a localized
|
| - * message bundle, it will replace the string at compile-time with a localized
|
| - * version, and expand goog.getMsg call to a concatenated string.
|
| - *
|
| - * Messages must be initialized in the form:
|
| - * <code>
|
| - * var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'});
|
| - * </code>
|
| - *
|
| + * Abstract implementation of goog.getMsg for use with localized messages.
|
| * @param {string} str Translatable string, places holders in the form {$foo}.
|
| * @param {Object=} opt_values Map of place holder name to value.
|
| * @return {string} message with placeholders filled.
|
| @@ -1489,35 +1347,18 @@ goog.getMsg = function(str, opt_values) {
|
|
|
|
|
| /**
|
| - * Gets a localized message. If the message does not have a translation, gives a
|
| - * fallback message.
|
| - *
|
| - * This is useful when introducing a new message that has not yet been
|
| - * translated into all languages.
|
| - *
|
| - * This function is a compiler primitive. Must be used in the form:
|
| - * <code>var x = goog.getMsgWithFallback(MSG_A, MSG_B);</code>
|
| - * where MSG_A and MSG_B were initialized with goog.getMsg.
|
| - *
|
| - * @param {string} a The preferred message.
|
| - * @param {string} b The fallback message.
|
| - * @return {string} The best translated message.
|
| - */
|
| -goog.getMsgWithFallback = function(a, b) {
|
| - return a;
|
| -};
|
| -
|
| -
|
| -/**
|
| * Exposes an unobfuscated global namespace path for the given object.
|
| - * Note that fields of the exported object *will* be obfuscated, unless they are
|
| - * exported in turn via this function or goog.exportProperty.
|
| + * Note that fields of the exported object *will* be obfuscated,
|
| + * unless they are exported in turn via this function or
|
| + * goog.exportProperty
|
| *
|
| - * Also handy for making public items that are defined in anonymous closures.
|
| + * <p>Also handy for making public items that are defined in anonymous
|
| + * closures.
|
| *
|
| - * ex. goog.exportSymbol('public.path.Foo', Foo);
|
| + * ex. goog.exportSymbol('Foo', Foo);
|
| *
|
| - * ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction);
|
| + * ex. goog.exportSymbol('public.path.Foo.staticFunction',
|
| + * Foo.staticFunction);
|
| * public.path.Foo.staticFunction();
|
| *
|
| * ex. goog.exportSymbol('public.path.Foo.prototype.myMethod',
|
| @@ -1527,7 +1368,7 @@ goog.getMsgWithFallback = function(a, b) {
|
| * @param {string} publicPath Unobfuscated name to export.
|
| * @param {*} object Object the name should point to.
|
| * @param {Object=} opt_objectToExportTo The object to add the path to; default
|
| - * is goog.global.
|
| + * is |goog.global|.
|
| */
|
| goog.exportSymbol = function(publicPath, object, opt_objectToExportTo) {
|
| goog.exportPath_(publicPath, object, opt_objectToExportTo);
|
| @@ -1556,21 +1397,22 @@ goog.exportProperty = function(object, publicName, symbol) {
|
| * ParentClass.prototype.foo = function(a) { }
|
| *
|
| * function ChildClass(a, b, c) {
|
| - * goog.base(this, a, b);
|
| + * ParentClass.call(this, a, b);
|
| * }
|
| + *
|
| * goog.inherits(ChildClass, ParentClass);
|
| *
|
| * var child = new ChildClass('a', 'b', 'see');
|
| - * child.foo(); // This works.
|
| + * child.foo(); // works
|
| * </pre>
|
| *
|
| - * In addition, a superclass' implementation of a method can be invoked as
|
| - * follows:
|
| + * In addition, a superclass' implementation of a method can be invoked
|
| + * as follows:
|
| *
|
| * <pre>
|
| * ChildClass.prototype.foo = function(a) {
|
| * ChildClass.superClass_.foo.call(this, a);
|
| - * // Other code here.
|
| + * // other code
|
| * };
|
| * </pre>
|
| *
|
| @@ -1583,30 +1425,7 @@ goog.inherits = function(childCtor, parentCtor) {
|
| tempCtor.prototype = parentCtor.prototype;
|
| childCtor.superClass_ = parentCtor.prototype;
|
| childCtor.prototype = new tempCtor();
|
| - /** @override */
|
| childCtor.prototype.constructor = childCtor;
|
| -
|
| - /**
|
| - * Calls superclass constructor/method.
|
| - *
|
| - * This function is only available if you use goog.inherits to
|
| - * express inheritance relationships between classes.
|
| - *
|
| - * NOTE: This is a replacement for goog.base and for superClass_
|
| - * property defined in childCtor.
|
| - *
|
| - * @param {!Object} me Should always be "this".
|
| - * @param {string} methodName The method name to call. Calling
|
| - * superclass constructor can be done with the special string
|
| - * 'constructor'.
|
| - * @param {...*} var_args The arguments to pass to superclass
|
| - * method/constructor.
|
| - * @return {*} The return value of the superclass method/constructor.
|
| - */
|
| - childCtor.base = function(me, methodName, var_args) {
|
| - var args = Array.prototype.slice.call(arguments, 2);
|
| - return parentCtor.prototype[methodName].apply(me, args);
|
| - };
|
| };
|
|
|
|
|
| @@ -1614,36 +1433,29 @@ goog.inherits = function(childCtor, parentCtor) {
|
| * Call up to the superclass.
|
| *
|
| * If this is called from a constructor, then this calls the superclass
|
| - * constructor with arguments 1-N.
|
| + * contructor with arguments 1-N.
|
| *
|
| - * If this is called from a prototype method, then you must pass the name of the
|
| - * method as the second argument to this function. If you do not, you will get a
|
| - * runtime error. This calls the superclass' method with arguments 2-N.
|
| + * If this is called from a prototype method, then you must pass
|
| + * the name of the method as the second argument to this function. If
|
| + * you do not, you will get a runtime error. This calls the superclass'
|
| + * method with arguments 2-N.
|
| *
|
| - * This function only works if you use goog.inherits to express inheritance
|
| - * relationships between your classes.
|
| + * This function only works if you use goog.inherits to express
|
| + * inheritance relationships between your classes.
|
| *
|
| - * This function is a compiler primitive. At compile-time, the compiler will do
|
| - * macro expansion to remove a lot of the extra overhead that this function
|
| - * introduces. The compiler will also enforce a lot of the assumptions that this
|
| - * function makes, and treat it as a compiler error if you break them.
|
| + * This function is a compiler primitive. At compile-time, the
|
| + * compiler will do macro expansion to remove a lot of
|
| + * the extra overhead that this function introduces. The compiler
|
| + * will also enforce a lot of the assumptions that this function
|
| + * makes, and treat it as a compiler error if you break them.
|
| *
|
| * @param {!Object} me Should always be "this".
|
| * @param {*=} opt_methodName The method name if calling a super method.
|
| * @param {...*} var_args The rest of the arguments.
|
| * @return {*} The return value of the superclass method.
|
| - * @suppress {es5Strict} This method can not be used in strict mode, but
|
| - * all Closure Library consumers must depend on this file.
|
| */
|
| goog.base = function(me, opt_methodName, var_args) {
|
| var caller = arguments.callee.caller;
|
| -
|
| - if (goog.STRICT_MODE_COMPATIBLE || (goog.DEBUG && !caller)) {
|
| - throw Error('arguments.caller not defined. goog.base() cannot be used ' +
|
| - 'with strict mode code. See ' +
|
| - 'http://www.ecma-international.org/ecma-262/5.1/#sec-C');
|
| - }
|
| -
|
| if (caller.superClass_) {
|
| // This is a constructor. Call the superclass constructor.
|
| return caller.superClass_.constructor.apply(
|
| @@ -1661,8 +1473,8 @@ goog.base = function(me, opt_methodName, var_args) {
|
| }
|
| }
|
|
|
| - // If we did not find the caller in the prototype chain, then one of two
|
| - // things happened:
|
| + // If we did not find the caller in the prototype chain,
|
| + // then one of two things happened:
|
| // 1) The caller is an instance method.
|
| // 2) This method was not called by the right caller.
|
| if (me[opt_methodName] === caller) {
|
| @@ -1677,30 +1489,15 @@ goog.base = function(me, opt_methodName, var_args) {
|
|
|
| /**
|
| * Allow for aliasing within scope functions. This function exists for
|
| - * uncompiled code - in compiled code the calls will be inlined and the aliases
|
| - * applied. In uncompiled code the function is simply run since the aliases as
|
| - * written are valid JavaScript.
|
| + * uncompiled code - in compiled code the calls will be inlined and the
|
| + * aliases applied. In uncompiled code the function is simply run since the
|
| + * aliases as written are valid JavaScript.
|
| * @param {function()} fn Function to call. This function can contain aliases
|
| * to namespaces (e.g. "var dom = goog.dom") or classes
|
| - * (e.g. "var Timer = goog.Timer").
|
| + * (e.g. "var Timer = goog.Timer").
|
| */
|
| goog.scope = function(fn) {
|
| fn.call(goog.global);
|
| };
|
|
|
|
|
| -/*
|
| - * To support uncompiled, strict mode bundles that use eval to divide source
|
| - * like so:
|
| - * eval('someSource;//# sourceUrl sourcefile.js');
|
| - * We need to export the globally defined symbols "goog" and "COMPILED".
|
| - * Exporting "goog" breaks the compiler optimizations, so we required that
|
| - * be defined externally.
|
| - * NOTE: We don't use goog.exportSymbol here because we don't want to trigger
|
| - * extern generation when that compiler option is enabled.
|
| - */
|
| -if (!COMPILED) {
|
| - goog.global['COMPILED'] = COMPILED;
|
| -}
|
| -
|
| -
|
|
|