-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)web-dart2jsweb-js-interopIssues that impact all js interopIssues that impact all js interop
Description
Description
I'm encountering an issue when compiling my Dart code to JavaScript using dart compile js. The problem appears to be related to the assignment of an external JavaScript function via dart:js_interop.
Code Example
Here's a minimal example of the code causing the issue:
import 'dart:js_interop';
@JS("exportedFunction")
external set exportedFunctions(JSFunction value);
void printStrings(JSString string) {}
void main() {
print("start!");
try {
exportedFunctions = printStrings.toJS;
print("function initialized.");
} catch (e) {
print("something went wrong: $e");
}
print("done");
}
Expected Output
start!
function initialized.
done
Actual Output
Without the try-catch block:
start!
With the try-catch block:
start!
done
Additional Information
Dart SDK Version: 3.5.0 (stable) (Tue Jul 30 02:17:59 2024 -0700) on "macos_x64"
Compilation Command:
dart compile js -o ./build.js ./build.dart
When using the -O0 flag or compiling to WebAssembly (dart compile wasm), the code works perfectly.
Steps Taken to Resolve
Removed and reinstalled both the Flutter and Dart SDKs.
Cleared cache.
Metadata
Metadata
Assignees
Labels
area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)web-dart2jsweb-js-interopIssues that impact all js interopIssues that impact all js interop