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 var dart, _js_helper; | 5 var dart, _js_helper; |
6 (function (dart) { | 6 (function (dart) { |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 let defineProperty = Object.defineProperty; | 9 let defineProperty = Object.defineProperty; |
10 let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | 10 let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 function copyProperties(to, from) { | 590 function copyProperties(to, from) { |
591 let names = getOwnPropertyNames(from); | 591 let names = getOwnPropertyNames(from); |
592 for (let i = 0; i < names.length; i++) { | 592 for (let i = 0; i < names.length; i++) { |
593 let name = names[i]; | 593 let name = names[i]; |
594 defineProperty(to, name, getOwnPropertyDescriptor(from, name)); | 594 defineProperty(to, name, getOwnPropertyDescriptor(from, name)); |
595 } | 595 } |
596 return to; | 596 return to; |
597 } | 597 } |
598 dart.copyProperties = copyProperties; | 598 dart.copyProperties = copyProperties; |
599 | 599 |
| 600 /** |
| 601 * Initialize field `name` on `obj` to `value`. |
| 602 * |
| 603 * We may have getters/setters in our prototype chain, so we can't simply set |
| 604 * `obj.name = value` in all cases. |
| 605 */ |
| 606 function initField(type, obj, name, value) { |
| 607 var prop = getOwnPropertyDescriptor(type.prototype, name); |
| 608 if (prop) { |
| 609 prop.set.call(obj, value); |
| 610 } else { |
| 611 obj[name] = value; |
| 612 } |
| 613 } |
| 614 dart.initField = initField; |
| 615 |
| 616 /** |
| 617 * This is called whenever a derived class needs to introduce a new field, |
| 618 * shadowing a field or getter/setter pair on its parent. |
| 619 * |
| 620 * This is important because otherwise, trying to read or write the field |
| 621 * would end up calling the getter or setter, and one of those might not even |
| 622 * exist, resulting in a runtime error. Even if they did exist, that's the |
| 623 * wrong behavior if a new field was declared. |
| 624 */ |
| 625 function virtualField(subclass, fieldName) { |
| 626 // If the field is already overridden, do nothing. |
| 627 let prop = getOwnPropertyDescriptor(subclass.prototype, fieldName); |
| 628 if (prop) return; |
| 629 |
| 630 let symbol = Symbol(subclass.name + '.' + fieldName); |
| 631 defineProperty(subclass.prototype, fieldName, { |
| 632 get: function() { return this[symbol]; }, |
| 633 set: function(x) { this[symbol] = x; } |
| 634 }); |
| 635 } |
| 636 dart.virtualField = virtualField; |
600 | 637 |
601 /** The Symbol for storing type arguments on a specialized generic type. */ | 638 /** The Symbol for storing type arguments on a specialized generic type. */ |
602 dart.mixins = Symbol('mixins'); | 639 dart.mixins = Symbol('mixins'); |
603 dart.implements = Symbol('implements'); | 640 dart.implements = Symbol('implements'); |
604 | 641 |
605 /** | 642 /** |
606 * Returns a new type that mixes members from base and all mixins. | 643 * Returns a new type that mixes members from base and all mixins. |
607 * | 644 * |
608 * Each mixin applies in sequence, with further to the right ones overriding | 645 * Each mixin applies in sequence, with further to the right ones overriding |
609 * previous entries. | 646 * previous entries. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 // TODO(vsm): How should we encode the runtime type? | 791 // TODO(vsm): How should we encode the runtime type? |
755 dart.runtimeType = Symbol('runtimeType'); | 792 dart.runtimeType = Symbol('runtimeType'); |
756 | 793 |
757 dart.JsSymbol = Symbol; | 794 dart.JsSymbol = Symbol; |
758 | 795 |
759 // TODO(jmesserly): hack to bootstrap the SDK | 796 // TODO(jmesserly): hack to bootstrap the SDK |
760 _js_helper = _js_helper || {}; | 797 _js_helper = _js_helper || {}; |
761 _js_helper.checkNum = notNull; | 798 _js_helper.checkNum = notNull; |
762 | 799 |
763 })(dart || (dart = {})); | 800 })(dart || (dart = {})); |
OLD | NEW |