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

Unified Diff: chrome/renderer/resources/extensions/utils.js

Issue 10392127: Move declarative API into events API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix change schema type reference from 'Event' to 'events.Event' Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/utils.js
diff --git a/chrome/renderer/resources/extensions/utils.js b/chrome/renderer/resources/extensions/utils.js
new file mode 100644
index 0000000000000000000000000000000000000000..47d827745128bb7e40b2af5baa633957ee25dc21
--- /dev/null
+++ b/chrome/renderer/resources/extensions/utils.js
@@ -0,0 +1,29 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function forEach(dict, f) {
+ for (key in dict) {
+ if (dict.hasOwnProperty(key))
+ f(key, dict[key]);
+ }
+}
+
+// Assuming |array_of_dictionaries| is structured like this:
+// [{id: 1, ... }, {id: 2, ...}, ...], you can use
+// lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2.
+function lookup(array_of_dictionaries, field, value) {
+ var filter = function (dict) {return dict[field] == value;};
+ var matches = array_of_dictionaries.filter(filter);
+ if (matches.length == 0) {
+ return undefined;
+ } else if (matches.length == 1) {
+ return matches[0]
+ } else {
+ throw new Error("Failed lookup of field '" + field + "' with value '" +
+ value + "'");
+ }
+}
+
+exports.forEach = forEach;
+exports.lookup = lookup;

Powered by Google App Engine
This is Rietveld 408576698