| OLD | NEW |
| 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'); |
| 7 var CHECK = requireNative('logging').CHECK; |
| 6 | 8 |
| 7 function forEach(obj, f, self) { | 9 function forEach(obj, f, self) { |
| 8 // For arrays, make sure the indices are numbers not strings - and in that | 10 // 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. | 11 // case this method can be more efficient by assuming the array isn't sparse. |
| 10 // | 12 // |
| 11 // Note: not (instanceof Array) because the array might come from a different | 13 // Note: not (instanceof Array) because the array might come from a different |
| 12 // context than our own. | 14 // context than our own. |
| 13 if (obj.constructor && obj.constructor.name == 'Array') { | 15 if (obj.constructor && obj.constructor.name == 'Array') { |
| 14 for (var i = 0; i < obj.length; i++) | 16 for (var i = 0; i < obj.length; i++) |
| 15 f.call(self, i, obj[i]); | 17 f.call(self, i, obj[i]); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 30 if (matches.length == 0) { | 32 if (matches.length == 0) { |
| 31 return undefined; | 33 return undefined; |
| 32 } else if (matches.length == 1) { | 34 } else if (matches.length == 1) { |
| 33 return matches[0] | 35 return matches[0] |
| 34 } else { | 36 } else { |
| 35 throw new Error("Failed lookup of field '" + field + "' with value '" + | 37 throw new Error("Failed lookup of field '" + field + "' with value '" + |
| 36 value + "'"); | 38 value + "'"); |
| 37 } | 39 } |
| 38 } | 40 } |
| 39 | 41 |
| 40 // Specify |currentApi| if this should return an API for $refs in the current | 42 function loadTypeSchema(typeName, defaultSchema) { |
| 41 // namespace. | 43 var parts = typeName.split('.'); |
| 42 function loadRefDependency(ref, currentApi) { | 44 if (parts.length == 1) { |
| 43 var parts = ref.split("."); | 45 CHECK(defaultSchema, 'Trying to reference "' + typeName + |
| 44 if (parts.length > 1) | 46 '" with neither namespace nor default schema.'); |
| 45 return chrome[parts.slice(0, parts.length - 1).join(".")]; | 47 var types = defaultSchema.types; |
| 46 else | 48 } else { |
| 47 return currentApi; | 49 var schemaName = parts.slice(0, parts.length - 1).join('.') |
| 50 var types = schemaRegistry.GetSchema(schemaName).types; |
| 51 } |
| 52 for (var i = 0; i < types.length; ++i) { |
| 53 if (types[i].id == typeName) |
| 54 return types[i]; |
| 55 } |
| 56 return null; |
| 48 } | 57 } |
| 49 | 58 |
| 50 exports.forEach = forEach; | 59 exports.forEach = forEach; |
| 51 exports.loadRefDependency = loadRefDependency; | 60 exports.loadTypeSchema = loadTypeSchema; |
| 52 exports.lookup = lookup; | 61 exports.lookup = lookup; |
| OLD | NEW |