Skip to content

Commit 6593592

Browse files
authored
Use isA to test for exceptions (flutter#183129)
This code was never testing that the exception was a DOMException. When compiling to JS, this is just checking if it is a JS object and when compiling to Wasm, this is just checking if the value is a JS value. With recent [lint changes](https://dart-review.googlesource.com/c/sdk/+/483960), this will now be linted and will therefore block the SDK roll. Instead, we should catch the exception without a type, do an isA check (now that it supports arbitrary values), and then rethrow if it isn't the exception we were looking for. Note that this does mean if this code was accidentally catching a different JS value before, it now rethrows it. ## 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]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord].
1 parent 8f2e7b7 commit 6593592

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

engine/src/flutter/lib/web_ui/lib/src/engine/view_embedder/style_manager.dart

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:js_interop';
6+
57
import 'package:meta/meta.dart';
68

79
import '../browser_detection.dart';
@@ -165,19 +167,23 @@ void applyGlobalCssRulesToSheet(
165167
' display: none;'
166168
'}',
167169
);
168-
} on DomException catch (e) {
169-
// Browsers that don't understand ::-ms-reveal throw a DOMException
170-
// of type SyntaxError.
171-
domWindow.console.warn(e);
172-
// Add a fake rule if our code failed because we're under testing
173-
assert(() {
174-
styleElement.appendText(
175-
'$cssSelectorPrefix input.fallback-for-fakey-browser-in-ci {'
176-
' display: none;'
177-
'}',
178-
);
179-
return true;
180-
}());
170+
} catch (e) {
171+
if (e.isA<DomException>()) {
172+
// Browsers that don't understand ::-ms-reveal throw a DOMException
173+
// of type SyntaxError.
174+
domWindow.console.warn(e);
175+
// Add a fake rule if our code failed because we're under testing
176+
assert(() {
177+
styleElement.appendText(
178+
'$cssSelectorPrefix input.fallback-for-fakey-browser-in-ci {'
179+
' display: none;'
180+
'}',
181+
);
182+
return true;
183+
}());
184+
} else {
185+
rethrow;
186+
}
181187
}
182188
}
183189
}

0 commit comments

Comments
 (0)