| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 '', | 269 '', |
| 270 '''(() => { | 270 '''(() => { |
| 271 if(!$name) $name = 'new'; | 271 if(!$name) $name = 'new'; |
| 272 if ($cls === void 0) return void 0; | 272 if ($cls === void 0) return void 0; |
| 273 if ($cls == null) return void 0; | 273 if ($cls == null) return void 0; |
| 274 let sigCtor = $cls[$_constructorSig]; | 274 let sigCtor = $cls[$_constructorSig]; |
| 275 if (sigCtor === void 0) return void 0; | 275 if (sigCtor === void 0) return void 0; |
| 276 return sigCtor[$name]; | 276 return sigCtor[$name]; |
| 277 })()'''); | 277 })()'''); |
| 278 | 278 |
| 279 /// Given an object and a method name, tear off the method. | |
| 280 /// Sets the runtime type of the torn off method appropriately, | |
| 281 /// and also binds the object. | |
| 282 /// | |
| 283 /// If the optional `f` argument is passed in, it will be used as the method. | |
| 284 /// This supports cases like `super.foo` where we need to tear off the method | |
| 285 /// from the superclass, not from the `obj` directly. | |
| 286 /// TODO(leafp): Consider caching the tearoff on the object? | |
| 287 bind(obj, name, f) => JS( | |
| 288 '', | |
| 289 '''(() => { | |
| 290 if ($f === void 0) $f = $obj[$name]; | |
| 291 // TODO(jmesserly): track the function's signature on the function, instead | |
| 292 // of having to go back to the class? | |
| 293 let sig = $getMethodType($getType($obj), $name); | |
| 294 | |
| 295 // JS interop case: do not bind this for compatibility with the dart2js | |
| 296 // implementation where we cannot bind this reliably here until we trust | |
| 297 // types more. | |
| 298 if (sig == null) return $f; | |
| 299 | |
| 300 $f = $f.bind($obj); | |
| 301 $tag($f, sig); | |
| 302 return $f; | |
| 303 })()'''); | |
| 304 | |
| 305 /// Instantiate a generic method. | |
| 306 /// | |
| 307 /// We need to apply the type arguments both to the function, as well as its | |
| 308 /// associated function type. | |
| 309 gbind(f, @rest typeArgs) { | |
| 310 var result = JS('', '#.apply(null, #)', f, typeArgs); | |
| 311 var sig = JS('', '#.instantiate(#)', _getRuntimeType(f), typeArgs); | |
| 312 tag(result, sig); | |
| 313 return result; | |
| 314 } | |
| 315 | |
| 316 // Set up the method signature field on the constructor | 279 // Set up the method signature field on the constructor |
| 317 _setInstanceSignature(f, sigF, kind) => defineMemoizedGetter( | 280 _setInstanceSignature(f, sigF, kind) => defineMemoizedGetter( |
| 318 f, | 281 f, |
| 319 kind, | 282 kind, |
| 320 JS( | 283 JS( |
| 321 '', | 284 '', |
| 322 '''() => { | 285 '''() => { |
| 323 let sigObj = #(); | 286 let sigObj = #(); |
| 324 let proto = #.__proto__; | 287 let proto = #.__proto__; |
| 325 // We need to set the root proto to null not undefined. | 288 // We need to set the root proto to null not undefined. |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 '''(() => { | 633 '''(() => { |
| 671 let values = []; | 634 let values = []; |
| 672 for (var i = 0; i < $names.length; i++) { | 635 for (var i = 0; i < $names.length; i++) { |
| 673 let value = $const_(new $enumClass(i)); | 636 let value = $const_(new $enumClass(i)); |
| 674 values.push(value); | 637 values.push(value); |
| 675 Object.defineProperty($enumClass, $names[i], | 638 Object.defineProperty($enumClass, $names[i], |
| 676 { value: value, configurable: true }); | 639 { value: value, configurable: true }); |
| 677 } | 640 } |
| 678 $enumClass.values = $constList(values, $enumClass); | 641 $enumClass.values = $constList(values, $enumClass); |
| 679 })()'''); | 642 })()'''); |
| OLD | NEW |