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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 } | 524 } |
525 return sig; | 525 return sig; |
526 }); | 526 }); |
527 }; | 527 }; |
528 upgradeSig($_methodSig); | 528 upgradeSig($_methodSig); |
529 upgradeSig($_fieldSig); | 529 upgradeSig($_fieldSig); |
530 upgradeSig($_getterSig); | 530 upgradeSig($_getterSig); |
531 upgradeSig($_setterSig); | 531 upgradeSig($_setterSig); |
532 })()'''); | 532 })()'''); |
533 | 533 |
534 /// Sets the type of `obj` to be `type` | |
535 setType(obj, type) { | |
536 JS('', '#.__proto__ = #.prototype', obj, type); | |
537 return obj; | |
538 } | |
539 | |
540 /// Link the extension to the type it's extending as a base class. | 534 /// Link the extension to the type it's extending as a base class. |
541 setBaseClass(derived, base) { | 535 setBaseClass(derived, base) { |
542 JS('', '#.prototype.__proto__ = #.prototype', derived, base); | 536 JS('', '#.prototype.__proto__ = #.prototype', derived, base); |
543 // We use __proto__ to track the superclass hierarchy (see isSubtype). | 537 // We use __proto__ to track the superclass hierarchy (see isSubtype). |
544 JS('', '#.__proto__ = #', derived, base); | 538 JS('', '#.__proto__ = #', derived, base); |
545 } | 539 } |
546 | 540 |
547 /// Like [setBaseClass], but for generic extension types such as `JSArray<E>`. | 541 /// Like [setBaseClass], but for generic extension types such as `JSArray<E>`. |
548 setExtensionBaseClass(dartType, jsType) { | 542 setExtensionBaseClass(dartType, jsType) { |
549 // Mark the generic type as an extension type and link the prototype objects. | 543 // Mark the generic type as an extension type and link the prototype objects. |
550 var dartProto = JS('', '#.prototype', dartType); | 544 var dartProto = JS('', '#.prototype', dartType); |
551 JS('', '#[#] = #', dartProto, _extensionType, dartType); | 545 JS('', '#[#] = #', dartProto, _extensionType, dartType); |
552 JS('', '#.__proto__ = #.prototype', dartProto, jsType); | 546 JS('', '#.__proto__ = #.prototype', dartProto, jsType); |
553 } | 547 } |
554 | 548 |
555 defineEnumValues(enumClass, names) { | 549 defineEnumValues(enumClass, names) { |
556 var values = []; | 550 var values = []; |
557 for (var i = 0; i < JS('int', '#.length', names); i++) { | 551 for (var i = 0; i < JS('int', '#.length', names); i++) { |
558 var value = const_(JS('', 'new #.new(#)', enumClass, i)); | 552 var value = const_(JS('', 'new #.new(#)', enumClass, i)); |
559 JS('', '#.push(#)', values, value); | 553 JS('', '#.push(#)', values, value); |
560 defineValue(enumClass, JS('', '#[#]', names, i), value); | 554 defineValue(enumClass, JS('', '#[#]', names, i), value); |
561 } | 555 } |
562 JS('', '#.values = #', enumClass, constList(values, enumClass)); | 556 JS('', '#.values = #', enumClass, constList(values, enumClass)); |
563 } | 557 } |
OLD | NEW |