Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
9e5c8771
Unverified
Commit
9e5c8771
authored
Dec 03, 2020
by
Jonah Williams
Committed by
GitHub
Dec 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] wire up native-null-assertions for flutter web (#71618)
parent
088b7c36
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
100 additions
and
7 deletions
+100
-7
web.dart
packages/flutter_tools/lib/src/build_system/targets/web.dart
+6
-0
build_web.dart
packages/flutter_tools/lib/src/commands/build_web.dart
+2
-0
run.dart
packages/flutter_tools/lib/src/commands/run.dart
+2
-0
device.dart
packages/flutter_tools/lib/src/device.dart
+9
-1
devfs_web.dart
packages/flutter_tools/lib/src/isolated/devfs_web.dart
+3
-0
resident_web_runner.dart
...s/flutter_tools/lib/src/isolated/resident_web_runner.dart
+3
-0
flutter_command.dart
packages/flutter_tools/lib/src/runner/flutter_command.dart
+13
-0
flutter_web_platform.dart
...ages/flutter_tools/lib/src/test/flutter_web_platform.dart
+1
-0
bootstrap.dart
packages/flutter_tools/lib/src/web/bootstrap.dart
+3
-3
compile.dart
packages/flutter_tools/lib/src/web/compile.dart
+2
-0
build_web_test.dart
...er_tools/test/commands.shard/hermetic/build_web_test.dart
+1
-0
web_test.dart
...ols/test/general.shard/build_system/targets/web_test.dart
+34
-0
bootstrap_test.dart
.../flutter_tools/test/general.shard/web/bootstrap_test.dart
+16
-3
devfs_web_test.dart
.../flutter_tools/test/general.shard/web/devfs_web_test.dart
+5
-0
No files found.
packages/flutter_tools/lib/src/build_system/targets/web.dart
View file @
9e5c8771
...
...
@@ -39,6 +39,9 @@ const String kServiceWorkerStrategy = 'ServiceWorkerStrategy';
/// Whether the dart2js build should output source maps.
const
String
kSourceMapsEnabled
=
'SourceMaps'
;
/// Whether the dart2js native null assertions are enabled.
const
String
kNativeNullAssertions
=
'NativeNullAssertions'
;
/// The caching strategy for the generated service worker.
enum
ServiceWorkerStrategy
{
/// Download the app shell eagerly and all other assets lazily.
...
...
@@ -190,6 +193,7 @@ class Dart2JSTarget extends Target {
Future
<
void
>
build
(
Environment
environment
)
async
{
final
BuildMode
buildMode
=
getBuildModeForName
(
environment
.
defines
[
kBuildMode
]);
final
bool
sourceMapsEnabled
=
environment
.
defines
[
kSourceMapsEnabled
]
==
'true'
;
final
bool
nativeNullAssertions
=
environment
.
defines
[
kNativeNullAssertions
]
==
'true'
;
final
List
<
String
>
sharedCommandOptions
=
<
String
>[
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
engineDartBinary
),
...
...
@@ -197,6 +201,8 @@ class Dart2JSTarget extends Target {
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
dart2jsSnapshot
),
'--libraries-spec=
${globals.fs.path.join(globals.artifacts.getArtifactPath(Artifact.flutterWebSdk), 'libraries.json')}
'
,
...?
decodeDartDefines
(
environment
.
defines
,
kExtraFrontEndOptions
),
if
(
nativeNullAssertions
)
'--native-null-assertions'
,
if
(
buildMode
==
BuildMode
.
profile
)
'-Ddart.vm.profile=true'
else
...
...
packages/flutter_tools/lib/src/commands/build_web.dart
View file @
9e5c8771
...
...
@@ -26,6 +26,7 @@ class BuildWebCommand extends BuildSubCommand {
usesWebRendererOption
();
addEnableExperimentation
(
hide:
!
verboseHelp
);
addNullSafetyModeOptions
(
hide:
!
verboseHelp
);
addNativeNullAssertions
(
hide:
false
);
argParser
.
addFlag
(
'csp'
,
defaultsTo:
false
,
negatable:
false
,
...
...
@@ -90,6 +91,7 @@ class BuildWebCommand extends BuildSubCommand {
boolArg
(
'csp'
),
stringArg
(
'pwa-strategy'
),
boolArg
(
'source-maps'
),
boolArg
(
'native-null-assertions'
),
);
return
FlutterCommandResult
.
success
();
}
...
...
packages/flutter_tools/lib/src/commands/run.dart
View file @
9e5c8771
...
...
@@ -30,6 +30,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
usesDartDefineOption
();
usesFlavorOption
();
usesWebRendererOption
();
addNativeNullAssertions
(
hide:
!
verboseHelp
);
argParser
..
addFlag
(
'trace-startup'
,
negatable:
false
,
...
...
@@ -205,6 +206,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
&&
boolArg
(
'fast-start'
)
&&
!
runningWithPrebuiltApplication
,
nullAssertions:
boolArg
(
'null-assertions'
),
nativeNullAssertions:
boolArg
(
'native-null-assertions'
),
);
}
}
...
...
packages/flutter_tools/lib/src/device.dart
View file @
9e5c8771
...
...
@@ -863,6 +863,7 @@ class DebuggingOptions {
this
.
vmserviceOutFile
,
this
.
fastStart
=
false
,
this
.
nullAssertions
=
false
,
this
.
nativeNullAssertions
=
false
,
})
:
debuggingEnabled
=
true
;
DebuggingOptions
.
disabled
(
this
.
buildInfo
,
{
...
...
@@ -897,7 +898,8 @@ class DebuggingOptions {
vmserviceOutFile
=
null
,
fastStart
=
false
,
webEnableExpressionEvaluation
=
false
,
nullAssertions
=
false
;
nullAssertions
=
false
,
nativeNullAssertions
=
false
;
final
bool
debuggingEnabled
;
...
...
@@ -947,6 +949,12 @@ class DebuggingOptions {
final
bool
nullAssertions
;
/// Additional null runtime checks inserted for web applications.
///
/// See also:
/// * https://github.com/dart-lang/sdk/blob/master/sdk/lib/html/doc/NATIVE_NULL_ASSERTIONS.md
final
bool
nativeNullAssertions
;
bool
get
hasObservatoryPort
=>
hostVmServicePort
!=
null
;
}
...
...
packages/flutter_tools/lib/src/isolated/devfs_web.dart
View file @
9e5c8771
...
...
@@ -605,6 +605,7 @@ class WebDevFS implements DevFS {
@required
this
.
expressionCompiler
,
@required
this
.
chromiumLauncher
,
@required
this
.
nullAssertions
,
@required
this
.
nativeNullAssertions
,
@required
this
.
nullSafetyMode
,
this
.
testMode
=
false
,
})
:
_port
=
port
;
...
...
@@ -621,6 +622,7 @@ class WebDevFS implements DevFS {
final
ExpressionCompiler
expressionCompiler
;
final
ChromiumLauncher
chromiumLauncher
;
final
bool
nullAssertions
;
final
bool
nativeNullAssertions
;
final
int
_port
;
final
NullSafetyMode
nullSafetyMode
;
...
...
@@ -779,6 +781,7 @@ class WebDevFS implements DevFS {
generateMainModule
(
entrypoint:
entrypoint
,
nullAssertions:
nullAssertions
,
nativeNullAssertions:
nativeNullAssertions
,
),
);
// TODO(jonahwilliams): refactor the asset code in this and the regular devfs to
...
...
packages/flutter_tools/lib/src/isolated/resident_web_runner.dart
View file @
9e5c8771
...
...
@@ -501,6 +501,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
chromiumLauncher:
_chromiumLauncher
,
nullAssertions:
debuggingOptions
.
nullAssertions
,
nullSafetyMode:
debuggingOptions
.
buildInfo
.
nullSafetyMode
,
nativeNullAssertions:
debuggingOptions
.
nativeNullAssertions
,
);
final
Uri
url
=
await
device
.
devFS
.
create
();
if
(
debuggingOptions
.
buildInfo
.
isDebug
)
{
...
...
@@ -520,6 +521,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
false
,
kNoneWorker
,
true
,
debuggingOptions
.
nativeNullAssertions
,
);
}
await
device
.
device
.
startApp
(
...
...
@@ -587,6 +589,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
false
,
kNoneWorker
,
true
,
debuggingOptions
.
nativeNullAssertions
,
);
}
on
ToolExit
{
return
OperationResult
(
1
,
'Failed to recompile application.'
);
...
...
packages/flutter_tools/lib/src/runner/flutter_command.dart
View file @
9e5c8771
...
...
@@ -674,6 +674,19 @@ abstract class FlutterCommand extends Command<void> {
);
}
void
addNativeNullAssertions
({
bool
hide
=
false
})
{
argParser
.
addFlag
(
'native-null-assertions'
,
defaultsTo:
true
,
hide:
hide
,
help:
'Enables additional runtime null checks in web applications to ensure '
'the correct nullability of native (such as in dart:html) and external '
'(such as with JS interop) types. This is enabled by default but only takes '
'effect in sound mode. To report an issue with a null assertion failure in '
'dart:html or the other dart web libraries, please file a bug at '
'https://github.com/dart-lang/sdk/issues/labels/web-libraries .'
);
}
/// Adds build options common to all of the desktop build commands.
void
addCommonDesktopBuildOptions
({
bool
verboseHelp
=
false
})
{
addBuildModeFlags
(
verboseHelp:
verboseHelp
);
...
...
packages/flutter_tools/lib/src/test/flutter_web_platform.dart
View file @
9e5c8771
...
...
@@ -224,6 +224,7 @@ class FlutterWebPlatform extends PlatformPlugin {
final
String
generatedFile
=
_fileSystem
.
path
.
split
(
leadingPath
).
join
(
'_'
)
+
'.dart.test.dart.js'
;
return
shelf
.
Response
.
ok
(
generateMainModule
(
nullAssertions:
nullAssertions
,
nativeNullAssertions:
true
,
bootstrapModule:
_fileSystem
.
path
.
basename
(
leadingPath
)
+
'.dart.bootstrap'
,
entrypoint:
'/'
+
generatedFile
),
headers:
<
String
,
String
>{
...
...
packages/flutter_tools/lib/src/web/bootstrap.dart
View file @
9e5c8771
...
...
@@ -54,6 +54,7 @@ document.head.appendChild(requireEl);
String
generateMainModule
(
{
@required
String
entrypoint
,
@required
bool
nullAssertions
,
@required
bool
nativeNullAssertions
,
String
bootstrapModule
=
'main_module.bootstrap'
,
})
{
// TODO(jonahwilliams): fix typo in dwds and update.
...
...
@@ -63,9 +64,8 @@ String generateMainModule({
define("
$bootstrapModule
", ["
$entrypoint
", "dart_sdk"], function(app, dart_sdk) {
dart_sdk.dart.setStartAsyncSynchronously(true);
dart_sdk._debugger.registerDevtoolsFormatter();
if (
$nullAssertions
) {
dart_sdk.dart.nonNullAsserts(true);
}
dart_sdk.dart.nonNullAsserts(
$nullAssertions
);
dart_sdk.dart.nativeNonNullAsserts(
$nativeNullAssertions
);
// See the generateMainModule doc comment.
var child = {};
...
...
packages/flutter_tools/lib/src/web/compile.dart
View file @
9e5c8771
...
...
@@ -24,6 +24,7 @@ Future<void> buildWeb(
bool
csp
,
String
serviceWorkerStrategy
,
bool
sourceMaps
,
bool
nativeNullAssertions
,
)
async
{
if
(!
flutterProject
.
web
.
existsSync
())
{
throwToolExit
(
'Missing index.html.'
);
...
...
@@ -51,6 +52,7 @@ Future<void> buildWeb(
kCspMode:
csp
.
toString
(),
kIconTreeShakerFlag:
buildInfo
.
treeShakeIcons
.
toString
(),
kSourceMapsEnabled:
sourceMaps
.
toString
(),
kNativeNullAssertions:
nativeNullAssertions
.
toString
(),
if
(
serviceWorkerStrategy
!=
null
)
kServiceWorkerStrategy:
serviceWorkerStrategy
,
if
(
buildInfo
.
extraFrontEndOptions
?.
isNotEmpty
??
false
)
...
...
packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
View file @
9e5c8771
...
...
@@ -56,6 +56,7 @@ void main() {
false
,
null
,
true
,
true
,
),
throwsToolExit
());
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
fakePlatform
,
...
...
packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
View file @
9e5c8771
...
...
@@ -392,6 +392,40 @@ void main() {
ProcessManager:
()
=>
processManager
,
}));
test
(
'Dart2JSTarget calls dart2js with expected args in release mode with native null assertions'
,
()
=>
testbed
.
run
(()
async
{
environment
.
defines
[
kBuildMode
]
=
'release'
;
environment
.
defines
[
kNativeNullAssertions
]
=
'true'
;
processManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
...
kDart2jsLinuxArgs
,
'--native-null-assertions'
,
'-Ddart.vm.product=true'
,
'--no-source-maps'
,
'-o'
,
environment
.
buildDir
.
childFile
(
'app.dill'
).
absolute
.
path
,
'--packages=.packages'
,
'--cfe-only'
,
environment
.
buildDir
.
childFile
(
'main.dart'
).
absolute
.
path
,
]
));
processManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
...
kDart2jsLinuxArgs
,
'--native-null-assertions'
,
'-Ddart.vm.product=true'
,
'--no-source-maps'
,
'-O4'
,
'-o'
,
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
absolute
.
path
,
environment
.
buildDir
.
childFile
(
'app.dill'
).
absolute
.
path
,
]
));
await
const
Dart2JSTarget
().
build
(
environment
);
},
overrides:
<
Type
,
Generator
>{
ProcessManager:
()
=>
processManager
,
}));
test
(
'Dart2JSTarget calls dart2js with expected args in release with dart2js optimization override'
,
()
=>
testbed
.
run
(()
async
{
environment
.
defines
[
kBuildMode
]
=
'release'
;
environment
.
defines
[
kDart2jsOptimization
]
=
'O3'
;
...
...
packages/flutter_tools/test/general.shard/web/bootstrap_test.dart
View file @
9e5c8771
...
...
@@ -24,6 +24,7 @@ void main() {
final
String
result
=
generateMainModule
(
entrypoint:
'foo/bar/main.js'
,
nullAssertions:
false
,
nativeNullAssertions:
false
,
);
// bootstrap main module has correct defined module.
expect
(
result
,
contains
(
'define("main_module.bootstrap", ["foo/bar/main.js", "dart_sdk"], '
...
...
@@ -34,6 +35,7 @@ void main() {
final
String
result
=
generateMainModule
(
entrypoint:
'foo/bar/main.js'
,
nullAssertions:
false
,
nativeNullAssertions:
false
,
bootstrapModule:
'foo_module.bootstrap'
,
);
// bootstrap main module has correct defined module.
...
...
@@ -45,11 +47,22 @@ void main() {
final
String
result
=
generateMainModule
(
entrypoint:
'foo/bar/main.js'
,
nullAssertions:
true
,
nativeNullAssertions:
true
,
);
expect
(
result
,
contains
(
'''
if (true) {
dart_sdk.dart.nonNullAsserts(true);'''
));
expect
(
result
,
contains
(
'''dart_sdk.dart.nonNullAsserts(true);'''
));
expect
(
result
,
contains
(
'''dart_sdk.dart.nativeNonNullAsserts(true);'''
));
});
test
(
'generateMainModule can disable null safety switches'
,
()
{
final
String
result
=
generateMainModule
(
entrypoint:
'foo/bar/main.js'
,
nullAssertions:
false
,
nativeNullAssertions:
false
,
);
expect
(
result
,
contains
(
'''dart_sdk.dart.nonNullAsserts(false);'''
));
expect
(
result
,
contains
(
'''dart_sdk.dart.nativeNonNullAsserts(false);'''
));
});
test
(
'generateTestBootstrapFileContents embeds urls correctly'
,
()
{
...
...
packages/flutter_tools/test/general.shard/web/devfs_web_test.dart
View file @
9e5c8771
...
...
@@ -617,6 +617,7 @@ void main() {
useSseForDebugProxy:
true
,
useSseForDebugBackend:
true
,
nullAssertions:
true
,
nativeNullAssertions:
true
,
buildInfo:
const
BuildInfo
(
BuildMode
.
debug
,
''
,
...
...
@@ -732,6 +733,7 @@ void main() {
useSseForDebugProxy:
true
,
useSseForDebugBackend:
true
,
nullAssertions:
true
,
nativeNullAssertions:
true
,
buildInfo:
const
BuildInfo
(
BuildMode
.
debug
,
''
,
...
...
@@ -850,6 +852,7 @@ void main() {
expressionCompiler:
null
,
chromiumLauncher:
null
,
nullAssertions:
true
,
nativeNullAssertions:
true
,
nullSafetyMode:
NullSafetyMode
.
sound
,
);
webDevFS
.
requireJS
.
createSync
(
recursive:
true
);
...
...
@@ -886,6 +889,7 @@ void main() {
useSseForDebugProxy:
true
,
useSseForDebugBackend:
true
,
nullAssertions:
true
,
nativeNullAssertions:
true
,
buildInfo:
const
BuildInfo
(
BuildMode
.
debug
,
''
,
...
...
@@ -936,6 +940,7 @@ void main() {
useSseForDebugProxy:
true
,
useSseForDebugBackend:
true
,
nullAssertions:
true
,
nativeNullAssertions:
true
,
buildInfo:
const
BuildInfo
(
BuildMode
.
debug
,
''
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment