| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 /// and also binds the object. | 264 /// and also binds the object. |
| 265 /// | 265 /// |
| 266 /// If the optional `f` argument is passed in, it will be used as the method. | 266 /// If the optional `f` argument is passed in, it will be used as the method. |
| 267 /// This supports cases like `super.foo` where we need to tear off the method | 267 /// This supports cases like `super.foo` where we need to tear off the method |
| 268 /// from the superclass, not from the `obj` directly. | 268 /// from the superclass, not from the `obj` directly. |
| 269 /// TODO(leafp): Consider caching the tearoff on the object? | 269 /// TODO(leafp): Consider caching the tearoff on the object? |
| 270 bind(obj, name, f) => JS( | 270 bind(obj, name, f) => JS( |
| 271 '', | 271 '', |
| 272 '''(() => { | 272 '''(() => { |
| 273 if ($f === void 0) $f = $obj[$name]; | 273 if ($f === void 0) $f = $obj[$name]; |
| 274 $f = $f.bind($obj); | |
| 275 // TODO(jmesserly): track the function's signature on the function, instead | 274 // TODO(jmesserly): track the function's signature on the function, instead |
| 276 // of having to go back to the class? | 275 // of having to go back to the class? |
| 277 let sig = $getMethodType($getType($obj), $name); | 276 let sig = $getMethodType($getType($obj), $name); |
| 278 $assert_(sig); | 277 |
| 278 // JS interop case: do not bind this for compatibility with the dart2js |
| 279 // implementation where we cannot bind this reliably here until we trust |
| 280 // types more. |
| 281 if (sig === void 0) return $f; |
| 282 |
| 283 $f = $f.bind($obj); |
| 279 $tag($f, sig); | 284 $tag($f, sig); |
| 280 return $f; | 285 return $f; |
| 281 })()'''); | 286 })()'''); |
| 282 | 287 |
| 283 /// Instantiate a generic method. | 288 /// Instantiate a generic method. |
| 284 /// | 289 /// |
| 285 /// We need to apply the type arguments both to the function, as well as its | 290 /// We need to apply the type arguments both to the function, as well as its |
| 286 /// associated function type. | 291 /// associated function type. |
| 287 gbind(f, @rest typeArgs) { | 292 gbind(f, @rest typeArgs) { |
| 288 var result = JS('', '#.apply(null, #)', f, typeArgs); | 293 var result = JS('', '#.apply(null, #)', f, typeArgs); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 '''(() => { | 643 '''(() => { |
| 639 let values = []; | 644 let values = []; |
| 640 for (var i = 0; i < $names.length; i++) { | 645 for (var i = 0; i < $names.length; i++) { |
| 641 let value = $const_(new $enumClass(i)); | 646 let value = $const_(new $enumClass(i)); |
| 642 values.push(value); | 647 values.push(value); |
| 643 Object.defineProperty($enumClass, $names[i], | 648 Object.defineProperty($enumClass, $names[i], |
| 644 { value: value, configurable: true }); | 649 { value: value, configurable: true }); |
| 645 } | 650 } |
| 646 $enumClass.values = $constList(values, $enumClass); | 651 $enumClass.values = $constList(values, $enumClass); |
| 647 })()'''); | 652 })()'''); |
| OLD | NEW |