mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix context.dart to properly handle nested zones (#7189)
This fixes an infinite loop in the code that walks the parent context chain looking for a variable. This also includes a fix in build_info.dart whereby if the context is set but the config is not yet set, we were trying to dereference null.
This commit is contained in:
parent
fc0b3ded43
commit
a4f2ad984d
@ -14,11 +14,13 @@ class AppContext {
|
||||
Map<Type, dynamic> _instances = <Type, dynamic>{};
|
||||
Zone _zone;
|
||||
|
||||
AppContext() : _zone = Zone.current;
|
||||
|
||||
bool isSet(Type type) {
|
||||
if (_instances.containsKey(type))
|
||||
return true;
|
||||
|
||||
AppContext parent = _calcParent(Zone.current);
|
||||
AppContext parent = _calcParent(_zone);
|
||||
return parent != null ? parent.isSet(type) : false;
|
||||
}
|
||||
|
||||
@ -26,7 +28,7 @@ class AppContext {
|
||||
if (_instances.containsKey(type))
|
||||
return _instances[type];
|
||||
|
||||
AppContext parent = _calcParent(_zone ?? Zone.current);
|
||||
AppContext parent = _calcParent(_zone);
|
||||
return parent?.getVariable(type);
|
||||
}
|
||||
|
||||
@ -51,12 +53,10 @@ class AppContext {
|
||||
if (parentZone == null)
|
||||
return null;
|
||||
|
||||
AppContext deps = parentZone['context'];
|
||||
if (deps == this) {
|
||||
return _calcParent(parentZone);
|
||||
} else {
|
||||
return deps;
|
||||
}
|
||||
AppContext parentContext = parentZone['context'];
|
||||
return parentContext == this
|
||||
? _calcParent(parentZone)
|
||||
: parentContext;
|
||||
}
|
||||
|
||||
dynamic runInZone(dynamic method(), {
|
||||
@ -70,11 +70,12 @@ class AppContext {
|
||||
}
|
||||
|
||||
dynamic _run(dynamic method()) async {
|
||||
Zone previousZone = _zone;
|
||||
try {
|
||||
_zone = Zone.current;
|
||||
return await method();
|
||||
} finally {
|
||||
_zone = null;
|
||||
_zone = previousZone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ HostPlatform getCurrentHostPlatform() {
|
||||
String getBuildDirectory() {
|
||||
// TODO(johnmccutchan): Stop calling this function as part of setting
|
||||
// up command line argument processing.
|
||||
if (context == null)
|
||||
if (context == null || config == null)
|
||||
return 'build';
|
||||
|
||||
String buildDir = config.getValue('build-dir') ?? 'build';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user