| 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 schemaRegistry = requireNative('schema_registry'); | 5 var schemaRegistry = requireNative('schema_registry'); |
| 6 var CHECK = requireNative('logging').CHECK; | 6 var CHECK = requireNative('logging').CHECK; |
| 7 var WARNING = requireNative('logging').WARNING; | 7 var WARNING = requireNative('logging').WARNING; |
| 8 | 8 |
| 9 // 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 |
| 10 // |self| as the target. | 10 // |self| as the target. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 var types = schemaRegistry.GetSchema(schemaName).types; | 45 var types = schemaRegistry.GetSchema(schemaName).types; |
| 46 } | 46 } |
| 47 for (var i = 0; i < types.length; ++i) { | 47 for (var i = 0; i < types.length; ++i) { |
| 48 if (types[i].id == typeName) | 48 if (types[i].id == typeName) |
| 49 return types[i]; | 49 return types[i]; |
| 50 } | 50 } |
| 51 return null; | 51 return null; |
| 52 } | 52 } |
| 53 | 53 |
| 54 // expose takes a private class implementation |cls| and exposes a subset of its | 54 // expose takes a private class implementation |cls| and exposes a subset of its |
| 55 // methods |funcs| in a public wrapper class that it returns. | 55 // methods |funcs| and properties |props| in a public wrapper class that it |
| 56 function expose(cls, funcs) { | 56 // returns. |
| 57 function expose(cls, funcs, props) { |
| 57 function publicClass() { | 58 function publicClass() { |
| 58 var privateObj = $Object.create(cls.prototype); | 59 var privateObj = $Object.create(cls.prototype); |
| 59 $Function.apply(cls, privateObj, arguments); | 60 $Function.apply(cls, privateObj, arguments); |
| 60 privateObj.wrapper = this; | 61 privateObj.wrapper = this; |
| 61 privates(this).impl = privateObj; | 62 privates(this).impl = privateObj; |
| 62 } | 63 } |
| 63 | 64 |
| 64 $Array.forEach(funcs, function(func) { | 65 if (funcs) { |
| 65 publicClass.prototype[func] = function() { | 66 $Array.forEach(funcs, function(func) { |
| 66 var impl = privates(this).impl; | 67 publicClass.prototype[func] = function() { |
| 67 return $Function.apply(impl[func], impl, arguments); | 68 var impl = privates(this).impl; |
| 68 }; | 69 return $Function.apply(impl[func], impl, arguments); |
| 69 }); | 70 }; |
| 71 }); |
| 72 } |
| 73 |
| 74 if (props) { |
| 75 $Array.forEach(props, function(prop) { |
| 76 $Object.defineProperty(publicClass.prototype, prop, { |
| 77 enumerable: true, |
| 78 get: function() { |
| 79 return privates(this).impl[prop]; |
| 80 }, |
| 81 set: function(value) { |
| 82 var impl = privates(this).impl; |
| 83 delete impl[prop]; |
| 84 impl[prop] = value; |
| 85 } |
| 86 }); |
| 87 }); |
| 88 } |
| 70 | 89 |
| 71 return publicClass; | 90 return publicClass; |
| 72 } | 91 } |
| 73 | 92 |
| 74 exports.forEach = forEach; | 93 exports.forEach = forEach; |
| 75 exports.loadTypeSchema = loadTypeSchema; | 94 exports.loadTypeSchema = loadTypeSchema; |
| 76 exports.lookup = lookup; | 95 exports.lookup = lookup; |
| 77 exports.expose = expose; | 96 exports.expose = expose; |
| OLD | NEW |