Skip to content

Commit dbcf23a

Browse files
osa1Commit Queue
authored and
Commit Queue
committed
[dart2wasm] Disallow dart:ffi in user code
Change-Id: I1d99637e4538a183d8fa567399bfb7c55675e60e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368568 Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Srujan Gaddam <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]>
1 parent ebd8c46 commit dbcf23a

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

+10
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,16 @@ Message _withArgumentsCyclicTypedef(String name) {
27422742
);
27432743
}
27442744

2745+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2746+
const Code<Null> codeDartFfiLibraryInDart2Wasm =
2747+
messageDartFfiLibraryInDart2Wasm;
2748+
2749+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2750+
const MessageCode messageDartFfiLibraryInDart2Wasm = const MessageCode(
2751+
"DartFfiLibraryInDart2Wasm",
2752+
problemMessage: r"""'dart:ffi' can't be imported when compiling to Wasm.""",
2753+
);
2754+
27452755
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
27462756
const Template<Message Function(String name, String string)>
27472757
templateDebugTrace =

pkg/_js_interop_checks/lib/js_interop_checks.dart

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
88
show
99
Message,
1010
LocatedMessage,
11+
messageDartFfiLibraryInDart2Wasm,
1112
messageJsInteropDartJsInteropAnnotationForStaticInteropOnly,
1213
messageJsInteropEnclosingClassJSAnnotation,
1314
messageJsInteropEnclosingClassJSAnnotationContext,
@@ -134,7 +135,8 @@ class JsInteropChecks extends RecursiveVisitor {
134135
'package:js/js.dart',
135136
'package:js/js_util.dart',
136137
'dart:js_util',
137-
'dart:js'
138+
'dart:js',
139+
'dart:ffi',
138140
];
139141

140142
/// Libraries that use `external` to exclude from checks on external.
@@ -550,12 +552,12 @@ class JsInteropChecks extends RecursiveVisitor {
550552
_allowedUseOfDart2WasmDisallowedInteropLibrariesTestPatterns
551553
.any((pattern) => uri.path.contains(pattern));
552554
if (allowedToImport) return;
553-
_reporter.report(
554-
templateJsInteropDisallowedInteropLibraryInDart2Wasm
555-
.withArguments(dependencyUriString),
556-
dependency.fileOffset,
557-
dependencyUriString.length,
558-
node.fileUri);
555+
final message = dependencyUriString == 'dart:ffi'
556+
? messageDartFfiLibraryInDart2Wasm
557+
: templateJsInteropDisallowedInteropLibraryInDart2Wasm
558+
.withArguments(dependencyUriString);
559+
_reporter.report(message, dependency.fileOffset,
560+
dependencyUriString.length, node.fileUri);
559561
}
560562
}
561563
}

pkg/front_end/messages.status

+3-1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ CyclicRedirectingFactoryConstructors/part_wrapped_script: Fail # Error is report
188188
CyclicRedirectingFactoryConstructors/script: Fail # Error is reported for each factory involved in the cycle.
189189
CyclicRepresentationDependency/analyzerCode: Fail
190190
CyclicTypedef/example: Fail
191+
DartFfiLibraryInDart2Wasm/analyzerCode: Fail
192+
DartFfiLibraryInDart2Wasm/example: Fail
191193
DeferredAfterPrefix/example: Fail
192194
DeferredExtensionImport/analyzerCode: Fail
193195
DeferredExtensionImport/part_wrapped_script: Fail
@@ -1136,4 +1138,4 @@ YieldNotGenerator/example: Fail
11361138
# TODO(johnniwinther): Remove these.
11371139
ExternalField/example: Fail
11381140
UnexpectedModifierInNonNnbd/example: Fail
1139-
SwitchExpressionNotAssignable/example: Fail
1141+
SwitchExpressionNotAssignable/example: Fail

pkg/front_end/messages.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -7355,4 +7355,7 @@ ExperimentExpiredEnabled:
73557355
problemMessage: "The experiment '#name' has expired and can't be enabled."
73567356

73577357
ExperimentExpiredDisabled:
7358-
problemMessage: "The experiment '#name' has expired and can't be disabled."
7358+
problemMessage: "The experiment '#name' has expired and can't be disabled."
7359+
7360+
DartFfiLibraryInDart2Wasm:
7361+
problemMessage: "'dart:ffi' can't be imported when compiling to Wasm."

tests/lib/js/static_interop_test/disallowed_interop_libraries_test.dart

+4
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@
2020
// ^
2121
// [web] JS interop library 'package:js/js_util.dart' can't be imported when compiling to Wasm.
2222

23+
/**/ import 'dart:ffi';
24+
// ^
25+
// [web] 'dart:ffi' can't be imported when compiling to Wasm.
26+
2327
void main() {}

0 commit comments

Comments
 (0)