Last active
November 26, 2019 03:08
-
-
Save deepak1556/f9ce7fd4d695361f1568c787affa3795 to your computer and use it in GitHub Desktop.
Debugging Async/Await crash with electron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
</body> | |
<script> | |
class Foo { | |
constructor() { | |
document.body.addEventListener('click', () => { | |
this.foo(); | |
}); | |
} | |
async foo() { | |
document.title = "test"; // Triggers `page-title-updated` event in main process which queues a ipc for our POC | |
await this.foo2(); // set breakpoint in this line | |
await this.foo2(); | |
} | |
async foo2() { | |
return Promise.resolve(); | |
} | |
} | |
new Foo(); | |
</script> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {app, BrowserWindow} = require('electron') | |
const path = require('path') | |
let mainWindow | |
function createWindow () { | |
mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
nodeIntegration: true | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
mainWindow.webContents.on('page-title-updated', () => { | |
// This will trigger the Microtasks after exiting the CallbackScope | |
// in InvokeIpcCallback under electron_api_service_impl.cc | |
// which causes the pending promises to fulfill when debug is paused | |
// and crashes in v8 with EXC_BAD_ACCESS | |
mainWindow.webContents.send('test') | |
}) | |
mainWindow.on('closed', function () { | |
mainWindow = null | |
}) | |
} | |
app.on('ready', createWindow) | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') app.quit() | |
}) | |
app.on('activate', function () { | |
if (mainWindow === null) createWindow() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment