| 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; | 5 var dart; |
| 6 (function (dart) { | 6 (function (dart) { |
| 7 var defineProperty = Object.defineProperty; | 7 var defineProperty = Object.defineProperty; |
| 8 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | 8 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 9 var getOwnPropertyNames = Object.getOwnPropertyNames; | 9 var getOwnPropertyNames = Object.getOwnPropertyNames; |
| 10 | 10 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 * previous entries. | 193 * previous entries. |
| 194 * | 194 * |
| 195 * For each mixin, we only take its own properties, not anything from its | 195 * For each mixin, we only take its own properties, not anything from its |
| 196 * superclass (prototype). | 196 * superclass (prototype). |
| 197 */ | 197 */ |
| 198 function mixin(base/*, ...mixins*/) { | 198 function mixin(base/*, ...mixins*/) { |
| 199 // Inherit statics from Base to simulate ES6 class inheritance | 199 // Inherit statics from Base to simulate ES6 class inheritance |
| 200 // Conceptually this is: `class Mixin extends base {}` | 200 // Conceptually this is: `class Mixin extends base {}` |
| 201 function Mixin() { | 201 function Mixin() { |
| 202 // TODO(jmesserly): since we're using initializers and not constructors, | 202 // TODO(jmesserly): since we're using initializers and not constructors, |
| 203 // we can just skip directly to dart.Object. | 203 // we can just skip directly to core.Object. |
| 204 dart.Object.apply(this, arguments); | 204 core.Object.apply(this, arguments); |
| 205 } | 205 } |
| 206 Mixin.__proto__ = base; | 206 Mixin.__proto__ = base; |
| 207 Mixin.prototype = Object.create(base.prototype); | 207 Mixin.prototype = Object.create(base.prototype); |
| 208 Mixin.prototype.constructor = Mixin; | 208 Mixin.prototype.constructor = Mixin; |
| 209 // Copy each mixin, with later ones overwriting earlier entries. | 209 // Copy each mixin, with later ones overwriting earlier entries. |
| 210 var mixins = Array.prototype.slice.call(arguments, 1); | 210 var mixins = Array.prototype.slice.call(arguments, 1); |
| 211 for (var i = 0; i < mixins.length; i++) { | 211 for (var i = 0; i < mixins.length; i++) { |
| 212 copyProperties(Mixin.prototype, mixins[i].prototype); | 212 copyProperties(Mixin.prototype, mixins[i].prototype); |
| 213 } | 213 } |
| 214 // Create an initializer for the mixin, so when derived constructor calls | 214 // Create an initializer for the mixin, so when derived constructor calls |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 /** | 334 /** |
| 335 * Implements Dart constructor behavior. Because of V8 `super` [constructor | 335 * Implements Dart constructor behavior. Because of V8 `super` [constructor |
| 336 * restrictions](https://code.google.com/p/v8/issues/detail?id=3330#c65) we | 336 * restrictions](https://code.google.com/p/v8/issues/detail?id=3330#c65) we |
| 337 * cannot currently emit actual ES6 constructors with super calls. Instead | 337 * cannot currently emit actual ES6 constructors with super calls. Instead |
| 338 * we use the same trick as named constructors, and do them as instance | 338 * we use the same trick as named constructors, and do them as instance |
| 339 * methods that perform initialization. | 339 * methods that perform initialization. |
| 340 */ | 340 */ |
| 341 // TODO(jmesserly): we'll need to rethink this once the ES6 spec and V8 | 341 // TODO(jmesserly): we'll need to rethink this once the ES6 spec and V8 |
| 342 // settles. See <https://github.com/dart-lang/dart-dev-compiler/issues/51>. | 342 // settles. See <https://github.com/dart-lang/dart-dev-compiler/issues/51>. |
| 343 // Performance of this pattern is likely to be bad. | 343 // Performance of this pattern is likely to be bad. |
| 344 dart.Object = function Object() { | 344 core.Object = function Object() { |
| 345 // Get the class name for this instance. | 345 // Get the class name for this instance. |
| 346 var name = this.constructor.name; | 346 var name = this.constructor.name; |
| 347 // Call the default constructor. | 347 // Call the default constructor. |
| 348 var init = this[name]; | 348 var init = this[name]; |
| 349 var result = void 0; | 349 var result = void 0; |
| 350 if (init) result = init.apply(this, arguments); | 350 if (init) result = init.apply(this, arguments); |
| 351 return result === void 0 ? this : result; | 351 return result === void 0 ? this : result; |
| 352 }; | 352 }; |
| 353 // The initializer for dart.Object | 353 // The initializer for Object |
| 354 dart.Object.prototype.Object = function() {}; | 354 core.Object.prototype.Object = function() {}; |
| 355 dart.Object.prototype.constructor = dart.Object; | 355 core.Object.prototype.constructor = core.Object; |
| 356 | 356 |
| 357 })(dart || (dart = {})); | 357 })(dart || (dart = {})); |
| OLD | NEW |