Unverified Commit 69fd5c50 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] null assertions off by default for web (#64186)

Like Android/iOS, only enable --null-assertions if asked. Previously this was enabled by default for web, but in general this has proved to be too breaking to enable by default.

#61042
parent ae4b3ba2
...@@ -866,7 +866,8 @@ Future<void> _runWebDebugTest(String target, { ...@@ -866,7 +866,8 @@ Future<void> _runWebDebugTest(String target, {
...<String>[ ...<String>[
'--enable-experiment', '--enable-experiment',
'non-nullable', 'non-nullable',
'--no-sound-null-safety' '--no-sound-null-safety',
'--null-assertions',
], ],
'-d', '-d',
'chrome', 'chrome',
......
...@@ -636,6 +636,7 @@ class WebDevFS implements DevFS { ...@@ -636,6 +636,7 @@ class WebDevFS implements DevFS {
@required this.entrypoint, @required this.entrypoint,
@required this.expressionCompiler, @required this.expressionCompiler,
@required this.chromiumLauncher, @required this.chromiumLauncher,
@required this.nullAssertions,
this.testMode = false, this.testMode = false,
}); });
...@@ -651,6 +652,7 @@ class WebDevFS implements DevFS { ...@@ -651,6 +652,7 @@ class WebDevFS implements DevFS {
final bool testMode; final bool testMode;
final ExpressionCompiler expressionCompiler; final ExpressionCompiler expressionCompiler;
final ChromiumLauncher chromiumLauncher; final ChromiumLauncher chromiumLauncher;
final bool nullAssertions;
WebAssetServer webAssetServer; WebAssetServer webAssetServer;
...@@ -791,8 +793,7 @@ class WebDevFS implements DevFS { ...@@ -791,8 +793,7 @@ class WebDevFS implements DevFS {
'main_module.bootstrap.js', 'main_module.bootstrap.js',
generateMainModule( generateMainModule(
entrypoint: entrypoint, entrypoint: entrypoint,
nullSafety: buildInfo.extraFrontEndOptions nullAssertions: nullAssertions,
?.contains('--enable-experiment=non-nullable') ?? false,
), ),
); );
// TODO(jonahwilliams): refactor the asset code in this and the regular devfs to // TODO(jonahwilliams): refactor the asset code in this and the regular devfs to
......
...@@ -469,6 +469,7 @@ class _ResidentWebRunner extends ResidentWebRunner { ...@@ -469,6 +469,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
entrypoint: globals.fs.file(target).uri, entrypoint: globals.fs.file(target).uri,
expressionCompiler: expressionCompiler, expressionCompiler: expressionCompiler,
chromiumLauncher: _chromiumLauncher, chromiumLauncher: _chromiumLauncher,
nullAssertions: debuggingOptions.nullAssertions,
); );
final Uri url = await device.devFS.create(); final Uri url = await device.devFS.create();
if (debuggingOptions.buildInfo.isDebug) { if (debuggingOptions.buildInfo.isDebug) {
......
...@@ -50,14 +50,14 @@ document.head.appendChild(requireEl); ...@@ -50,14 +50,14 @@ document.head.appendChild(requireEl);
/// this object is the module. /// this object is the module.
String generateMainModule({ String generateMainModule({
@required String entrypoint, @required String entrypoint,
@required bool nullSafety, @required bool nullAssertions,
}) { }) {
return '''/* ENTRYPOINT_EXTENTION_MARKER */ return '''/* ENTRYPOINT_EXTENTION_MARKER */
// Create the main module loaded below. // Create the main module loaded below.
define("main_module.bootstrap", ["$entrypoint", "dart_sdk"], function(app, dart_sdk) { define("main_module.bootstrap", ["$entrypoint", "dart_sdk"], function(app, dart_sdk) {
dart_sdk.dart.setStartAsyncSynchronously(true); dart_sdk.dart.setStartAsyncSynchronously(true);
dart_sdk._debugger.registerDevtoolsFormatter(); dart_sdk._debugger.registerDevtoolsFormatter();
if ($nullSafety) { if ($nullAssertions) {
dart_sdk.dart.nonNullAsserts(true); dart_sdk.dart.nonNullAsserts(true);
} }
......
...@@ -23,7 +23,7 @@ void main() { ...@@ -23,7 +23,7 @@ void main() {
test('generateMainModule embeds urls correctly', () { test('generateMainModule embeds urls correctly', () {
final String result = generateMainModule( final String result = generateMainModule(
entrypoint: 'foo/bar/main.js', entrypoint: 'foo/bar/main.js',
nullSafety: false, nullAssertions: false,
); );
// bootstrap main module has correct defined module. // bootstrap main module has correct defined module.
expect(result, contains('define("main_module.bootstrap", ["foo/bar/main.js", "dart_sdk"], ' expect(result, contains('define("main_module.bootstrap", ["foo/bar/main.js", "dart_sdk"], '
...@@ -33,7 +33,7 @@ void main() { ...@@ -33,7 +33,7 @@ void main() {
test('generateMainModule includes null safety switches', () { test('generateMainModule includes null safety switches', () {
final String result = generateMainModule( final String result = generateMainModule(
entrypoint: 'foo/bar/main.js', entrypoint: 'foo/bar/main.js',
nullSafety: true, nullAssertions: true,
); );
expect(result, contains( expect(result, contains(
......
...@@ -462,6 +462,7 @@ void main() { ...@@ -462,6 +462,7 @@ void main() {
urlTunneller: null, urlTunneller: null,
useSseForDebugProxy: true, useSseForDebugProxy: true,
useSseForDebugBackend: true, useSseForDebugBackend: true,
nullAssertions: true,
buildInfo: const BuildInfo( buildInfo: const BuildInfo(
BuildMode.debug, BuildMode.debug,
'', '',
...@@ -574,6 +575,7 @@ void main() { ...@@ -574,6 +575,7 @@ void main() {
urlTunneller: null, urlTunneller: null,
useSseForDebugProxy: true, useSseForDebugProxy: true,
useSseForDebugBackend: true, useSseForDebugBackend: true,
nullAssertions: true,
buildInfo: const BuildInfo( buildInfo: const BuildInfo(
BuildMode.debug, BuildMode.debug,
'', '',
...@@ -689,6 +691,7 @@ void main() { ...@@ -689,6 +691,7 @@ void main() {
testMode: true, testMode: true,
expressionCompiler: null, expressionCompiler: null,
chromiumLauncher: null, chromiumLauncher: null,
nullAssertions: true,
); );
webDevFS.requireJS.createSync(recursive: true); webDevFS.requireJS.createSync(recursive: true);
webDevFS.stackTraceMapper.createSync(recursive: true); webDevFS.stackTraceMapper.createSync(recursive: true);
...@@ -725,6 +728,7 @@ void main() { ...@@ -725,6 +728,7 @@ void main() {
urlTunneller: null, urlTunneller: null,
useSseForDebugProxy: true, useSseForDebugProxy: true,
useSseForDebugBackend: true, useSseForDebugBackend: true,
nullAssertions: true,
buildInfo: const BuildInfo( buildInfo: const BuildInfo(
BuildMode.debug, BuildMode.debug,
'', '',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment