Track the last component to build

...rather than the stack trace at the time the RenderObjectWrapper updates the RenderObject.

Also, hide some of the debug-only fields behind "debug" prefixes and assert()s.
This commit is contained in:
Hixie 2015-08-24 16:10:47 -07:00
parent 1393b4c6b0
commit 670f3cd7c9

View File

@ -638,7 +638,8 @@ abstract class Component extends Widget {
: _order = _currentOrder + 1, : _order = _currentOrder + 1,
super._withKey(key); super._withKey(key);
bool _isBuilding = false; bool _debugIsBuilding = false;
static String _debugLastComponent;
bool _dirty = true; bool _dirty = true;
@ -702,7 +703,16 @@ abstract class Component extends Widget {
oldChild = old._child; oldChild = old._child;
} }
_isBuilding = true; String _debugPreviousComponent;
assert(() {
_debugIsBuilding = true;
_debugPreviousComponent = _debugLastComponent;
if (_debugLastComponent != null)
_debugLastComponent = "$_debugPreviousComponent -> ${this.toStringName()}";
else
_debugLastComponent = "Build chain: ${this.toStringName()}";
return true;
});
int lastOrder = _currentOrder; int lastOrder = _currentOrder;
_currentOrder = _order; _currentOrder = _order;
@ -712,7 +722,12 @@ abstract class Component extends Widget {
_child = syncChild(_child, oldChild, slot); _child = syncChild(_child, oldChild, slot);
assert(_child != null); assert(_child != null);
assert(_child.parent == this); assert(_child.parent == this);
_isBuilding = false;
assert(() {
_debugIsBuilding = false;
_debugLastComponent = _debugPreviousComponent;
return true;
});
_dirty = false; _dirty = false;
_renderObject = _child.renderObject; _renderObject = _child.renderObject;
@ -729,7 +744,7 @@ abstract class Component extends Widget {
} }
void _scheduleBuild() { void _scheduleBuild() {
assert(!_isBuilding); assert(!_debugIsBuilding);
if (_dirty || !_mounted) if (_dirty || !_mounted)
return; return;
_dirty = true; _dirty = true;
@ -956,13 +971,10 @@ abstract class RenderObjectWrapper extends Widget {
_ancestor = old._ancestor; _ancestor = old._ancestor;
assert(_renderObject != null); assert(_renderObject != null);
} }
if (inDebugBuild) { assert(() {
try { _renderObject.debugExceptionContext = Component._debugLastComponent;
throw null; return true;
} catch (_, stack) { });
_renderObject.debugExceptionContext = stack;
}
}
assert(_renderObject == renderObject); // in case a subclass reintroduces it assert(_renderObject == renderObject); // in case a subclass reintroduces it
assert(renderObject != null); assert(renderObject != null);
assert(mounted); assert(mounted);