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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // TODO(jmesserly): essentially this gives two names to the same method. | 452 // TODO(jmesserly): essentially this gives two names to the same method. |
453 // This benefit is roughly equivalent call performance either way, but the | 453 // This benefit is roughly equivalent call performance either way, but the |
454 // cost is we need to call defineExtensionMembers any time a subclass | 454 // cost is we need to call defineExtensionMembers any time a subclass |
455 // overrides one of these methods. | 455 // overrides one of these methods. |
456 defineExtensionMembers(type, methodNames) => JS( | 456 defineExtensionMembers(type, methodNames) => JS( |
457 '', | 457 '', |
458 '''(() => { | 458 '''(() => { |
459 let proto = $type.prototype; | 459 let proto = $type.prototype; |
460 for (let name of $methodNames) { | 460 for (let name of $methodNames) { |
461 let method = $getOwnPropertyDescriptor(proto, name); | 461 let method = $getOwnPropertyDescriptor(proto, name); |
462 // TODO(vsm): We should be able to generate code to avoid this case. | |
463 // The method may be null if this type implements a potentially native | |
464 // interface but isn't native itself. For a field on this type, we're not | |
465 // generating a corresponding getter/setter method - it's just a field. | |
466 if (!method) continue; | |
467 $defineProperty(proto, $getExtensionSymbol(name), method); | 462 $defineProperty(proto, $getExtensionSymbol(name), method); |
468 } | 463 } |
469 // Ensure the signature is available too. | 464 // Ensure the signature is available too. |
470 // TODO(jmesserly): not sure if we can do this in a cleaner way. Essentially | 465 // TODO(jmesserly): not sure if we can do this in a cleaner way. Essentially |
471 // we need to copy the signature (and in the future, other data like | 466 // we need to copy the signature (and in the future, other data like |
472 // annotations) any time we copy a method as part of our metaprogramming. | 467 // annotations) any time we copy a method as part of our metaprogramming. |
473 // It might be more friendly to JS metaprogramming if we include this info | 468 // It might be more friendly to JS metaprogramming if we include this info |
474 // on the function. | 469 // on the function. |
475 let originalSigFn = $getOwnPropertyDescriptor($type, $_methodSig).get; | 470 let originalSigFn = $getOwnPropertyDescriptor($type, $_methodSig).get; |
476 $defineMemoizedGetter(type, $_methodSig, function() { | 471 $defineMemoizedGetter(type, $_methodSig, function() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 /// | 533 /// |
539 /// The constructor | 534 /// The constructor |
540 defineNamedConstructorCallable(clazz, name, ctor) => JS( | 535 defineNamedConstructorCallable(clazz, name, ctor) => JS( |
541 '', | 536 '', |
542 '''(() => { | 537 '''(() => { |
543 ctor.prototype = $clazz.prototype; | 538 ctor.prototype = $clazz.prototype; |
544 // Use defineProperty so we don't hit a property defined on Function, | 539 // Use defineProperty so we don't hit a property defined on Function, |
545 // like `caller` and `arguments`. | 540 // like `caller` and `arguments`. |
546 $defineProperty($clazz, $name, { value: ctor, configurable: true }); | 541 $defineProperty($clazz, $name, { value: ctor, configurable: true }); |
547 })()'''); | 542 })()'''); |
OLD | NEW |