Skip to content

Commit 7f839e1

Browse files
committed
Check for method existence instead of catching errors
1 parent 9053742 commit 7f839e1

File tree

3 files changed

+784
-791
lines changed

3 files changed

+784
-791
lines changed

build_runner/lib/src/server/hot_reload_client/client.dart

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'dart:convert';
1010
import 'dart:html';
1111

1212
import 'package:js/js.dart';
13+
import 'package:js/js_util.dart';
1314

1415
import 'reload_handler.dart';
1516
import 'reloading_manager.dart';
@@ -69,32 +70,29 @@ class ModuleWrapper implements Module {
6970

7071
@override
7172
Object onDestroy() {
72-
try {
73+
if (_internal != null && hasProperty(_internal, r'hot$onDestroy')) {
7374
return _internal.hot$onDestroy();
74-
} on NoSuchMethodError {
75-
return null;
7675
}
76+
return null;
7777
}
7878

7979
@override
8080
bool onSelfUpdate([Object data]) {
81-
try {
81+
if (_internal != null && hasProperty(_internal, r'hot$onSelfUpdate')) {
8282
return _internal.hot$onSelfUpdate(data);
83-
} on NoSuchMethodError {
84-
// ignore: avoid_returning_null
85-
return null;
8683
}
84+
// ignore: avoid_returning_null
85+
return null;
8786
}
8887

8988
@override
9089
bool onChildUpdate(String childId, Module child, [Object data]) {
91-
try {
90+
if (_internal != null && hasProperty(_internal, r'hot$onChildUpdate')) {
9291
return _internal.hot$onChildUpdate(
9392
childId, (child as ModuleWrapper)._internal, data);
94-
} on NoSuchMethodError {
95-
// ignore: avoid_returning_null
96-
return null;
9793
}
94+
// ignore: avoid_returning_null
95+
return null;
9896
}
9997
}
10098

0 commit comments

Comments
 (0)