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

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

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more progress Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 chrome = requireNative('chrome').GetChrome();
not at google - send to devlin 2013/01/24 21:10:12 Just curious: is there a particular reason why you
cduvall 2013/01/24 22:15:15 I think since they are being loaded differently th
6
5 function forEach(dict, f) { 7 function forEach(dict, f) {
6 for (key in dict) { 8 for (key in dict) {
7 if (dict.hasOwnProperty(key)) 9 if (dict.hasOwnProperty(key))
8 f(key, dict[key]); 10 f(key, dict[key]);
9 } 11 }
10 } 12 }
11 13
12 // Assuming |array_of_dictionaries| is structured like this: 14 // Assuming |array_of_dictionaries| is structured like this:
13 // [{id: 1, ... }, {id: 2, ...}, ...], you can use 15 // [{id: 1, ... }, {id: 2, ...}, ...], you can use
14 // lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2. 16 // lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2.
15 function lookup(array_of_dictionaries, field, value) { 17 function lookup(array_of_dictionaries, field, value) {
16 var filter = function (dict) {return dict[field] == value;}; 18 var filter = function (dict) {return dict[field] == value;};
17 var matches = array_of_dictionaries.filter(filter); 19 var matches = array_of_dictionaries.filter(filter);
18 if (matches.length == 0) { 20 if (matches.length == 0) {
19 return undefined; 21 return undefined;
20 } else if (matches.length == 1) { 22 } else if (matches.length == 1) {
21 return matches[0] 23 return matches[0]
22 } else { 24 } else {
23 throw new Error("Failed lookup of field '" + field + "' with value '" + 25 throw new Error("Failed lookup of field '" + field + "' with value '" +
24 value + "'"); 26 value + "'");
25 } 27 }
26 } 28 }
27 29
30 function loadRefDependency(ref) {
31 var parts = ref.split(".");
32 return chrome[parts.slice(0, parts.length - 1).join(".")];
not at google - send to devlin 2013/01/24 21:10:12 So this forces the object to be loaded? What if |r
cduvall 2013/01/24 22:15:15 This will just do nothing if its called for a ref
33 }
34
28 exports.forEach = forEach; 35 exports.forEach = forEach;
36 exports.loadRefDependency = loadRefDependency;
29 exports.lookup = lookup; 37 exports.lookup = lookup;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698