Fix assertion violation in event loop tracking.

This commit is contained in:
John Preston 2020-06-29 21:27:32 +04:00
parent 0ede4bba72
commit 44e81269a3

View file

@ -469,10 +469,7 @@ uint64 Sandbox::installationTag() const {
return _launcher->installationTag(); return _launcher->installationTag();
} }
void Sandbox::postponeCall(FnMut<void()> &&callable) { void Sandbox::checkForEmptyLoopNestingLevel() {
Expects(callable != nullptr);
Expects(_eventNestingLevel >= _loopNestingLevel);
// _loopNestingLevel == _eventNestingLevel means that we had a // _loopNestingLevel == _eventNestingLevel means that we had a
// native event in a nesting loop that didn't get a notify() call // native event in a nesting loop that didn't get a notify() call
// after. That means we already have exited the nesting loop and // after. That means we already have exited the nesting loop and
@ -485,7 +482,13 @@ void Sandbox::postponeCall(FnMut<void()> &&callable) {
_loopNestingLevel = _previousLoopNestingLevels.back(); _loopNestingLevel = _previousLoopNestingLevels.back();
_previousLoopNestingLevels.pop_back(); _previousLoopNestingLevels.pop_back();
} }
}
void Sandbox::postponeCall(FnMut<void()> &&callable) {
Expects(callable != nullptr);
Expects(_eventNestingLevel >= _loopNestingLevel);
checkForEmptyLoopNestingLevel();
_postponedCalls.push_back({ _postponedCalls.push_back({
_loopNestingLevel, _loopNestingLevel,
std::move(callable) std::move(callable)
@ -497,16 +500,23 @@ void Sandbox::incrementEventNestingLevel() {
} }
void Sandbox::decrementEventNestingLevel() { void Sandbox::decrementEventNestingLevel() {
Expects(_eventNestingLevel >= _loopNestingLevel);
if (_eventNestingLevel == _loopNestingLevel) { if (_eventNestingLevel == _loopNestingLevel) {
_loopNestingLevel = _previousLoopNestingLevels.back(); _loopNestingLevel = _previousLoopNestingLevels.back();
_previousLoopNestingLevels.pop_back(); _previousLoopNestingLevels.pop_back();
} }
const auto processTillLevel = _eventNestingLevel - 1; const auto processTillLevel = _eventNestingLevel - 1;
processPostponedCalls(processTillLevel); processPostponedCalls(processTillLevel);
checkForEmptyLoopNestingLevel();
_eventNestingLevel = processTillLevel; _eventNestingLevel = processTillLevel;
Ensures(_eventNestingLevel >= _loopNestingLevel);
} }
void Sandbox::registerEnterFromEventLoop() { void Sandbox::registerEnterFromEventLoop() {
Expects(_eventNestingLevel >= _loopNestingLevel);
if (_eventNestingLevel > _loopNestingLevel) { if (_eventNestingLevel > _loopNestingLevel) {
_previousLoopNestingLevels.push_back(_loopNestingLevel); _previousLoopNestingLevels.push_back(_loopNestingLevel);
_loopNestingLevel = _eventNestingLevel; _loopNestingLevel = _eventNestingLevel;