| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 277 } |
| 278 | 278 |
| 279 defineExtensionNames(names) => | 279 defineExtensionNames(names) => |
| 280 JS('', '#.forEach(#)', names, getExtensionSymbol); | 280 JS('', '#.forEach(#)', names, getExtensionSymbol); |
| 281 | 281 |
| 282 // Install properties in prototype order. Properties / descriptors from | 282 // Install properties in prototype order. Properties / descriptors from |
| 283 // more specific types should overwrite ones from less specific types. | 283 // more specific types should overwrite ones from less specific types. |
| 284 _installProperties(jsProto, extProto) { | 284 _installProperties(jsProto, extProto) { |
| 285 var coreObjProto = JS('', '#.prototype', Object); | 285 var coreObjProto = JS('', '#.prototype', Object); |
| 286 if (JS('bool', '# === #', extProto, coreObjProto)) { | 286 if (JS('bool', '# === #', extProto, coreObjProto)) { |
| 287 // core.Object members need to be copied from the non-symbol name to the | 287 // core.Object members need to be copied from the non-symbol name to the |
| 288 // symbol name. | 288 // symbol name. |
| 289 for (var name in getOwnPropertyNames(coreObjProto)) { | 289 var names = getOwnPropertyNames(coreObjProto); |
| 290 for (int i = 0; i < JS('int', '#.length', names); ++i) { |
| 291 var name = JS('', '#[#]', names, i); |
| 290 var desc = getOwnPropertyDescriptor(coreObjProto, name); | 292 var desc = getOwnPropertyDescriptor(coreObjProto, name); |
| 291 defineProperty(jsProto, getExtensionSymbol(name), desc); | 293 defineProperty(jsProto, getExtensionSymbol(name), desc); |
| 292 } | 294 } |
| 293 return; | 295 return; |
| 294 } | 296 } |
| 295 if (JS('bool', '# !== #', jsProto, extProto)) { | 297 if (JS('bool', '# !== #', jsProto, extProto)) { |
| 296 _installProperties(jsProto, JS('', '#.__proto__', extProto)); | 298 _installProperties(jsProto, JS('', '#.__proto__', extProto)); |
| 297 } | 299 } |
| 298 copyTheseProperties(jsProto, extProto, getOwnPropertySymbols(extProto)); | 300 copyTheseProperties(jsProto, extProto, getOwnPropertySymbols(extProto)); |
| 299 } | 301 } |
| 300 | 302 |
| 301 /// | 303 /// |
| 302 /// Copy symbols from the prototype of the source to destination. | 304 /// Copy symbols from the prototype of the source to destination. |
| 303 /// These are the only properties safe to copy onto an existing public | 305 /// These are the only properties safe to copy onto an existing public |
| 304 /// JavaScript class. | 306 /// JavaScript class. |
| 305 /// | 307 /// |
| 306 registerExtension(jsType, dartExtType) => JS('', '''(() => { | 308 registerExtension(jsType, dartExtType) => JS('', '''(() => { |
| 307 // TODO(vsm): Not all registered js types are real. | 309 // TODO(vsm): Not all registered js types are real. |
| 308 if (!jsType) return; | 310 if (!jsType) return; |
| 309 | 311 |
| 310 let extProto = $dartExtType.prototype; | 312 let extProto = $dartExtType.prototype; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 })()'''); | 388 })()'''); |
| 387 | 389 |
| 388 /// Sets the element type of a list literal. | 390 /// Sets the element type of a list literal. |
| 389 list(obj, elementType) => | 391 list(obj, elementType) => |
| 390 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); | 392 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); |
| 391 | 393 |
| 392 setBaseClass(derived, base) => JS('', '''(() => { | 394 setBaseClass(derived, base) => JS('', '''(() => { |
| 393 // Link the extension to the type it's extending as a base class. | 395 // Link the extension to the type it's extending as a base class. |
| 394 $derived.prototype.__proto__ = $base.prototype; | 396 $derived.prototype.__proto__ = $base.prototype; |
| 395 })()'''); | 397 })()'''); |
| OLD | NEW |