Skip to content

Commit

Permalink
[dart2wasm] Disallow dart:ffi in user code
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
osa1 authored and Commit Queue committed May 31, 2024
1 parent ebd8c46 commit dbcf23a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
10 changes: 10 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2742,6 +2742,16 @@ Message _withArgumentsCyclicTypedef(String name) {
);
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeDartFfiLibraryInDart2Wasm =
messageDartFfiLibraryInDart2Wasm;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageDartFfiLibraryInDart2Wasm = const MessageCode(
"DartFfiLibraryInDart2Wasm",
problemMessage: r"""'dart:ffi' can't be imported when compiling to Wasm.""",
);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<Message Function(String name, String string)>
templateDebugTrace =
Expand Down
16 changes: 9 additions & 7 deletions pkg/_js_interop_checks/lib/js_interop_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
show
Message,
LocatedMessage,
messageDartFfiLibraryInDart2Wasm,
messageJsInteropDartJsInteropAnnotationForStaticInteropOnly,
messageJsInteropEnclosingClassJSAnnotation,
messageJsInteropEnclosingClassJSAnnotationContext,
Expand Down Expand Up @@ -134,7 +135,8 @@ class JsInteropChecks extends RecursiveVisitor {
'package:js/js.dart',
'package:js/js_util.dart',
'dart:js_util',
'dart:js'
'dart:js',
'dart:ffi',
];

/// Libraries that use `external` to exclude from checks on external.
Expand Down Expand Up @@ -550,12 +552,12 @@ class JsInteropChecks extends RecursiveVisitor {
_allowedUseOfDart2WasmDisallowedInteropLibrariesTestPatterns
.any((pattern) => uri.path.contains(pattern));
if (allowedToImport) return;
_reporter.report(
templateJsInteropDisallowedInteropLibraryInDart2Wasm
.withArguments(dependencyUriString),
dependency.fileOffset,
dependencyUriString.length,
node.fileUri);
final message = dependencyUriString == 'dart:ffi'
? messageDartFfiLibraryInDart2Wasm
: templateJsInteropDisallowedInteropLibraryInDart2Wasm
.withArguments(dependencyUriString);
_reporter.report(message, dependency.fileOffset,
dependencyUriString.length, node.fileUri);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/front_end/messages.status
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ CyclicRedirectingFactoryConstructors/part_wrapped_script: Fail # Error is report
CyclicRedirectingFactoryConstructors/script: Fail # Error is reported for each factory involved in the cycle.
CyclicRepresentationDependency/analyzerCode: Fail
CyclicTypedef/example: Fail
DartFfiLibraryInDart2Wasm/analyzerCode: Fail
DartFfiLibraryInDart2Wasm/example: Fail
DeferredAfterPrefix/example: Fail
DeferredExtensionImport/analyzerCode: Fail
DeferredExtensionImport/part_wrapped_script: Fail
Expand Down Expand Up @@ -1136,4 +1138,4 @@ YieldNotGenerator/example: Fail
# TODO(johnniwinther): Remove these.
ExternalField/example: Fail
UnexpectedModifierInNonNnbd/example: Fail
SwitchExpressionNotAssignable/example: Fail
SwitchExpressionNotAssignable/example: Fail
5 changes: 4 additions & 1 deletion pkg/front_end/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7355,4 +7355,7 @@ ExperimentExpiredEnabled:
problemMessage: "The experiment '#name' has expired and can't be enabled."

ExperimentExpiredDisabled:
problemMessage: "The experiment '#name' has expired and can't be disabled."
problemMessage: "The experiment '#name' has expired and can't be disabled."

DartFfiLibraryInDart2Wasm:
problemMessage: "'dart:ffi' can't be imported when compiling to Wasm."
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
// ^
// [web] JS interop library 'package:js/js_util.dart' can't be imported when compiling to Wasm.

/**/ import 'dart:ffi';
// ^
// [web] 'dart:ffi' can't be imported when compiling to Wasm.

void main() {}

0 comments on commit dbcf23a

Please sign in to comment.