| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 413 |
| 414 if ($obj != null && $obj[$_extensionType]) return $dartx[$name]; | 414 if ($obj != null && $obj[$_extensionType]) return $dartx[$name]; |
| 415 // Check for certain names that we can't use in JS | 415 // Check for certain names that we can't use in JS |
| 416 if ($name == 'constructor' || $name == 'prototype') { | 416 if ($name == 'constructor' || $name == 'prototype') { |
| 417 $name = '+' + $name; | 417 $name = '+' + $name; |
| 418 } | 418 } |
| 419 return $name; | 419 return $name; |
| 420 })()'''); | 420 })()'''); |
| 421 | 421 |
| 422 /// Sets the type of `obj` to be `type` | 422 /// Sets the type of `obj` to be `type` |
| 423 setType(obj, type) => JS('', '''(() => { | 423 setType(obj, type) { |
| 424 $obj.__proto__ = $type.prototype; | 424 JS('', '#.__proto__ = #.prototype', obj, type); |
| 425 // TODO(vsm): This should be set in registerExtension, but that is only | 425 return obj; |
| 426 // invoked on the generic type (e.g., JSArray<dynamic>, not JSArray<int>). | 426 } |
| 427 $obj.__proto__[$_extensionType] = $type; | |
| 428 return $obj; | |
| 429 })()'''); | |
| 430 | 427 |
| 431 /// Sets the element type of a list literal. | 428 /// Sets the element type of a list literal. |
| 432 list(obj, elementType) => | 429 list(obj, elementType) => |
| 433 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); | 430 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); |
| 434 | 431 |
| 435 setBaseClass(derived, base) => JS('', '''(() => { | 432 /// Link the extension to the type it's extending as a base class. |
| 436 // Link the extension to the type it's extending as a base class. | 433 setBaseClass(derived, base) { |
| 437 $derived.prototype.__proto__ = $base.prototype; | 434 JS('', '#.prototype.__proto__ = #.prototype', derived, base); |
| 438 })()'''); | 435 } |
| 436 |
| 437 /// Like [setBaseClass] but for generic extension types, e.g. `JSArray<E>` |
| 438 setExtensionBaseClass(derived, base) { |
| 439 // Mark the generic type as an extension type. |
| 440 JS('', '#.prototype[#] = #', derived, _extensionType, derived); |
| 441 setBaseClass(derived, base); |
| 442 } |
| OLD | NEW |