Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Unified Diff: third_party/google_input_tools/third_party/closure_library/closure/goog/base.js

Issue 674153004: Add third_party/google-input-tools: Take 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@google_input_tools
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/google_input_tools/third_party/closure_library/closure/goog/base.js
diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/base.js b/third_party/google_input_tools/third_party/closure_library/closure/goog/base.js
similarity index 89%
copy from chrome/third_party/chromevox/third_party/closure-library/closure/goog/base.js
copy to third_party/google_input_tools/third_party/closure_library/closure/goog/base.js
index 68f871b163b98d1eaf9d9f9f920f8b840d1995f9..ead806b43e93996dc9199e893c2f5c4abec71c5f 100644
--- a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/base.js
+++ b/third_party/google_input_tools/third_party/closure_library/closure/goog/base.js
@@ -277,7 +277,7 @@ goog.setTestOnly = function(opt_message) {
if (COMPILED && !goog.DEBUG) {
opt_message = opt_message || '';
throw Error('Importing test-only code into non-debug environment' +
- opt_message ? ': ' + opt_message : '.');
+ (opt_message ? ': ' + opt_message : '.'));
}
};
@@ -410,7 +410,7 @@ goog.addDependency = function(relPath, provides, requires) {
// 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
+// 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
@@ -1479,10 +1479,10 @@ if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) {
* @return {string} message with placeholders filled.
*/
goog.getMsg = function(str, opt_values) {
- var values = opt_values || {};
- for (var key in values) {
- var value = ('' + values[key]).replace(/\$/g, '$$$$');
- str = str.replace(new RegExp('\\{\\$' + key + '\\}', 'gi'), value);
+ if (opt_values) {
+ str = str.replace(/\{\$([^}]+)}/g, function(match, key) {
+ return key in opt_values ? opt_values[key] : match;
+ });
}
return str;
};
@@ -1553,10 +1553,10 @@ goog.exportProperty = function(object, publicName, symbol) {
* Usage:
* <pre>
* function ParentClass(a, b) { }
- * ParentClass.prototype.foo = function(a) { }
+ * ParentClass.prototype.foo = function(a) { };
*
* function ChildClass(a, b, c) {
- * goog.base(this, a, b);
+ * ChildClass.base(this, 'constructor', a, b);
* }
* goog.inherits(ChildClass, ParentClass);
*
@@ -1564,16 +1564,6 @@ goog.exportProperty = function(object, publicName, symbol) {
* child.foo(); // This works.
* </pre>
*
- * 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.
- * };
- * </pre>
- *
* @param {Function} childCtor Child class.
* @param {Function} parentCtor Parent class.
*/
@@ -1680,6 +1670,8 @@ goog.base = function(me, opt_methodName, var_args) {
* 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").
@@ -1704,3 +1696,180 @@ if (!COMPILED) {
}
+
+//==============================================================================
+// goog.defineClass implementation
+//==============================================================================
+
+/**
+ * Creates a restricted form of a Closure "class":
+ * - from the compiler's perspective, the instance returned from the
+ * constructor is sealed (no new properties may be added). This enables
+ * better checks.
+ * - the compiler will rewrite this definition to a form that is optimal
+ * for type checking and optimization (initially this will be a more
+ * traditional form).
+ *
+ * @param {Function} superClass The superclass, Object or null.
+ * @param {goog.defineClass.ClassDescriptor} def
+ * An object literal describing the
+ * the class. It may have the following properties:
+ * "constructor": the constructor function
+ * "statics": an object literal containing methods to add to the constructor
+ * as "static" methods or a function that will receive the constructor
+ * function as its only parameter to which static properties can
+ * be added.
+ * all other properties are added to the prototype.
+ * @return {!Function} The class constructor.
+ */
+goog.defineClass = function(superClass, def) {
+ // TODO(johnlenz): consider making the superClass an optional parameter.
+ var constructor = def.constructor;
+ var statics = def.statics;
+ // Wrap the constructor prior to setting up the prototype and static methods.
+ if (!constructor || constructor == Object.prototype.constructor) {
+ constructor = function() {
+ throw Error('cannot instantiate an interface (no constructor defined).');
+ };
+ }
+
+ var cls = goog.defineClass.createSealingConstructor_(constructor, superClass);
+ if (superClass) {
+ goog.inherits(cls, superClass);
+ }
+
+ // Remove all the properties that should not be copied to the prototype.
+ delete def.constructor;
+ delete def.statics;
+
+ goog.defineClass.applyProperties_(cls.prototype, def);
+ if (statics != null) {
+ if (statics instanceof Function) {
+ statics(cls);
+ } else {
+ goog.defineClass.applyProperties_(cls, statics);
+ }
+ }
+
+ return cls;
+};
+
+
+/**
+ * @typedef {
+ * !Object|
+ * {constructor:!Function}|
+ * {constructor:!Function, statics:(Object|function(Function):void)}}
+ */
+goog.defineClass.ClassDescriptor;
+
+
+/**
+ * @define {boolean} Whether the instances returned by
+ * goog.defineClass should be sealed when possible.
+ */
+goog.define('goog.defineClass.SEAL_CLASS_INSTANCES', goog.DEBUG);
+
+
+/**
+ * If goog.defineClass.SEAL_CLASS_INSTANCES is enabled and Object.seal is
+ * defined, this function will wrap the constructor in a function that seals the
+ * results of the provided constructor function.
+ *
+ * @param {!Function} ctr The constructor whose results maybe be sealed.
+ * @param {Function} superClass The superclass constructor.
+ * @return {!Function} The replacement constructor.
+ * @private
+ */
+goog.defineClass.createSealingConstructor_ = function(ctr, superClass) {
+ if (goog.defineClass.SEAL_CLASS_INSTANCES &&
+ Object.seal instanceof Function) {
+ // Don't seal subclasses of unsealable-tagged legacy classes.
+ if (superClass && superClass.prototype &&
+ superClass.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_]) {
+ return ctr;
+ }
+ /** @this {*} */
+ var wrappedCtr = function() {
+ // Don't seal an instance of a subclass when it calls the constructor of
+ // its super class as there is most likely still setup to do.
+ var instance = ctr.apply(this, arguments) || this;
+ if (this.constructor === wrappedCtr) {
+ Object.seal(instance);
+ }
+ return instance;
+ };
+ return wrappedCtr;
+ }
+ return ctr;
+};
+
+
+// TODO(johnlenz): share these values with the goog.object
+/**
+ * The names of the fields that are defined on Object.prototype.
+ * @type {!Array.<string>}
+ * @private
+ * @const
+ */
+goog.defineClass.OBJECT_PROTOTYPE_FIELDS_ = [
+ 'constructor',
+ 'hasOwnProperty',
+ 'isPrototypeOf',
+ 'propertyIsEnumerable',
+ 'toLocaleString',
+ 'toString',
+ 'valueOf'
+];
+
+
+// TODO(johnlenz): share this function with the goog.object
+/**
+ * @param {!Object} target The object to add properties to.
+ * @param {!Object} source The object to copy properites from.
+ * @private
+ */
+goog.defineClass.applyProperties_ = function(target, source) {
+ // TODO(johnlenz): update this to support ES5 getters/setters
+
+ var key;
+ for (key in source) {
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
+ target[key] = source[key];
+ }
+ }
+
+ // For IE the for-in-loop does not contain any properties that are not
+ // enumerable on the prototype object (for example isPrototypeOf from
+ // Object.prototype) and it will also not include 'replace' on objects that
+ // extend String and change 'replace' (not that it is common for anyone to
+ // extend anything except Object).
+ for (var i = 0; i < goog.defineClass.OBJECT_PROTOTYPE_FIELDS_.length; i++) {
+ key = goog.defineClass.OBJECT_PROTOTYPE_FIELDS_[i];
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
+ target[key] = source[key];
+ }
+ }
+};
+
+
+/**
+ * Sealing classes breaks the older idiom of assigning properties on the
+ * prototype rather than in the constructor. As such, goog.defineClass
+ * must not seal subclasses of these old-style classes until they are fixed.
+ * Until then, this marks a class as "broken", instructing defineClass
+ * not to seal subclasses.
+ * @param {!Function} ctr The legacy constructor to tag as unsealable.
+ */
+goog.tagUnsealableClass = function(ctr) {
+ if (!COMPILED && goog.defineClass.SEAL_CLASS_INSTANCES) {
+ ctr.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_] = true;
+ }
+};
+
+
+/**
+ * Name for unsealable tag property.
+ * @const @private {string}
+ */
+goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_ = 'goog_defineClass_legacy_unsealable';

Powered by Google App Engine
This is Rietveld 408576698