Fix for consecutive calls to clearTestState()

This bug would only happen from Chrome debug mode, where consecutive calls would crash the app because the m_objects iterator would be in a bad state. This method is faster anyways.
This commit is contained in:
Scott Kyle 2016-05-26 17:58:02 -07:00
parent af70bb3c63
commit 5a3997d268
1 changed files with 8 additions and 5 deletions

View File

@ -182,15 +182,18 @@ RPCServer::RPCServer() {
return json::object();
};
m_requests["/clear_test_state"] = [this](const json dict) {
for (auto object : m_objects) {
// The session ID points to the Realm constructor object, which should remain.
if (object.first != m_session_id) {
m_objects.erase(object.first);
}
auto realm_constructor = m_objects[m_session_id];
m_objects.clear();
if (realm_constructor) {
m_objects.emplace(m_session_id, realm_constructor);
}
m_callbacks.clear();
JSGarbageCollect(m_context);
js::delete_all_realms();
return json::object();
};
}