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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 $defineMemoizedGetter(type, $_methodSig, function() { | 336 $defineMemoizedGetter(type, $_methodSig, function() { |
337 let sig = originalSigFn(); | 337 let sig = originalSigFn(); |
338 for (let name of $methodNames) { | 338 for (let name of $methodNames) { |
339 sig[$getExtensionSymbol(name)] = sig[name]; | 339 sig[$getExtensionSymbol(name)] = sig[name]; |
340 } | 340 } |
341 return sig; | 341 return sig; |
342 }); | 342 }); |
343 })()'''); | 343 })()'''); |
344 | 344 |
345 canonicalMember(obj, name) => JS('', '''(() => { | 345 canonicalMember(obj, name) => JS('', '''(() => { |
| 346 // Private names are symbols and are already canonical. |
| 347 if (typeof name === 'symbol') return name; |
| 348 |
346 if ($obj != null && $obj[$_extensionType]) return $dartx[$name]; | 349 if ($obj != null && $obj[$_extensionType]) return $dartx[$name]; |
347 // Check for certain names that we can't use in JS | 350 // Check for certain names that we can't use in JS |
348 if ($name == 'constructor' || $name == 'prototype') { | 351 if ($name == 'constructor' || $name == 'prototype') { |
349 $name = '+' + $name; | 352 $name = '+' + $name; |
350 } | 353 } |
351 return $name; | 354 return $name; |
352 })()'''); | 355 })()'''); |
353 | 356 |
354 /// Sets the type of `obj` to be `type` | 357 /// Sets the type of `obj` to be `type` |
355 setType(obj, type) => JS('', '''(() => { | 358 setType(obj, type) => JS('', '''(() => { |
356 $obj.__proto__ = $type.prototype; | 359 $obj.__proto__ = $type.prototype; |
357 // TODO(vsm): This should be set in registerExtension, but that is only | 360 // TODO(vsm): This should be set in registerExtension, but that is only |
358 // invoked on the generic type (e.g., JSArray<dynamic>, not JSArray<int>). | 361 // invoked on the generic type (e.g., JSArray<dynamic>, not JSArray<int>). |
359 $obj.__proto__[$_extensionType] = $type; | 362 $obj.__proto__[$_extensionType] = $type; |
360 return $obj; | 363 return $obj; |
361 })()'''); | 364 })()'''); |
362 | 365 |
363 /// Sets the element type of a list literal. | 366 /// Sets the element type of a list literal. |
364 list(obj, elementType) => | 367 list(obj, elementType) => |
365 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); | 368 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); |
366 | 369 |
367 setBaseClass(derived, base) => JS('', '''(() => { | 370 setBaseClass(derived, base) => JS('', '''(() => { |
368 // Link the extension to the type it's extending as a base class. | 371 // Link the extension to the type it's extending as a base class. |
369 $derived.prototype.__proto__ = $base.prototype; | 372 $derived.prototype.__proto__ = $base.prototype; |
370 })()'''); | 373 })()'''); |
OLD | NEW |