OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /* This library defines the operations that define and manipulate Dart | 5 /* This library defines the operations that define and manipulate Dart |
6 * classes. Included in this are: | 6 * classes. Included in this are: |
7 * - Generics | 7 * - Generics |
8 * - Class metadata | 8 * - Class metadata |
9 * - Extension methods | 9 * - Extension methods |
10 */ | 10 */ |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 if (sigCtor === void 0) return void 0; | 185 if (sigCtor === void 0) return void 0; |
186 let parts = sigCtor[name]; | 186 let parts = sigCtor[name]; |
187 if (parts === void 0) return void 0; | 187 if (parts === void 0) return void 0; |
188 return types.definiteFunctionType.apply(null, parts); | 188 return types.definiteFunctionType.apply(null, parts); |
189 } | 189 } |
190 exports.classGetConstructorType = _getConstructorType; | 190 exports.classGetConstructorType = _getConstructorType; |
191 | 191 |
192 /// Given an object and a method name, tear off the method. | 192 /// Given an object and a method name, tear off the method. |
193 /// Sets the runtime type of the torn off method appropriately, | 193 /// Sets the runtime type of the torn off method appropriately, |
194 /// and also binds the object. | 194 /// and also binds the object. |
| 195 /// |
| 196 /// If the optional `f` argument is passed in, it will be used as the method. |
| 197 /// This supports cases like `super.foo` where we need to tear off the method |
| 198 /// from the superclass, not from the `obj` directly. |
195 /// TODO(leafp): Consider caching the tearoff on the object? | 199 /// TODO(leafp): Consider caching the tearoff on the object? |
196 function bind(obj, name) { | 200 function bind(obj, name, f) { |
197 let f = obj[name].bind(obj); | 201 if (f === void 0) f = obj[name]; |
| 202 f = f.bind(obj); |
| 203 // TODO(jmesserly): track the function's signature on the function, instead |
| 204 // of having to go back to the class? |
198 let sig = _getMethodType(obj, name); | 205 let sig = _getMethodType(obj, name); |
199 assert(sig); | 206 assert(sig); |
200 rtti.tag(f, sig); | 207 rtti.tag(f, sig); |
201 return f; | 208 return f; |
202 } | 209 } |
203 exports.bind = bind; | 210 exports.bind = bind; |
204 | 211 |
205 // Set up the method signature field on the constructor | 212 // Set up the method signature field on the constructor |
206 function _setMethodSignature(f, sigF) { | 213 function _setMethodSignature(f, sigF) { |
207 defineMemoizedGetter(f, _methodSig, () => { | 214 defineMemoizedGetter(f, _methodSig, () => { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 409 } |
403 exports.list = list; | 410 exports.list = list; |
404 | 411 |
405 function setBaseClass(derived, base) { | 412 function setBaseClass(derived, base) { |
406 // Link the extension to the type it's extending as a base class. | 413 // Link the extension to the type it's extending as a base class. |
407 derived.prototype.__proto__ = base.prototype; | 414 derived.prototype.__proto__ = base.prototype; |
408 } | 415 } |
409 exports.setBaseClass = setBaseClass; | 416 exports.setBaseClass = setBaseClass; |
410 | 417 |
411 }); | 418 }); |
OLD | NEW |