Skip to content

Commit

Permalink
fix: exit event
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Sep 13, 2022
1 parent 0403176 commit b669d3f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions shell/browser/api/electron_api_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "shell/app/command_line_args.h"
#include "shell/browser/api/electron_api_menu.h"
#include "shell/browser/api/electron_api_session.h"
#include "shell/browser/api/electron_api_utility_process.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/browser/api/gpuinfo_manager.h"
#include "shell/browser/electron_browser_context.h"
Expand Down Expand Up @@ -921,6 +922,12 @@ void App::BrowserChildProcessCrashedOrKilled(
if (!data.name.empty()) {
details.Set("name", data.name);
}
if (data.process_type == content::PROCESS_TYPE_UTILITY) {
base::ProcessId pid = data.GetProcess().Pid();
auto* utility_process_wrapper = GetAllUtilityProcessWrappers().Lookup(pid);
if (utility_process_wrapper)
utility_process_wrapper->Emit("exit", info.exit_code);
}
Emit("child-process-gone", details);
}

Expand Down
16 changes: 16 additions & 0 deletions spec/api-utility-process-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ describe('UtilityProcess module', () => {
const [, code] = await emittedOnce(child, 'exit');
expect(code).to.equal(0);
});

it('emits \'exit\' when child process crashes', async () => {
const child = new UtilityProcess(path.join(fixturesPath, 'crash.js'));
const [, code] = await emittedOnce(child, 'exit');
expect(code).to.equal(11);
});

it('emits \'exit\' corresponding to the child process', async () => {
const child1 = new UtilityProcess(path.join(fixturesPath, 'endless.js'));
await emittedOnce(child1, 'spawn');
const child2 = new UtilityProcess(path.join(fixturesPath, 'crash.js'));
const [, code] = await emittedOnce(child2, 'exit');
expect(code).to.equal(11);
expect(child1.kill()).to.be.true();
await emittedOnce(child1, 'exit');
});
});

describe('kill() API', () => {
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/api/utility-process/crash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.crash();

0 comments on commit b669d3f

Please sign in to comment.