OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library js_backend.native_data; | 5 library js_backend.native_data; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common_elements.dart' show ElementEnvironment; | 8 import '../common_elements.dart' show ElementEnvironment; |
9 import '../elements/entities.dart'; | 9 import '../elements/entities.dart'; |
10 import '../native/behavior.dart' show NativeBehavior; | 10 import '../native/behavior.dart' show NativeBehavior; |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 nativeMemberName, | 364 nativeMemberName, |
365 nativeMethodBehavior, | 365 nativeMethodBehavior, |
366 nativeFieldLoadBehavior, | 366 nativeFieldLoadBehavior, |
367 nativeFieldStoreBehavior, | 367 nativeFieldStoreBehavior, |
368 jsInteropLibraryNames, | 368 jsInteropLibraryNames, |
369 anonymousJsInteropClasses, | 369 anonymousJsInteropClasses, |
370 jsInteropClassNames, | 370 jsInteropClassNames, |
371 jsInteropMemberNames); | 371 jsInteropMemberNames); |
372 } | 372 } |
373 | 373 |
374 class NativeDataImpl implements NativeData { | 374 class NativeDataImpl implements NativeData, NativeBasicDataImpl { |
375 /// Prefix used to escape JS names that are not valid Dart names | 375 /// Prefix used to escape JS names that are not valid Dart names |
376 /// when using JSInterop. | 376 /// when using JSInterop. |
377 static const String _jsInteropEscapePrefix = r'JS$'; | 377 static const String _jsInteropEscapePrefix = r'JS$'; |
378 | 378 |
379 final NativeBasicData _nativeBasicData; | 379 final NativeBasicDataImpl _nativeBasicData; |
380 | 380 |
381 /// The JavaScript names for native JavaScript elements implemented. | 381 /// The JavaScript names for native JavaScript elements implemented. |
382 final Map<MemberEntity, String> nativeMemberName; | 382 final Map<MemberEntity, String> nativeMemberName; |
383 | 383 |
384 /// Cache for [NativeBehavior]s for calling native methods. | 384 /// Cache for [NativeBehavior]s for calling native methods. |
385 final Map<FunctionEntity, NativeBehavior> nativeMethodBehavior; | 385 final Map<FunctionEntity, NativeBehavior> nativeMethodBehavior; |
386 | 386 |
387 /// Cache for [NativeBehavior]s for reading from native fields. | 387 /// Cache for [NativeBehavior]s for reading from native fields. |
388 final Map<MemberEntity, NativeBehavior> nativeFieldLoadBehavior; | 388 final Map<MemberEntity, NativeBehavior> nativeFieldLoadBehavior; |
389 | 389 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 return nativeFieldStoreBehavior[field]; | 596 return nativeFieldStoreBehavior[field]; |
597 } | 597 } |
598 | 598 |
599 /// Apply JS$ escaping scheme to convert possible escaped Dart names into | 599 /// Apply JS$ escaping scheme to convert possible escaped Dart names into |
600 /// JS names. | 600 /// JS names. |
601 String computeUnescapedJSInteropName(String name) { | 601 String computeUnescapedJSInteropName(String name) { |
602 return name.startsWith(_jsInteropEscapePrefix) | 602 return name.startsWith(_jsInteropEscapePrefix) |
603 ? name.substring(_jsInteropEscapePrefix.length) | 603 ? name.substring(_jsInteropEscapePrefix.length) |
604 : name; | 604 : name; |
605 } | 605 } |
| 606 |
| 607 @override |
| 608 Set<ClassEntity> get jsInteropClasses => _nativeBasicData.jsInteropClasses; |
| 609 |
| 610 @override |
| 611 Set<LibraryEntity> get jsInteropLibraries => |
| 612 _nativeBasicData.jsInteropLibraries; |
| 613 |
| 614 @override |
| 615 Map<ClassEntity, NativeClassTag> get nativeClassTagInfo => |
| 616 _nativeBasicData.nativeClassTagInfo; |
| 617 |
| 618 @override |
| 619 ElementEnvironment get _env => _nativeBasicData._env; |
606 } | 620 } |
607 | 621 |
608 class NativeClassTag { | 622 class NativeClassTag { |
609 final List<String> names; | 623 final List<String> names; |
610 final bool isNonLeaf; | 624 final bool isNonLeaf; |
611 | 625 |
612 factory NativeClassTag(String tagText) { | 626 factory NativeClassTag(String tagText) { |
613 List<String> tags = tagText.split(','); | 627 List<String> tags = tagText.split(','); |
614 List<String> names = tags.where((s) => !s.startsWith('!')).toList(); | 628 List<String> names = tags.where((s) => !s.startsWith('!')).toList(); |
615 bool isNonLeaf = tags.contains('!nonleaf'); | 629 bool isNonLeaf = tags.contains('!nonleaf'); |
(...skipping 17 matching lines...) Expand all Loading... |
633 int get hashCode => Hashing.listHash(names, isNonLeaf.hashCode); | 647 int get hashCode => Hashing.listHash(names, isNonLeaf.hashCode); |
634 | 648 |
635 bool operator ==(other) { | 649 bool operator ==(other) { |
636 if (identical(this, other)) return true; | 650 if (identical(this, other)) return true; |
637 if (other is! NativeClassTag) return false; | 651 if (other is! NativeClassTag) return false; |
638 return equalElements(names, other.names) && isNonLeaf == other.isNonLeaf; | 652 return equalElements(names, other.names) && isNonLeaf == other.isNonLeaf; |
639 } | 653 } |
640 | 654 |
641 String toString() => text; | 655 String toString() => text; |
642 } | 656 } |
OLD | NEW |