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

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

Issue 1936673002: [Extensions] Finish freezing schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 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
« no previous file with comments | « extensions/renderer/resources/storage_area.js ('k') | extensions/renderer/safe_builtins.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
(...skipping 15 matching lines...) Expand all
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<?>>} array_of_dictionaries 30 * @param {Array<Object<?>>} 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.filter(array_of_dictionaries, 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]
41 } else { 41 } else {
42 throw new Error("Failed lookup of field '" + field + "' with value '" + 42 throw new Error("Failed lookup of field '" + field + "' with value '" +
43 value + "'"); 43 value + "'");
44 } 44 }
45 } 45 }
46 46
(...skipping 118 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.$set('forEach', forEach); 169 exports.$set('forEach', forEach);
170 exports.$set('loadTypeSchema', loadTypeSchema); 170 exports.$set('loadTypeSchema', loadTypeSchema);
171 exports.$set('lookup', lookup); 171 exports.$set('lookup', lookup);
172 exports.$set('expose', expose); 172 exports.$set('expose', expose);
173 exports.$set('deepCopy', deepCopy); 173 exports.$set('deepCopy', deepCopy);
174 exports.$set('promise', promise); 174 exports.$set('promise', promise);
OLDNEW
« no previous file with comments | « extensions/renderer/resources/storage_area.js ('k') | extensions/renderer/safe_builtins.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698