Fix potential RTE caused by setting (saved) profiling data while profiling is in progress

This commit is contained in:
Brian Vaughn
2019-05-23 14:49:47 -07:00
parent 395c02567c
commit 408fbee23b
2 changed files with 24 additions and 0 deletions
+17
View File
@@ -54,4 +54,21 @@ describe('ProfilerStore', () => {
expect(store.profilerStore.getDataForRoot(rootB)).not.toBeNull();
});
it('should not allow new/saved profiling data to be set while profiling is in progress', () => {
utils.act(() => store.profilerStore.startProfiling());
const fauxProfilingData = {
dataForRoots: new Map(),
};
spyOn(console, 'warn');
store.profilerStore.profilingData = fauxProfilingData;
expect(store.profilerStore.profilingData).not.toBe(fauxProfilingData);
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
'Profiling data cannot be updated while profiling is in progress.'
);
utils.act(() => store.profilerStore.stopProfiling());
store.profilerStore.profilingData = fauxProfilingData;
expect(store.profilerStore.profilingData).toBe(fauxProfilingData);
});
});
+7
View File
@@ -144,6 +144,13 @@ export default class ProfilerStore extends EventEmitter {
return this._dataFrontend;
}
set profilingData(value: ProfilingDataFrontend | null): void {
if (this._isProfiling) {
console.warn(
'Profiling data cannot be updated while profiling is in progress.'
);
return;
}
this._dataBackends.splice(0);
this._dataFrontend = value;
this._initialRendererIDs.clear();