Commit a4f2ad98 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

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.
parent fc0b3ded
......@@ -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';
......
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