| 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 * This is called whenever a derived class needs to introduce a new field, |
| 602 * shadowing a field or getter/setter pair on its parent. |
| 603 * |
| 604 * This is important because otherwise, trying to read or write the field |
| 605 * would end up calling the getter or setter, and one of those might not even |
| 606 * exist, resulting in a runtime error. Even if they did exist, that's the |
| 607 * wrong behavior if a new field was declared. |
| 608 */ |
| 609 function virtualField(subclass, fieldName) { |
| 610 // If the field is already overridden, do nothing. |
| 611 let prop = getOwnPropertyDescriptor(subclass.prototype, fieldName); |
| 612 if (prop) return; |
| 613 |
| 614 let symbol = Symbol(subclass.name + '.' + fieldName); |
| 615 defineProperty(subclass.prototype, fieldName, { |
| 616 get: function() { return this[symbol]; }, |
| 617 set: function(x) { this[symbol] = x; } |
| 618 }); |
| 619 } |
| 620 dart.virtualField = virtualField; |
| 600 | 621 |
| 601 /** The Symbol for storing type arguments on a specialized generic type. */ | 622 /** The Symbol for storing type arguments on a specialized generic type. */ |
| 602 dart.mixins = Symbol('mixins'); | 623 dart.mixins = Symbol('mixins'); |
| 603 dart.implements = Symbol('implements'); | 624 dart.implements = Symbol('implements'); |
| 604 | 625 |
| 605 /** | 626 /** |
| 606 * Returns a new type that mixes members from base and all mixins. | 627 * Returns a new type that mixes members from base and all mixins. |
| 607 * | 628 * |
| 608 * Each mixin applies in sequence, with further to the right ones overriding | 629 * Each mixin applies in sequence, with further to the right ones overriding |
| 609 * previous entries. | 630 * 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? | 775 // TODO(vsm): How should we encode the runtime type? |
| 755 dart.runtimeType = Symbol('runtimeType'); | 776 dart.runtimeType = Symbol('runtimeType'); |
| 756 | 777 |
| 757 dart.JsSymbol = Symbol; | 778 dart.JsSymbol = Symbol; |
| 758 | 779 |
| 759 // TODO(jmesserly): hack to bootstrap the SDK | 780 // TODO(jmesserly): hack to bootstrap the SDK |
| 760 _js_helper = _js_helper || {}; | 781 _js_helper = _js_helper || {}; |
| 761 _js_helper.checkNum = notNull; | 782 _js_helper.checkNum = notNull; |
| 762 | 783 |
| 763 })(dart || (dart = {})); | 784 })(dart || (dart = {})); |
| OLD | NEW |