| Index: pkg/compiler/lib/src/js_backend/native_data.dart
|
| diff --git a/pkg/compiler/lib/src/js_backend/native_data.dart b/pkg/compiler/lib/src/js_backend/native_data.dart
|
| index 67f495368e14d6ae2a612d3bef18f33a62ed3703..0ad4565e6a93b4f820a0300ad29816ddd9bd62e6 100644
|
| --- a/pkg/compiler/lib/src/js_backend/native_data.dart
|
| +++ b/pkg/compiler/lib/src/js_backend/native_data.dart
|
| @@ -146,6 +146,9 @@ abstract class NativeDataBuilder {
|
|
|
| /// Sets the explicit js interop [name] for the member [element].
|
| void setJsInteropMemberName(MemberEntity element, String name);
|
| +
|
| + /// Closes this builder and creates the resulting [NativeData] object.
|
| + NativeData close();
|
| }
|
|
|
| class NativeBasicDataBuilderImpl implements NativeBasicDataBuilder {
|
| @@ -251,11 +254,7 @@ class NativeBasicDataImpl implements NativeBasicData {
|
| }
|
| }
|
|
|
| -class NativeDataImpl implements NativeDataBuilder, NativeData {
|
| - /// Prefix used to escape JS names that are not valid Dart names
|
| - /// when using JSInterop.
|
| - static const String _jsInteropEscapePrefix = r'JS$';
|
| -
|
| +class NativeDataBuilderImpl implements NativeDataBuilder {
|
| final NativeBasicData _nativeBasicData;
|
|
|
| /// The JavaScript names for native JavaScript elements implemented.
|
| @@ -273,17 +272,22 @@ class NativeDataImpl implements NativeDataBuilder, NativeData {
|
| Map<MemberEntity, NativeBehavior> nativeFieldStoreBehavior =
|
| <FieldEntity, NativeBehavior>{};
|
|
|
| - /// The JavaScript names for elements implemented via typed JavaScript
|
| + /// The JavaScript names for libraries implemented via typed JavaScript
|
| /// interop.
|
| Map<LibraryEntity, String> jsInteropLibraryNames = <LibraryEntity, String>{};
|
| +
|
| + /// JavaScript interop classes annotated with `@anonymous`
|
| Set<ClassEntity> anonymousJsInteropClasses = new Set<ClassEntity>();
|
| +
|
| + /// The JavaScript names for classes implemented via typed JavaScript
|
| + /// interop.
|
| Map<ClassEntity, String> jsInteropClassNames = <ClassEntity, String>{};
|
|
|
| - /// The JavaScript names for elements implemented via typed JavaScript
|
| + /// The JavaScript names for members implemented via typed JavaScript
|
| /// interop.
|
| Map<MemberEntity, String> jsInteropMemberNames = <MemberEntity, String>{};
|
|
|
| - NativeDataImpl(this._nativeBasicData);
|
| + NativeDataBuilderImpl(this._nativeBasicData);
|
|
|
| /// Sets the native [name] for the member [element]. This name is used for
|
| /// [element] in the generated JavaScript.
|
| @@ -323,11 +327,6 @@ class NativeDataImpl implements NativeDataBuilder, NativeData {
|
| }
|
|
|
| @override
|
| - bool isAnonymousJsInteropClass(ClassEntity element) {
|
| - return anonymousJsInteropClasses.contains(element);
|
| - }
|
| -
|
| - @override
|
| void markJsInteropClassAsAnonymous(ClassEntity element) {
|
| anonymousJsInteropClasses.add(element);
|
| }
|
| @@ -345,19 +344,77 @@ class NativeDataImpl implements NativeDataBuilder, NativeData {
|
| jsInteropMemberNames[element] = null;
|
| }
|
|
|
| - /// Returns `true` if [element] is explicitly marked as part of JsInterop.
|
| - bool _isJsInteropMember(MemberEntity element) {
|
| - return jsInteropMemberNames.containsKey(element);
|
| - }
|
| -
|
| /// Sets the explicit js interop [name] for the member [element].
|
| void setJsInteropMemberName(MemberEntity element, String name) {
|
| - assert(invariant(element, _isJsInteropMember(element),
|
| + assert(invariant(element, jsInteropMemberNames.containsKey(element),
|
| message:
|
| 'Member $element is not js interop but given a js interop name.'));
|
| jsInteropMemberNames[element] = name;
|
| }
|
|
|
| + @override
|
| + NativeData close() => new NativeDataImpl(
|
| + _nativeBasicData,
|
| + nativeMemberName,
|
| + nativeMethodBehavior,
|
| + nativeFieldLoadBehavior,
|
| + nativeFieldStoreBehavior,
|
| + jsInteropLibraryNames,
|
| + anonymousJsInteropClasses,
|
| + jsInteropClassNames,
|
| + jsInteropMemberNames);
|
| +}
|
| +
|
| +class NativeDataImpl implements NativeData {
|
| + /// Prefix used to escape JS names that are not valid Dart names
|
| + /// when using JSInterop.
|
| + static const String _jsInteropEscapePrefix = r'JS$';
|
| +
|
| + final NativeBasicData _nativeBasicData;
|
| +
|
| + /// The JavaScript names for native JavaScript elements implemented.
|
| + final Map<MemberEntity, String> nativeMemberName;
|
| +
|
| + /// Cache for [NativeBehavior]s for calling native methods.
|
| + final Map<FunctionEntity, NativeBehavior> nativeMethodBehavior;
|
| +
|
| + /// Cache for [NativeBehavior]s for reading from native fields.
|
| + final Map<MemberEntity, NativeBehavior> nativeFieldLoadBehavior;
|
| +
|
| + /// Cache for [NativeBehavior]s for writing to native fields.
|
| + final Map<MemberEntity, NativeBehavior> nativeFieldStoreBehavior;
|
| +
|
| + /// The JavaScript names for libraries implemented via typed JavaScript
|
| + /// interop.
|
| + final Map<LibraryEntity, String> jsInteropLibraryNames;
|
| +
|
| + /// JavaScript interop classes annotated with `@anonymous`
|
| + final Set<ClassEntity> anonymousJsInteropClasses;
|
| +
|
| + /// The JavaScript names for classes implemented via typed JavaScript
|
| + /// interop.
|
| + final Map<ClassEntity, String> jsInteropClassNames;
|
| +
|
| + /// The JavaScript names for members implemented via typed JavaScript
|
| + /// interop.
|
| + final Map<MemberEntity, String> jsInteropMemberNames;
|
| +
|
| + NativeDataImpl(
|
| + this._nativeBasicData,
|
| + this.nativeMemberName,
|
| + this.nativeMethodBehavior,
|
| + this.nativeFieldLoadBehavior,
|
| + this.nativeFieldStoreBehavior,
|
| + this.jsInteropLibraryNames,
|
| + this.anonymousJsInteropClasses,
|
| + this.jsInteropClassNames,
|
| + this.jsInteropMemberNames);
|
| +
|
| + @override
|
| + bool isAnonymousJsInteropClass(ClassEntity element) {
|
| + return anonymousJsInteropClasses.contains(element);
|
| + }
|
| +
|
| /// Returns `true` if [cls] is a native class.
|
| bool isNativeClass(ClassEntity element) =>
|
| _nativeBasicData.isNativeClass(element);
|
| @@ -399,6 +456,11 @@ class NativeDataImpl implements NativeDataBuilder, NativeData {
|
| return jsInteropMemberNames[element];
|
| }
|
|
|
| + /// Returns `true` if [element] is explicitly marked as part of JsInterop.
|
| + bool _isJsInteropMember(MemberEntity element) {
|
| + return jsInteropMemberNames.containsKey(element);
|
| + }
|
| +
|
| /// Returns `true` if [element] is a JsInterop method.
|
| bool isJsInteropMember(MemberEntity element) {
|
| if (element.isFunction ||
|
|
|