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

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

Issue 12647017: Lazily require types when validating Extensions API calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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(); 5 var chrome = requireNative('chrome').GetChrome();
6 var schemaRegistry = requireNative('schema_registry');
6 7
7 function forEach(obj, f, self) { 8 function forEach(obj, f, self) {
8 // For arrays, make sure the indices are numbers not strings - and in that 9 // For arrays, make sure the indices are numbers not strings - and in that
9 // case this method can be more efficient by assuming the array isn't sparse. 10 // case this method can be more efficient by assuming the array isn't sparse.
10 // 11 //
11 // Note: not (instanceof Array) because the array might come from a different 12 // Note: not (instanceof Array) because the array might come from a different
12 // context than our own. 13 // context than our own.
13 if (obj.constructor && obj.constructor.name == 'Array') { 14 if (obj.constructor && obj.constructor.name == 'Array') {
14 for (var i = 0; i < obj.length; i++) 15 for (var i = 0; i < obj.length; i++)
15 f.call(self, i, obj[i]); 16 f.call(self, i, obj[i]);
(...skipping 14 matching lines...) Expand all
30 if (matches.length == 0) { 31 if (matches.length == 0) {
31 return undefined; 32 return undefined;
32 } else if (matches.length == 1) { 33 } else if (matches.length == 1) {
33 return matches[0] 34 return matches[0]
34 } else { 35 } else {
35 throw new Error("Failed lookup of field '" + field + "' with value '" + 36 throw new Error("Failed lookup of field '" + field + "' with value '" +
36 value + "'"); 37 value + "'");
37 } 38 }
38 } 39 }
39 40
40 // Specify |currentApi| if this should return an API for $refs in the current 41 function loadRefType(ref, defaultSchema) {
not at google - send to devlin 2013/03/21 00:01:13 loadTypeSchema? ref -> typeName? (the fact that
cduvall 2013/03/21 00:59:51 Done.
41 // namespace. 42 var parts = ref.split('.');
42 function loadRefDependency(ref, currentApi) { 43 if (parts.length == 1) {
43 var parts = ref.split("."); 44 if (!defaultSchema)
44 if (parts.length > 1) 45 return undefined;
not at google - send to devlin 2013/03/21 00:01:13 CHECK
cduvall 2013/03/21 00:59:51 Done.
45 return chrome[parts.slice(0, parts.length - 1).join(".")]; 46 var types = defaultSchema.types;
46 else 47 } else {
47 return currentApi; 48 var schemaName = parts.slice(0, parts.length - 1).join('.')
49 var types = schemaRegistry.GetSchema(schemaName).types;
50 }
51 for (var i = 0; i < types.length; ++i) {
52 if (types[i]['id'] == ref)
not at google - send to devlin 2013/03/21 00:01:13 .id
cduvall 2013/03/21 00:59:51 Done.
53 return types[i];
54 }
not at google - send to devlin 2013/03/21 00:01:13 return null (nice to be explicit)
cduvall 2013/03/21 00:59:51 returned undefined to be consistent. Is null bette
not at google - send to devlin 2013/03/21 01:36:55 that is always a question with JS. my rule at lea
cduvall 2013/03/21 17:16:07 Done.
48 } 55 }
49 56
50 exports.forEach = forEach; 57 exports.forEach = forEach;
51 exports.loadRefDependency = loadRefDependency; 58 exports.loadRefType = loadRefType;
52 exports.lookup = lookup; 59 exports.lookup = lookup;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698