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

Side by Side Diff: extensions/renderer/resources/utils.js

Issue 917093003: Shorten Closure template notation from Array.<*> to Array<*>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove cvox Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var createClassWrapper = requireNative('utils').createClassWrapper; 5 var createClassWrapper = requireNative('utils').createClassWrapper;
6 var nativeDeepCopy = requireNative('utils').deepCopy; 6 var nativeDeepCopy = requireNative('utils').deepCopy;
7 var schemaRegistry = requireNative('schema_registry'); 7 var schemaRegistry = requireNative('schema_registry');
8 var CHECK = requireNative('logging').CHECK; 8 var CHECK = requireNative('logging').CHECK;
9 var DCHECK = requireNative('logging').DCHECK; 9 var DCHECK = requireNative('logging').DCHECK;
10 var WARNING = requireNative('logging').WARNING; 10 var WARNING = requireNative('logging').WARNING;
11 11
12 /** 12 /**
13 * An object forEach. Calls |f| with each (key, value) pair of |obj|, using 13 * An object forEach. Calls |f| with each (key, value) pair of |obj|, using
14 * |self| as the target. 14 * |self| as the target.
15 * @param {Object} obj The object to iterate over. 15 * @param {Object} obj The object to iterate over.
16 * @param {function} f The function to call in each iteration. 16 * @param {function} f The function to call in each iteration.
17 * @param {Object} self The object to use as |this| in each function call. 17 * @param {Object} self The object to use as |this| in each function call.
18 */ 18 */
19 function forEach(obj, f, self) { 19 function forEach(obj, f, self) {
20 for (var key in obj) { 20 for (var key in obj) {
21 if ($Object.hasOwnProperty(obj, key)) 21 if ($Object.hasOwnProperty(obj, key))
22 $Function.call(f, self, key, obj[key]); 22 $Function.call(f, self, key, obj[key]);
23 } 23 }
24 } 24 }
25 25
26 /** 26 /**
27 * Assuming |array_of_dictionaries| is structured like this: 27 * Assuming |array_of_dictionaries| is structured like this:
28 * [{id: 1, ... }, {id: 2, ...}, ...], you can use 28 * [{id: 1, ... }, {id: 2, ...}, ...], you can use
29 * lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2. 29 * lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2.
30 * @param {Array.<Object.<string, ?>>} array_of_dictionaries 30 * @param {Array<Object<string, ?>>} array_of_dictionaries
31 * @param {string} field 31 * @param {string} field
32 * @param {?} value 32 * @param {?} value
33 */ 33 */
34 function lookup(array_of_dictionaries, field, value) { 34 function lookup(array_of_dictionaries, field, value) {
35 var filter = function (dict) {return dict[field] == value;}; 35 var filter = function (dict) {return dict[field] == value;};
36 var matches = array_of_dictionaries.filter(filter); 36 var matches = array_of_dictionaries.filter(filter);
37 if (matches.length == 0) { 37 if (matches.length == 0) {
38 return undefined; 38 return undefined;
39 } else if (matches.length == 1) { 39 } else if (matches.length == 1) {
40 return matches[0] 40 return matches[0]
(...skipping 27 matching lines...) Expand all
68 * Takes a private class implementation |cls| and exposes a subset of its 68 * Takes a private class implementation |cls| and exposes a subset of its
69 * methods |functions| and properties |properties| and |readonly| in a public 69 * methods |functions| and properties |properties| and |readonly| in a public
70 * wrapper class that it returns. Within bindings code, you can access the 70 * wrapper class that it returns. Within bindings code, you can access the
71 * implementation from an instance of the wrapper class using 71 * implementation from an instance of the wrapper class using
72 * privates(instance).impl, and from the implementation class you can access 72 * privates(instance).impl, and from the implementation class you can access
73 * the wrapper using this.wrapper (or implInstance.wrapper if you have another 73 * the wrapper using this.wrapper (or implInstance.wrapper if you have another
74 * instance of the implementation class). 74 * instance of the implementation class).
75 * @param {string} name The name of the exposed wrapper class. 75 * @param {string} name The name of the exposed wrapper class.
76 * @param {Object} cls The class implementation. 76 * @param {Object} cls The class implementation.
77 * @param {{superclass: ?Function, 77 * @param {{superclass: ?Function,
78 * functions: ?Array.<string>, 78 * functions: ?Array<string>,
79 * properties: ?Array.<string>, 79 * properties: ?Array<string>,
80 * readonly: ?Array.<string>}} exposed The names of properties on the 80 * readonly: ?Array<string>}} exposed The names of properties on the
81 * implementation class to be exposed. |superclass| represents the 81 * implementation class to be exposed. |superclass| represents the
82 * constructor of the class to be used as the superclass of the exposed 82 * constructor of the class to be used as the superclass of the exposed
83 * class; |functions| represents the names of functions which should be 83 * class; |functions| represents the names of functions which should be
84 * delegated to the implementation; |properties| are gettable/settable 84 * delegated to the implementation; |properties| are gettable/settable
85 * properties and |readonly| are read-only properties. 85 * properties and |readonly| are read-only properties.
86 */ 86 */
87 function expose(name, cls, exposed) { 87 function expose(name, cls, exposed) {
88 var publicClass = createClassWrapper(name, cls, exposed.superclass); 88 var publicClass = createClassWrapper(name, cls, exposed.superclass);
89 89
90 if ('functions' in exposed) { 90 if ('functions' in exposed) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 $Function.apply(func, null, args); 165 $Function.apply(func, null, args);
166 }); 166 });
167 } 167 }
168 168
169 exports.forEach = forEach; 169 exports.forEach = forEach;
170 exports.loadTypeSchema = loadTypeSchema; 170 exports.loadTypeSchema = loadTypeSchema;
171 exports.lookup = lookup; 171 exports.lookup = lookup;
172 exports.expose = expose; 172 exports.expose = expose;
173 exports.deepCopy = deepCopy; 173 exports.deepCopy = deepCopy;
174 exports.promise = promise; 174 exports.promise = promise;
OLDNEW
« no previous file with comments | « extensions/renderer/resources/stash_client.js ('k') | extensions/test/data/web_view/apitest/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698