api-web-contents-view-spec.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { closeWindow } from './window-helpers';
  2. import { BaseWindow, WebContentsView } from 'electron/main';
  3. describe('WebContentsView', () => {
  4. let w: BaseWindow;
  5. afterEach(() => closeWindow(w as any).then(() => { w = null as unknown as BaseWindow; }));
  6. it('can be used as content view', () => {
  7. w = new BaseWindow({ show: false });
  8. w.setContentView(new WebContentsView({}));
  9. });
  10. function triggerGCByAllocation () {
  11. const arr = [];
  12. for (let i = 0; i < 1000000; i++) {
  13. arr.push([]);
  14. }
  15. return arr;
  16. }
  17. it('doesn\'t crash when GCed during allocation', (done) => {
  18. // eslint-disable-next-line no-new
  19. new WebContentsView({});
  20. setTimeout(() => {
  21. // NB. the crash we're testing for is the lack of a current `v8::Context`
  22. // when emitting an event in WebContents's destructor. V8 is inconsistent
  23. // about whether or not there's a current context during garbage
  24. // collection, and it seems that `v8Util.requestGarbageCollectionForTesting`
  25. // causes a GC in which there _is_ a current context, so the crash isn't
  26. // triggered. Thus, we force a GC by other means: namely, by allocating a
  27. // bunch of stuff.
  28. triggerGCByAllocation();
  29. done();
  30. });
  31. });
  32. });