Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash when using vm after window.open() #37506

Closed
wants to merge 1 commit into from

fix: crash when using vm after window.open()

0ff6c2a
Select commit
Failed to load commit list.
Closed

fix: crash when using vm after window.open() #37506

fix: crash when using vm after window.open()
0ff6c2a
Select commit
Failed to load commit list.
This check has been archived and is scheduled for deletion. Learn more about checks retention
trop / Backportable? - 24-x-y completed Apr 6, 2023 in 31d 1h 7m 13s

Backport Failed

This PR was checked and could not be automatically backported to "24-x-y" cleanly

Details

Failed Diff:

diff --cc spec/guest-window-manager-spec.ts
index 2e96f32e1a,159771d18f..0000000000
--- a/spec/guest-window-manager-spec.ts
+++ b/spec/guest-window-manager-spec.ts
@@@ -173,20 -173,48 +173,53 @@@ describe('webContents.setWindowOpenHand
        browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true");
      });
  
 -    await once(browserWindow.webContents, 'did-create-window');
 +    await emittedOnce(browserWindow.webContents, 'did-create-window');
    });
  
++<<<<<<< HEAD
 +  it('can change webPreferences of child windows', (done) => {
++=======
+   it('does not crash when used in conjunction with the vm module', async () => {
+     const w = new BrowserWindow({
+       show: false,
+       webPreferences: {
+         contextIsolation: false,
+         nodeIntegration: true
+       }
+     });
+ 
+     await w.loadURL('about:blank');
+ 
+     const didCreateWindow = once(w.webContents, 'did-create-window');
+     w.webContents.executeJavaScript("window.open('')");
+     await didCreateWindow;
+ 
+     const result = await w.webContents.executeJavaScript(`
+       const vm = require('node:vm')
+       const run = () => {
+           const context = { x: 2 }
+           vm.createContext(context)
+           vm.runInContext('x += 40', context)
+           return context.x
+       }
+       run()
+     `);
+ 
+     expect(result).to.equal(42);
+   });
+ 
+   it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()
      browserWindow.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { defaultFontSize: 30 } } }));
  
 -    const didCreateWindow = once(browserWindow.webContents, 'did-create-window');
 -    browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true");
 -    const [childWindow] = await didCreateWindow;
 +    browserWindow.webContents.on('did-create-window', async (childWindow) => {
 +      await childWindow.webContents.executeJavaScript("document.write('hello')");
 +      const size = await childWindow.webContents.executeJavaScript("getComputedStyle(document.querySelector('body')).fontSize");
 +      expect(size).to.equal('30px');
 +      done();
 +    });
  
 -    await childWindow.webContents.executeJavaScript("document.write('hello')");
 -    const size = await childWindow.webContents.executeJavaScript("getComputedStyle(document.querySelector('body')).fontSize");
 -    expect(size).to.equal('30px');
 +    browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true");
    });
  
    it('does not hang parent window when denying window.open', async () => {

Annotations

Check failure on line 180 in spec/guest-window-manager-spec.ts

See this annotation in the file changed.

@trop trop / Backportable? - 24-x-y

spec/guest-window-manager-spec.ts#L180

Patch Conflict
Raw output
++<<<<<<< HEAD
 +  it('can change webPreferences of child windows', (done) => {
++=======
+   it('does not crash when used in conjunction with the vm module', async () => {
+     const w = new BrowserWindow({
+       show: false,
+       webPreferences: {
+         contextIsolation: false,
+         nodeIntegration: true
+       }
+     });
+ 
+     await w.loadURL('about:blank');
+ 
+     const didCreateWindow = once(w.webContents, 'did-create-window');
+     w.webContents.executeJavaScript("window.open('')");
+     await didCreateWindow;
+ 
+     const result = await w.webContents.executeJavaScript(`
+       const vm = require('node:vm')
+       const run = () => {
+           const context = { x: 2 }
+           vm.createContext(context)
+           vm.runInContext('x += 40', context)
+           return context.x
+       }
+       run()
+     `);
+ 
+     expect(result).to.equal(42);
+   });
+ 
+   it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()

Check failure on line 180 in spec/guest-window-manager-spec.ts

See this annotation in the file changed.

@trop trop / Backportable? - 24-x-y

spec/guest-window-manager-spec.ts#L180

Patch Conflict
Raw output
++<<<<<<< HEAD
 +  it('can change webPreferences of child windows', (done) => {
++=======
+   it('does not crash when used in conjunction with the vm module', async () => {
+     const w = new BrowserWindow({
+       show: false,
+       webPreferences: {
+         contextIsolation: false,
+         nodeIntegration: true
+       }
+     });
+ 
+     await w.loadURL('about:blank');
+ 
+     const didCreateWindow = once(w.webContents, 'did-create-window');
+     w.webContents.executeJavaScript("window.open('')");
+     await didCreateWindow;
+ 
+     const result = await w.webContents.executeJavaScript(`
+       const vm = require('node:vm')
+       const run = () => {
+           const context = { x: 2 }
+           vm.createContext(context)
+           vm.runInContext('x += 40', context)
+           return context.x
+       }
+       run()
+     `);
+ 
+     expect(result).to.equal(42);
+   });
+ 
+   it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()

Check failure on line 180 in spec/guest-window-manager-spec.ts

See this annotation in the file changed.

@trop trop / Backportable? - 24-x-y

spec/guest-window-manager-spec.ts#L180

Patch Conflict
Raw output
++<<<<<<< HEAD
 +  it('can change webPreferences of child windows', (done) => {
++=======
+   it('does not crash when used in conjunction with the vm module', async () => {
+     const w = new BrowserWindow({
+       show: false,
+       webPreferences: {
+         contextIsolation: false,
+         nodeIntegration: true
+       }
+     });
+ 
+     await w.loadURL('about:blank');
+ 
+     const didCreateWindow = once(w.webContents, 'did-create-window');
+     w.webContents.executeJavaScript("window.open('')");
+     await didCreateWindow;
+ 
+     const result = await w.webContents.executeJavaScript(`
+       const vm = require('node:vm')
+       const run = () => {
+           const context = { x: 2 }
+           vm.createContext(context)
+           vm.runInContext('x += 40', context)
+           return context.x
+       }
+       run()
+     `);
+ 
+     expect(result).to.equal(42);
+   });
+ 
+   it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()

Check failure on line 180 in spec/guest-window-manager-spec.ts

See this annotation in the file changed.

@trop trop / Backportable? - 24-x-y

spec/guest-window-manager-spec.ts#L180

Patch Conflict
Raw output
++<<<<<<< HEAD
 +  it('can change webPreferences of child windows', (done) => {
++=======
+   it('does not crash when used in conjunction with the vm module', async () => {
+     const w = new BrowserWindow({
+       show: false,
+       webPreferences: {
+         contextIsolation: false,
+         nodeIntegration: true
+       }
+     });
+ 
+     await w.loadURL('about:blank');
+ 
+     const didCreateWindow = once(w.webContents, 'did-create-window');
+     w.webContents.executeJavaScript("window.open('')");
+     await didCreateWindow;
+ 
+     const result = await w.webContents.executeJavaScript(`
+       const vm = require('node:vm')
+       const run = () => {
+           const context = { x: 2 }
+           vm.createContext(context)
+           vm.runInContext('x += 40', context)
+           return context.x
+       }
+       run()
+     `);
+ 
+     expect(result).to.equal(42);
+   });
+ 
+   it('can change webPreferences of child windows', async () => {
++>>>>>>> fix: crash when using vm after window.open()