Skip to content

Commit d53711d

Browse files
MarkzipanCommit Queue
authored andcommitted
[ddc] Reconciling d8 and Chrome timing differences in hot reload suite.
Appending a script to the DOM in Chrome causes microtasks to fire. This change makes the `hotRestart` pathway async and inserts an async callback at the hot restart boundary for d8. Change-Id: Ib05e9e496b6313d861fb5cb691a5894beed62a6e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389224 Reviewed-by: Nicholas Shahan <[email protected]>
1 parent 949eb44 commit d53711d

File tree

10 files changed

+29
-26
lines changed

10 files changed

+29
-26
lines changed

pkg/dev_compiler/lib/js/ddc/ddc_module_loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,8 +1701,8 @@ if (!self.deferred_loader) {
17011701
* Immediately triggers a hot restart of the application losing all state
17021702
* and running the main method again.
17031703
*/
1704-
hotRestart() {
1705-
self.$dartReloadModifiedModules(
1704+
async hotRestart() {
1705+
await self.$dartReloadModifiedModules(
17061706
libraryManager.savedEntryPointLibraryName,
17071707
() => { libraryManager.hotRestart(); });
17081708
}

pkg/reload_test/lib/ddc_helpers.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ let modifiedFilesPerGeneration = ${_encoder.convert(modifiedFilesPerGeneration)}
124124
let previousGenerations = new Set();
125125
126126
// Append a helper function for hot restart.
127-
self.\$dartReloadModifiedModules = function(subAppName, callback) {
127+
self.\$dartReloadModifiedModules = async function(subAppName, callback) {
128128
let expectedName = "$entrypointModuleName";
129129
if (subAppName !== expectedName) {
130130
throw Error("Unexpected app name " + subAppName
@@ -152,8 +152,9 @@ self.\$dartReloadModifiedModules = function(subAppName, callback) {
152152
self.\$dartLoader.forceLoadScript(modifiedFilePath);
153153
}
154154
155-
// Run main.
156-
callback();
155+
// Run main in an async callback. D8 performs synchronous loads, so we need
156+
// to insert an async task to match its semantics to that of Chrome.
157+
await Promise.resolve().then(() => { callback(); });
157158
}
158159
159160
// Append a helper function for hot reload.
@@ -467,7 +468,7 @@ let _scriptUrls = {
467468
return [fileUrls, libraryIds];
468469
}
469470
470-
self.\$dartReloadModifiedModules = function(subAppName, callback) {
471+
self.\$dartReloadModifiedModules = async function(subAppName, callback) {
471472
let expectedName = "$entrypointModuleName";
472473
if (subAppName !== expectedName) {
473474
throw Error("Unexpected app name " + subAppName

pkg/reload_test/lib/src/_ddc_reload_utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension type _DDCLoader(JSObject _) implements JSObject {
2323

2424
extension type _DartDevEmbedder(JSObject _) implements JSObject {
2525
external JSFunction hotReload;
26-
external void hotRestart();
26+
external JSFunction hotRestart;
2727
external JSNumber get hotReloadGeneration;
2828
external JSNumber get hotRestartGeneration;
2929
}
@@ -41,9 +41,9 @@ final _ddcLoader = _dartLoader.loader;
4141

4242
int get hotRestartGeneration => _dartDevEmbedder.hotRestartGeneration.toDartInt;
4343

44-
void hotRestart() {
44+
Future<void> hotRestart() async {
4545
_ddcLoader.intendedHotRestartGeneration++;
46-
_dartDevEmbedder.hotRestart();
46+
await (_dartDevEmbedder.hotRestart.callAsFunction() as JSPromise).toDart;
4747
}
4848

4949
int get hotReloadGeneration => _dartDevEmbedder.hotReloadGeneration.toDartInt;

pkg/reload_test/lib/src/_reload_utils_api.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
int get hotRestartGeneration =>
88
throw Exception('Not implemented on this platform.');
99

10-
void hotRestart() => throw Exception('Not implemented on this platform.');
10+
Future<void> hotRestart() async =>
11+
throw Exception('Not implemented on this platform.');
1112

1213
int get hotReloadGeneration =>
1314
throw Exception('Not implemented on this platform.');
1415

15-
Future<void> hotReload() =>
16+
Future<void> hotReload() async =>
1617
throw Exception('Not implemented on this platform.');

pkg/reload_test/lib/src/_vm_reload_utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import 'package:vm_service/vm_service_io.dart' as vm_service_io;
1212
int get hotRestartGeneration =>
1313
throw Exception('Not implemented on this platform.');
1414

15-
void hotRestart() => throw Exception('Not implemented on this platform.');
15+
Future<void> hotRestart() async =>
16+
throw Exception('Not implemented on this platform.');
1617

1718
int _reloadCounter = 0;
1819
int get hotReloadGeneration => _reloadCounter;

tests/hot_reload/framework_timing_test/main.0.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:reload_test/reload_test_utils.dart';
99

1010
var x = 'Hello World';
1111

12-
void main() {
12+
Future<void> main() async {
1313
Expect.equals('Hello World', x);
1414
Expect.equals(0, hotRestartGeneration);
1515

@@ -29,5 +29,5 @@ void main() {
2929
'This should never run.');
3030
});
3131

32-
hotRestart();
32+
await hotRestart();
3333
}

tests/hot_reload/framework_timing_test/main.1.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:reload_test/reload_test_utils.dart';
99

1010
var x = 'Hello Foo';
1111

12-
void main() {
12+
Future<void> main() async {
1313
Expect.equals('Hello Foo', x);
1414
Expect.equals(1, hotRestartGeneration);
1515

@@ -29,7 +29,7 @@ void main() {
2929
'This should never run.');
3030
});
3131

32-
hotRestart();
32+
await hotRestart();
3333
}
3434
/** DIFF **/
3535
/*
@@ -40,7 +40,7 @@ void main() {
4040
-var x = 'Hello World';
4141
+var x = 'Hello Foo';
4242
43-
void main() {
43+
Future<void> main() async {
4444
- Expect.equals('Hello World', x);
4545
- Expect.equals(0, hotRestartGeneration);
4646
+ Expect.equals('Hello Foo', x);

tests/hot_reload/framework_timing_test/main.2.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:reload_test/reload_test_utils.dart';
99

1010
var x = 'Hello Bar';
1111

12-
void main() {
12+
Future<void> main() async {
1313
Expect.equals('Hello Bar', x);
1414
Expect.equals(2, hotRestartGeneration);
1515

@@ -24,7 +24,7 @@ void main() {
2424
}).then((_) {
2525
Expect.equals(2, hotRestartGeneration);
2626
});
27-
hotRestart();
27+
await hotRestart();
2828
}
2929
/** DIFF **/
3030
/*
@@ -35,7 +35,7 @@ void main() {
3535
-var x = 'Hello Foo';
3636
+var x = 'Hello Bar';
3737
38-
void main() {
38+
Future<void> main() async {
3939
- Expect.equals('Hello Foo', x);
4040
- Expect.equals(1, hotRestartGeneration);
4141
+ Expect.equals('Hello Bar', x);
@@ -61,6 +61,6 @@ void main() {
6161
- 'This should never run.');
6262
- });
6363
-
64-
hotRestart();
64+
await hotRestart();
6565
}
6666
*/

tests/hot_reload/hot_restart_constant_equality/main.0.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class ConstObject {
2727
'${value1 == value2 ? 'ConstantEqualitySuccess' : 'ConstantEqualityFailure'})';
2828
}
2929

30-
void main() {
30+
Future<void> main() async {
3131
Expect.equals('ConstObject(reloadVariable: 23, ConstantEqualitySuccess)',
3232
'${const ConstObject().text}');
33-
hotRestart();
33+
await hotRestart();
3434
}

tests/hot_reload/hot_restart_constant_equality/main.1.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ConstObject {
2727
'${value1 == value2 ? 'ConstantEqualitySuccess' : 'ConstantEqualityFailure'})';
2828
}
2929

30-
void main() {
30+
Future<void> main() async {
3131
Expect.equals('ConstObject(reloadVariable: 45, ConstantEqualitySuccess)',
3232
'${const ConstObject().text}');
3333
}
@@ -36,10 +36,10 @@ void main() {
3636
@@ -28,7 +28,6 @@
3737
}
3838
39-
void main() {
39+
Future<void> main() async {
4040
- Expect.equals('ConstObject(reloadVariable: 23, ConstantEqualitySuccess)',
4141
+ Expect.equals('ConstObject(reloadVariable: 45, ConstantEqualitySuccess)',
4242
'${const ConstObject().text}');
43-
- hotRestart();
43+
- await hotRestart();
4444
}
4545
*/

0 commit comments

Comments
 (0)