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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 494 |
495 /// Link the extension to the type it's extending as a base class. | 495 /// Link the extension to the type it's extending as a base class. |
496 setBaseClass(derived, base) { | 496 setBaseClass(derived, base) { |
497 JS('', '#.prototype.__proto__ = #.prototype', derived, base); | 497 JS('', '#.prototype.__proto__ = #.prototype', derived, base); |
498 // We use __proto__ to track the superclass hierarchy (see isSubtype). | 498 // We use __proto__ to track the superclass hierarchy (see isSubtype). |
499 JS('', '#.__proto__ = #', derived, base); | 499 JS('', '#.__proto__ = #', derived, base); |
500 } | 500 } |
501 | 501 |
502 /// Like [setBaseClass] but for generic extension types, e.g. `JSArray<E>` | 502 /// Like [setBaseClass] but for generic extension types, e.g. `JSArray<E>` |
503 setExtensionBaseClass(derived, base) { | 503 setExtensionBaseClass(derived, base) { |
504 // Mark the generic type as an extension type. | 504 // Mark the generic type as an extension type and link the prototype objects |
505 JS('', '#.prototype[#] = #', derived, _extensionType, derived); | 505 return JS('', '''(() => { |
506 // Link the prototype objects | 506 if ($base) { |
507 JS('', '#.prototype.__proto__ = #.prototype', derived, base); | 507 $derived.prototype[$_extensionType] = $derived; |
| 508 $derived.prototype.__proto__ = $base.prototype |
| 509 } |
| 510 })()'''); |
508 } | 511 } |
509 | 512 |
510 /// Given a special constructor function that creates a function instances, | 513 /// Given a special constructor function that creates a function instances, |
511 /// and a class with a `call` method, merge them so the constructor function | 514 /// and a class with a `call` method, merge them so the constructor function |
512 /// will have the correct methods and prototype. | 515 /// will have the correct methods and prototype. |
513 /// | 516 /// |
514 /// For example: | 517 /// For example: |
515 /// | 518 /// |
516 /// lib.Foo = dart.callableClass( | 519 /// lib.Foo = dart.callableClass( |
517 /// function Foo { function call(...args) { ... } ... return call; }, | 520 /// function Foo { function call(...args) { ... } ... return call; }, |
(...skipping 17 matching lines...) Expand all Loading... |
535 /// | 538 /// |
536 /// The constructor | 539 /// The constructor |
537 defineNamedConstructorCallable(clazz, name, ctor) => JS( | 540 defineNamedConstructorCallable(clazz, name, ctor) => JS( |
538 '', | 541 '', |
539 '''(() => { | 542 '''(() => { |
540 ctor.prototype = $clazz.prototype; | 543 ctor.prototype = $clazz.prototype; |
541 // Use defineProperty so we don't hit a property defined on Function, | 544 // Use defineProperty so we don't hit a property defined on Function, |
542 // like `caller` and `arguments`. | 545 // like `caller` and `arguments`. |
543 $defineProperty($clazz, $name, { value: ctor, configurable: true }); | 546 $defineProperty($clazz, $name, { value: ctor, configurable: true }); |
544 })()'''); | 547 })()'''); |
OLD | NEW |