| 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'); | 6 var schemaRegistry = requireNative('schema_registry'); |
| 7 var CHECK = requireNative('logging').CHECK; | 7 var CHECK = requireNative('logging').CHECK; |
| 8 var DCHECK = requireNative('logging').DCHECK; | 8 var DCHECK = requireNative('logging').DCHECK; |
| 9 var WARNING = requireNative('logging').WARNING; | 9 var WARNING = requireNative('logging').WARNING; |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 var types = schemaRegistry.GetSchema(schemaName).types; | 57 var types = schemaRegistry.GetSchema(schemaName).types; |
| 58 } | 58 } |
| 59 for (var i = 0; i < types.length; ++i) { | 59 for (var i = 0; i < types.length; ++i) { |
| 60 if (types[i].id == typeName) | 60 if (types[i].id == typeName) |
| 61 return types[i]; | 61 return types[i]; |
| 62 } | 62 } |
| 63 return null; | 63 return null; |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Sets a property |value| on |obj| with property name |key|. Like |
| 68 * |
| 69 * obj[key] = value; |
| 70 * |
| 71 * but without triggering setters. |
| 72 */ |
| 73 function defineProperty(obj, key, value) { |
| 74 $Object.defineProperty(obj, key, { |
| 75 __proto__: null, |
| 76 configurable: true, |
| 77 enumerable: true, |
| 78 writable: true, |
| 79 value: value, |
| 80 }); |
| 81 } |
| 82 |
| 83 /** |
| 67 * Takes a private class implementation |privateClass| and exposes a subset of | 84 * Takes a private class implementation |privateClass| and exposes a subset of |
| 68 * its methods |functions| and properties |properties| and |readonly| to a | 85 * its methods |functions| and properties |properties| and |readonly| to a |
| 69 * public wrapper class that should be passed in. Within bindings code, you can | 86 * public wrapper class that should be passed in. Within bindings code, you can |
| 70 * access the implementation from an instance of the wrapper class using | 87 * access the implementation from an instance of the wrapper class using |
| 71 * privates(instance).impl, and from the implementation class you can access | 88 * privates(instance).impl, and from the implementation class you can access |
| 72 * the wrapper using this.wrapper (or implInstance.wrapper if you have another | 89 * the wrapper using this.wrapper (or implInstance.wrapper if you have another |
| 73 * instance of the implementation class). | 90 * instance of the implementation class). |
| 74 * | 91 * |
| 75 * |publicClass| should be a constructor that calls constructPrivate() like so: | 92 * |publicClass| should be a constructor that calls constructPrivate() like so: |
| 76 * | 93 * |
| 77 * privates(publicClass).constructPrivate(this, arguments); | 94 * privates(publicClass).constructPrivate(this, arguments); |
| 78 * | 95 * |
| 79 * @param {function} publicClass The publicly exposed wrapper class. This must | 96 * @param {function} publicClass The publicly exposed wrapper class. This must |
| 80 * be a named function, and the name appears in stack traces. | 97 * be a named function, and the name appears in stack traces. |
| 81 * @param {Object} privateClass The class implementation. | 98 * @param {Object} privateClass The class implementation. |
| 82 * @param {{superclass: ?Function, | 99 * @param {{superclass: ?Function, |
| 83 * functions: ?Array<string>, | 100 * functions: ?Array<string>, |
| 84 * properties: ?Array<string>, | 101 * properties: ?Array<string>, |
| 85 * readonly: ?Array<string>}} exposed The names of properties on the | 102 * readonly: ?Array<string>}} exposed The names of properties on the |
| 86 * implementation class to be exposed. |superclass| represents the | 103 * implementation class to be exposed. |superclass| represents the |
| 87 * constructor of the class to be used as the superclass of the exposed | 104 * constructor of the class to be used as the superclass of the exposed |
| 88 * class; |functions| represents the names of functions which should be | 105 * class; |functions| represents the names of functions which should be |
| 89 * delegated to the implementation; |properties| are gettable/settable | 106 * delegated to the implementation; |properties| are gettable/settable |
| 90 * properties and |readonly| are read-only properties. | 107 * properties and |readonly| are read-only properties. |
| 91 */ | 108 */ |
| 92 function expose(publicClass, privateClass, exposed) { | 109 function expose(publicClass, privateClass, exposed) { |
| 93 // TODO(robwu): Fix callers and uncomment this assertion. | 110 DCHECK(!(privateClass.prototype instanceof $Object.self)); |
| 94 // DCHECK(!(privateClass instanceof $Object.self)); | |
| 95 | 111 |
| 96 $Object.setPrototypeOf(exposed, null); | 112 $Object.setPrototypeOf(exposed, null); |
| 97 | 113 |
| 98 // This should be called by publicClass. | 114 // This should be called by publicClass. |
| 99 privates(publicClass).constructPrivate = function(self, args) { | 115 privates(publicClass).constructPrivate = function(self, args) { |
| 100 if (!(self instanceof publicClass)) { | 116 if (!(self instanceof publicClass)) { |
| 101 throw new Error('Please use "new ' + publicClass.name + '"'); | 117 throw new Error('Please use "new ' + publicClass.name + '"'); |
| 102 } | 118 } |
| 103 // The "instanceof publicClass" check can easily be spoofed, so we check | 119 // The "instanceof publicClass" check can easily be spoofed, so we check |
| 104 // whether the private impl is already set before continuing. | 120 // whether the private impl is already set before continuing. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 else | 227 else |
| 212 resolve($Array.slice(arguments)); | 228 resolve($Array.slice(arguments)); |
| 213 }); | 229 }); |
| 214 $Function.apply(func, null, args); | 230 $Function.apply(func, null, args); |
| 215 }); | 231 }); |
| 216 } | 232 } |
| 217 | 233 |
| 218 exports.$set('forEach', forEach); | 234 exports.$set('forEach', forEach); |
| 219 exports.$set('loadTypeSchema', loadTypeSchema); | 235 exports.$set('loadTypeSchema', loadTypeSchema); |
| 220 exports.$set('lookup', lookup); | 236 exports.$set('lookup', lookup); |
| 237 exports.$set('defineProperty', defineProperty); |
| 221 exports.$set('expose', expose); | 238 exports.$set('expose', expose); |
| 222 exports.$set('deepCopy', deepCopy); | 239 exports.$set('deepCopy', deepCopy); |
| 223 exports.$set('promise', promise); | 240 exports.$set('promise', promise); |
| OLD | NEW |