@@ -15,7 +15,6 @@ import 'package:front_end/src/api_prototype/codes.dart'
1515 codeDartFfiLibraryInDart2Wasm,
1616 codeJsInteropDartClassExtendsJSClass,
1717 codeJsInteropDartJsInteropAnnotationForStaticInteropOnly,
18- codeJsInteropDisallowedInteropLibraryInDart2Wasm,
1918 codeJsInteropEnclosingClassJSAnnotation,
2019 codeJsInteropEnclosingClassJSAnnotationContext,
2120 codeJsInteropExtensionTypeMemberNotInterop,
@@ -88,8 +87,7 @@ class JsInteropChecks extends RecursiveVisitor {
8887
8988 final ExportChecker exportChecker;
9089 final bool isDart2Wasm;
91-
92- final List <String > _disallowedInteropLibrariesInDart2Wasm;
90+ final bool enableExperimentalFfi;
9391
9492 /// Native tests to exclude from checks on external.
9593 // TODO(rileyporter): Use ExternalName from CFE to exclude native tests.
@@ -103,29 +101,7 @@ class JsInteropChecks extends RecursiveVisitor {
103101 RegExp (r'(?<!generated_)tests/lib/js' ),
104102 ];
105103
106- static final List <Pattern >
107- _allowedUseOfDart2WasmDisallowedInteropLibrariesTestPatterns = [
108- // Benchmarks.
109- RegExp (r'BigIntParsePrint/dart/native_version_javascript.dart' ),
110- RegExp (r'JSInterop/dart/jsinterop_lib.dart' ),
111- // Tests.
112- RegExp (r'(?<!generated_)tests/lib/js/export' ),
113- // Negative lookahead to test the violation.
114- RegExp (
115- r'(?<!generated_)tests/lib/js/static_interop_test(?!/disallowed_interop_libraries_test.dart)' ,
116- ),
117- RegExp (r'(?<!generated_)tests/web/wasm/(?!ffi/).*' ),
118- // Flutter tests.
119- RegExp (r'flutter/lib/web_ui/test' ),
120- ];
121-
122- // TODO(srujzs): Help migrate some of these away. Once we're done, we can
123- // remove `dart:*` interop libraries from the check as they can be moved out
124- // of `libraries.json`.
125104 static const allowedInteropLibrariesInDart2WasmPackages = [
126- // Both these packages re-export other interop libraries
127- 'js' ,
128- 'js_util' ,
129105 // Flutter/benchmarks.
130106 'flutter' ,
131107 'engine' ,
@@ -137,14 +113,6 @@ class JsInteropChecks extends RecursiveVisitor {
137113 'url_launcher_web' ,
138114 ];
139115
140- /// Interop libraries that cannot be used in dart2wasm.
141- static const _disallowedInteropLibrariesInDart2WasmByDefault = [
142- 'package:js/js.dart' ,
143- 'package:js/js_util.dart' ,
144- 'dart:js_util' ,
145- 'dart:ffi' ,
146- ];
147-
148116 /// Libraries that use `external` to exclude from checks on external.
149117 static const Iterable <String > _pathsWithAllowedDartExternalUsage = < String > [
150118 '_foreign_helper' , // for foreign helpers
@@ -173,7 +141,7 @@ class JsInteropChecks extends RecursiveVisitor {
173141 this ._reporter,
174142 this ._nativeClasses, {
175143 this .isDart2Wasm = false ,
176- bool enableExperimentalFfi = false ,
144+ this . enableExperimentalFfi = false ,
177145 }) : exportChecker = ExportChecker (_reporter, _coreTypes.objectClass),
178146 _functionToJSTarget = _coreTypes.index.getTopLevelProcedure (
179147 'dart:js_interop' ,
@@ -185,11 +153,7 @@ class JsInteropChecks extends RecursiveVisitor {
185153 ),
186154 _staticTypeContext = StatefulStaticTypeContext .stacked (
187155 TypeEnvironment (_coreTypes, hierarchy),
188- ),
189- _disallowedInteropLibrariesInDart2Wasm = [
190- for (final entry in _disallowedInteropLibrariesInDart2WasmByDefault)
191- if (! (entry == 'dart:ffi' && enableExperimentalFfi)) entry,
192- ] {
156+ ) {
193157 extensionIndex = ExtensionIndex (
194158 _coreTypes,
195159 _staticTypeContext.typeEnvironment,
@@ -625,34 +589,24 @@ class JsInteropChecks extends RecursiveVisitor {
625589 /// Check that [node] doesn't depend on any disallowed interop libraries in
626590 /// dart2wasm.
627591 ///
628- /// We allowlist `dart:*` libraries, select packages, and test patterns .
592+ /// We allowlist `dart:*` libraries and select packages .
629593 void _checkDisallowedLibrariesForDart2Wasm (Library node) {
630594 final uri = node.importUri;
631595 for (final dependency in node.dependencies) {
632596 final dependencyUriString = dependency.targetLibrary.importUri.toString ();
633- if (_disallowedInteropLibrariesInDart2Wasm.contains (
634- dependencyUriString,
635- )) {
597+ if (! enableExperimentalFfi && dependencyUriString == 'dart:ffi' ) {
636598 // TODO(srujzs): While we allow these imports for all `dart:*`
637599 // libraries, we may want to restrict this further, as it may include
638600 // `dart:ui`.
639601 final allowedToImport =
640602 uri.isScheme ('dart' ) ||
641- (uri.isScheme ('package' ) &&
642- allowedInteropLibrariesInDart2WasmPackages.any (
643- (pkg) => uri.pathSegments.first == pkg,
644- )) ||
645- _allowedUseOfDart2WasmDisallowedInteropLibrariesTestPatterns.any (
646- (pattern) => uri.path.contains (pattern),
647- );
603+ uri.isScheme ('package' ) &&
604+ allowedInteropLibrariesInDart2WasmPackages.contains (
605+ uri.pathSegments.first,
606+ );
648607 if (allowedToImport) return ;
649- final message = dependencyUriString == 'dart:ffi'
650- ? codeDartFfiLibraryInDart2Wasm
651- : codeJsInteropDisallowedInteropLibraryInDart2Wasm.withArgumentsOld (
652- dependencyUriString,
653- );
654608 _reporter.report (
655- message ,
609+ codeDartFfiLibraryInDart2Wasm ,
656610 dependency.fileOffset,
657611 dependencyUriString.length,
658612 node.fileUri,
@@ -683,9 +637,7 @@ class JsInteropChecks extends RecursiveVisitor {
683637 bool _isAllowedTrustTypesUsage (Class cls) {
684638 final uri = cls.enclosingLibrary.importUri;
685639 return uri.isScheme ('dart' ) && uri.path == 'ui' ||
686- _allowedTrustTypesTestPatterns.any (
687- (pattern) => uri.path.contains (pattern),
688- );
640+ _allowedTrustTypesTestPatterns.any (uri.path.contains);
689641 }
690642
691643 /// Check that JS interop class [node] , that only has an @JS annotation, is
@@ -731,7 +683,7 @@ class JsInteropChecks extends RecursiveVisitor {
731683 final uri = member.enclosingLibrary.importUri;
732684 return uri.isScheme ('dart' ) &&
733685 _pathsWithAllowedDartExternalUsage.contains (uri.path) ||
734- _allowedNativeTestPatterns.any ((pattern) => uri.path.contains (pattern) );
686+ _allowedNativeTestPatterns.any (uri.path.contains);
735687 }
736688
737689 /// Assumes given [member] is not JS interop, and reports an error if
0 commit comments