| 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 sym = JS('', 'Symbol("dartx." + #.toString())', name); | 273 sym = JS('', 'Symbol("dartx." + #.toString())', name); |
| 274 JS('', 'dartx[#] = #', name, sym); | 274 JS('', 'dartx[#] = #', name, sym); |
| 275 } | 275 } |
| 276 return sym; | 276 return sym; |
| 277 } | 277 } |
| 278 | 278 |
| 279 defineExtensionNames(names) => | 279 defineExtensionNames(names) => |
| 280 JS('', '#.forEach(#)', names, getExtensionSymbol); | 280 JS('', '#.forEach(#)', names, getExtensionSymbol); |
| 281 | 281 |
| 282 | 282 |
| 283 /// A map from peer class prototypes to the Dart class prototype. This is used | |
| 284 /// to recognize when Dart subclass inheritance corresponds to JavaScript | |
| 285 /// prototype inheritance. | |
| 286 final _installedDartPeers = JS('', 'new Map()'); | |
| 287 | |
| 288 /// Install properties in prototype-first order. Properties / descriptors from | 283 /// Install properties in prototype-first order. Properties / descriptors from |
| 289 /// more specific types should overwrite ones from less specific types. | 284 /// more specific types should overwrite ones from less specific types. |
| 290 void _installProperties(jsProto, extProto) { | 285 void _installProperties(jsProto, extProto) { |
| 291 | 286 |
| 292 // This relies on the Dart type literal evaluating to the JavaScript | 287 // This relies on the Dart type literal evaluating to the JavaScript |
| 293 // constructor. | 288 // constructor. |
| 294 var coreObjProto = JS('', '#.prototype', Object); | 289 var coreObjProto = JS('', '#.prototype', Object); |
| 295 | 290 |
| 291 var parentsExtension = |
| 292 JS('', '(#.__proto__)[#]', jsProto, _extensionType); |
| 296 var installedParent = | 293 var installedParent = |
| 297 JS('', '#.get(#.__proto__)', _installedDartPeers, jsProto); | 294 JS('', '# && #.prototype', parentsExtension, parentsExtension); |
| 298 | 295 |
| 299 _installProperties2(jsProto, extProto, coreObjProto, installedParent); | 296 _installProperties2(jsProto, extProto, coreObjProto, installedParent); |
| 300 | |
| 301 // Mark this jsProto as being the prototype for the extension class. | |
| 302 JS('', '#.set(#, #)', _installedDartPeers, jsProto, extProto); | |
| 303 } | 297 } |
| 304 | 298 |
| 305 void _installProperties2(jsProto, extProto, coreObjProto, installedParent) { | 299 void _installProperties2(jsProto, extProto, coreObjProto, installedParent) { |
| 306 if (JS('bool', '# === #', extProto, coreObjProto)) { | 300 if (JS('bool', '# === #', extProto, coreObjProto)) { |
| 307 _installPropertiesForObject(jsProto, coreObjProto); | 301 _installPropertiesForObject(jsProto, coreObjProto); |
| 308 return; | 302 return; |
| 309 } | 303 } |
| 310 if (JS('bool', '# !== #', jsProto, extProto)) { | 304 if (JS('bool', '# !== #', jsProto, extProto)) { |
| 311 var extParent = JS('', '#.__proto__', extProto); | 305 var extParent = JS('', '#.__proto__', extProto); |
| 312 | 306 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 })()'''); | 415 })()'''); |
| 422 | 416 |
| 423 /// Sets the element type of a list literal. | 417 /// Sets the element type of a list literal. |
| 424 list(obj, elementType) => | 418 list(obj, elementType) => |
| 425 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); | 419 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); |
| 426 | 420 |
| 427 setBaseClass(derived, base) => JS('', '''(() => { | 421 setBaseClass(derived, base) => JS('', '''(() => { |
| 428 // Link the extension to the type it's extending as a base class. | 422 // Link the extension to the type it's extending as a base class. |
| 429 $derived.prototype.__proto__ = $base.prototype; | 423 $derived.prototype.__proto__ = $base.prototype; |
| 430 })()'''); | 424 })()'''); |
| OLD | NEW |