Repository navigation
Update browser_environment.js to require try_table - #193090
Conversation
An upcoming change to the dart2wasm compiler will make it generate try_table instructions, so this prepares flutter to fall back to JS if it runs on a browser without such support.
|
This pull request targets the Please change the base branch of this pull request to |
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
There was a problem hiding this comment.
Code Review
This pull request updates the supportsDart2Wasm function in browser_environment.js to include an additional WebAssembly validation check for try_table support. The review feedback recommends refactoring the long, single-line expression into descriptive boolean variables to improve readability, and updating the accompanying inline comment to document this new check and correct a typo.
kevmoo
left a comment
There was a problem hiding this comment.
LGTM! Verified that the 31-byte try_table (0x1F, catch_all $0) validation sequence is byte-for-byte identical to supportsTryTable in pkg/dart2wasm/lib/compile.dart (https://dart-review.googlesource.com/c/sdk/+/551200) and empirically verified supportsDart2Wasm() across our local Playwright WebKit (621.1.11..625.1.21 / Safari 18.4 -> 26.6) and Firefox (153.0..155.0) browser matrix:
| Engine | WasmGC |
JsStringBuiltins |
TryTable (0x1F) |
WasmSimd |
supportsDart2Wasm |
|---|---|---|---|---|---|
WebKit 621.1.11 (Safari 18.4) |
yes |
no |
yes |
yes |
no |
WebKit 622.1.35..625.1.21 (Safari 26.0..26.6) |
yes |
yes |
yes |
yes |
yes |
Firefox 153.0..155.0 (SpiderMonkey) |
yes |
yes |
yes |
yes |
yes |
mdebbar
left a comment
There was a problem hiding this comment.
From @kevmoo's agent:
Which Chrome versions are affected: Chrome 130 through 136
- Chrome <= 129: Already fell back to JS because
wasm:js-stringshipped in Chrome 130 (Oct 2024).- Chrome 130 - 136 (Oct 2024 - Apr 2025): Shipped
wasm:js-string(supportsJsStringBuiltins: true), but V8 kept Wasmexnref/try_table(0x1F) behind--experimental-wasm-exnref. On Playwright Chromium136.0.7103.25,supportsTryTableisfalseunder default flags and flips to true only when launched with--js-flags=--experimental-wasm-exnref.- Chrome 137+ (May 2025+): Unflagged
try_table(0x1F) by default (supportsTryTable: true,supportsDart2Wasm: true).
|
autosubmit label was removed for flutter/flutter/193090, because - The status or check suite Mac_arm64_verify_binaries has failed. Please fix the issues identified (or deflake) before re-applying this label.
|
|
autosubmit label was removed for flutter/flutter/193090, because - The status or check suite Mac_arm64_verify_binaries has failed. Please fix the issues identified (or deflake) before re-applying this label.
|
…trap.js (flutter#193271) Synchronizes Flutter Web's Wasm feature detection with the Dart SDK's `dart2wasm` compiler output (`main.dart.support.js`) and automates keeping `supportsDart2Wasm()` in sync during Dart SDK rolls. Follows up on flutter#193090. ### Background When `dart2wasm` compiles a Wasm module (`pkg/dart2wasm/lib/compile.dart`), it emits `<output>.support.js` (`main.dart.support.js` in Flutter Web builds), containing a JavaScript boolean expression that checks whether the current browser supports all WebAssembly features required by the compiled module (WasmGC, relaxed/standard SIMD, `js-string` builtins, `try_table`, and conditional `requiresMultiMemory`). Previously, `engine/src/flutter/lib/web_ui/flutter_js/src/browser_environment.js` maintained a manual copy of this byte array check inside `supportsDart2Wasm()`. Whenever `dart2wasm` added or modified a required Wasm feature probe in the Dart SDK, `flutter_js` had to be manually updated in a separate PR. Additionally, `main.dart.support.js` emitted by `dart2wasm` during `flutter build web --wasm` was never read by `flutter_tools`. ### Changes 1. **Consume `main.dart.support.js` in `flutter_tools` bootstrap generation**: - `generateFlutterBootstrapScript` reads `main.dart.support.js` when present in the build output directory and emits `_flutter.supportsDart2Wasm = <expr>;` immediately after `_flutter.buildConfig = ...;` (preserving strict JSON parsing in `--web-content-hash`). - `supportsDart2Wasm()` in `browser_environment.js` evaluates `window._flutter?.supportsDart2Wasm ?? defaultSupportsDart2Wasm()` after enforcing the Firefox `< 147` guard, so standard `flutter build web --wasm` apps use the exact feature probe emitted by the active `dart2wasm` compiler (including conditional flags such as `--extra-compiler-option=--import-shared-memory`), while custom HTML embeddings using standalone `flutter.js` fall back to `defaultSupportsDart2Wasm()` from `supports_dart2wasm.js`. 2. **Automate `supports_dart2wasm.js` generation during Dart SDK rolls**: - Moves the default `supportsDart2Wasm` probe into a standalone generated module `engine/src/flutter/lib/web_ui/flutter_js/src/supports_dart2wasm.js` imported by `browser_environment.js`. - `engine/src/tools/dart/create_updated_flutter_deps.py` (`SyncSupportsDart2WasmJs`) parses `_generateSupportJs` from `pkg/dart2wasm/lib/compile.dart` (from local `third_party/dart` or `dart.googlesource.com` when `--dart_revision` is specified) and generates `supports_dart2wasm.js`. - `.github/workflows/roll-dart-dependencies.yml` stages `engine/src/flutter/lib/web_ui/flutter_js/src/supports_dart2wasm.js` alongside `DEPS` when rolling Dart dependencies. 3. **CI Parity Guard**: - `engine/src/tools/dart/create_updated_flutter_deps_tests.py` verifies `ExtractDart2WasmSupportExpression` across historical `dart2wasm` epochs and asserts that `supports_dart2wasm.js` matches `third_party/dart/pkg/dart2wasm/lib/compile.dart` whenever `third_party/dart` is present. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing.
An upcoming change to the dart2wasm compiler will make it generate try_table instructions, so this prepares flutter to fall back to JS if it runs on a browser without such support.
See https://dart-review.googlesource.com/c/sdk/+/551200?tab=checks for the Dart compiler change.
Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.
List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.