| OLD | NEW |
| 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 nativeDeepCopy = requireNative('utils').deepCopy; | 5 var nativeDeepCopy = requireNative('utils').deepCopy; |
| 6 var schemaRegistry = requireNative('schema_registry'); | |
| 7 var CHECK = requireNative('logging').CHECK; | |
| 8 var DCHECK = requireNative('logging').DCHECK; | 6 var DCHECK = requireNative('logging').DCHECK; |
| 9 var WARNING = requireNative('logging').WARNING; | |
| 10 | 7 |
| 11 /** | 8 /** |
| 12 * An object forEach. Calls |f| with each (key, value) pair of |obj|, using | 9 * An object forEach. Calls |f| with each (key, value) pair of |obj|, using |
| 13 * |self| as the target. | 10 * |self| as the target. |
| 14 * @param {Object} obj The object to iterate over. | 11 * @param {Object} obj The object to iterate over. |
| 15 * @param {function} f The function to call in each iteration. | 12 * @param {function} f The function to call in each iteration. |
| 16 * @param {Object} self The object to use as |this| in each function call. | 13 * @param {Object} self The object to use as |this| in each function call. |
| 17 */ | 14 */ |
| 18 function forEach(obj, f, self) { | 15 function forEach(obj, f, self) { |
| 19 for (var key in obj) { | 16 for (var key in obj) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 36 if (matches.length == 0) { | 33 if (matches.length == 0) { |
| 37 return undefined; | 34 return undefined; |
| 38 } else if (matches.length == 1) { | 35 } else if (matches.length == 1) { |
| 39 return matches[0] | 36 return matches[0] |
| 40 } else { | 37 } else { |
| 41 throw new Error("Failed lookup of field '" + field + "' with value '" + | 38 throw new Error("Failed lookup of field '" + field + "' with value '" + |
| 42 value + "'"); | 39 value + "'"); |
| 43 } | 40 } |
| 44 } | 41 } |
| 45 | 42 |
| 46 function loadTypeSchema(typeName, defaultSchema) { | |
| 47 var parts = $String.split(typeName, '.'); | |
| 48 if (parts.length == 1) { | |
| 49 if (defaultSchema == null) { | |
| 50 WARNING('Trying to reference "' + typeName + '" ' + | |
| 51 'with neither namespace nor default schema.'); | |
| 52 return null; | |
| 53 } | |
| 54 var types = defaultSchema.types; | |
| 55 } else { | |
| 56 var schemaName = $Array.join($Array.slice(parts, 0, parts.length - 1), '.'); | |
| 57 var types = schemaRegistry.GetSchema(schemaName).types; | |
| 58 } | |
| 59 for (var i = 0; i < types.length; ++i) { | |
| 60 if (types[i].id == typeName) | |
| 61 return types[i]; | |
| 62 } | |
| 63 return null; | |
| 64 } | |
| 65 | |
| 66 /** | 43 /** |
| 67 * Sets a property |value| on |obj| with property name |key|. Like | 44 * Sets a property |value| on |obj| with property name |key|. Like |
| 68 * | 45 * |
| 69 * obj[key] = value; | 46 * obj[key] = value; |
| 70 * | 47 * |
| 71 * but without triggering setters. | 48 * but without triggering setters. |
| 72 */ | 49 */ |
| 73 function defineProperty(obj, key, value) { | 50 function defineProperty(obj, key, value) { |
| 74 $Object.defineProperty(obj, key, { | 51 $Object.defineProperty(obj, key, { |
| 75 __proto__: null, | 52 __proto__: null, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 if (arguments.length <= 1) | 200 if (arguments.length <= 1) |
| 224 resolve(arguments[0]); | 201 resolve(arguments[0]); |
| 225 else | 202 else |
| 226 resolve($Array.slice(arguments)); | 203 resolve($Array.slice(arguments)); |
| 227 }); | 204 }); |
| 228 $Function.apply(func, null, args); | 205 $Function.apply(func, null, args); |
| 229 }); | 206 }); |
| 230 } | 207 } |
| 231 | 208 |
| 232 exports.$set('forEach', forEach); | 209 exports.$set('forEach', forEach); |
| 233 exports.$set('loadTypeSchema', loadTypeSchema); | |
| 234 exports.$set('lookup', lookup); | 210 exports.$set('lookup', lookup); |
| 235 exports.$set('defineProperty', defineProperty); | 211 exports.$set('defineProperty', defineProperty); |
| 236 exports.$set('expose', expose); | 212 exports.$set('expose', expose); |
| 237 exports.$set('deepCopy', deepCopy); | 213 exports.$set('deepCopy', deepCopy); |
| 238 exports.$set('promise', promise); | 214 exports.$set('promise', promise); |
| OLD | NEW |