fix: prevent crash on web-contents creation when error is thrown (#28971)
* fix: prevent crash when error occurs during event emitter CallMethod * wip: emit error event within trycatch * fix: handle uncaught exceptions within node on web_contents init * fix: create gin_helper::CallMethodCatchException * test: add web-contents create crash to test cases * test: clean up test data for web-contents crash Co-authored-by: Jeremy Rose <jeremya@chromium.org> * fix: convert CatchException to WebContents static helper method * fix: restore try_catch to callsite Co-authored-by: Jeremy Rose <jeremya@chromium.org>
This commit is contained in:
parent
82946133b1
commit
06f51b7283
3 changed files with 27 additions and 0 deletions
|
@ -3708,7 +3708,11 @@ gin::Handle<WebContents> WebContents::New(
|
||||||
const gin_helper::Dictionary& options) {
|
const gin_helper::Dictionary& options) {
|
||||||
gin::Handle<WebContents> handle =
|
gin::Handle<WebContents> handle =
|
||||||
gin::CreateHandle(isolate, new WebContents(isolate, options));
|
gin::CreateHandle(isolate, new WebContents(isolate, options));
|
||||||
|
v8::TryCatch try_catch(isolate);
|
||||||
gin_helper::CallMethod(isolate, handle.get(), "_init");
|
gin_helper::CallMethod(isolate, handle.get(), "_init");
|
||||||
|
if (try_catch.HasCaught()) {
|
||||||
|
node::errors::TriggerUncaughtException(isolate, try_catch);
|
||||||
|
}
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3719,7 +3723,11 @@ gin::Handle<WebContents> WebContents::CreateAndTake(
|
||||||
Type type) {
|
Type type) {
|
||||||
gin::Handle<WebContents> handle = gin::CreateHandle(
|
gin::Handle<WebContents> handle = gin::CreateHandle(
|
||||||
isolate, new WebContents(isolate, std::move(web_contents), type));
|
isolate, new WebContents(isolate, std::move(web_contents), type));
|
||||||
|
v8::TryCatch try_catch(isolate);
|
||||||
gin_helper::CallMethod(isolate, handle.get(), "_init");
|
gin_helper::CallMethod(isolate, handle.get(), "_init");
|
||||||
|
if (try_catch.HasCaught()) {
|
||||||
|
node::errors::TriggerUncaughtException(isolate, try_catch);
|
||||||
|
}
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3739,7 +3747,11 @@ gin::Handle<WebContents> WebContents::FromOrCreate(
|
||||||
WebContents* api_web_contents = From(web_contents);
|
WebContents* api_web_contents = From(web_contents);
|
||||||
if (!api_web_contents) {
|
if (!api_web_contents) {
|
||||||
api_web_contents = new WebContents(isolate, web_contents);
|
api_web_contents = new WebContents(isolate, web_contents);
|
||||||
|
v8::TryCatch try_catch(isolate);
|
||||||
gin_helper::CallMethod(isolate, api_web_contents, "_init");
|
gin_helper::CallMethod(isolate, api_web_contents, "_init");
|
||||||
|
if (try_catch.HasCaught()) {
|
||||||
|
node::errors::TriggerUncaughtException(isolate, try_catch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return gin::CreateHandle(isolate, api_web_contents);
|
return gin::CreateHandle(isolate, api_web_contents);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "node_buffer.h"
|
#include "node_buffer.h"
|
||||||
|
#include "node_errors.h"
|
||||||
#include "node_internals.h"
|
#include "node_internals.h"
|
||||||
#include "node_options-inl.h"
|
#include "node_options-inl.h"
|
||||||
#include "node_options.h"
|
#include "node_options.h"
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
const { app, BrowserWindow } = require('electron');
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
const mainWindow = new BrowserWindow({
|
||||||
|
show: false
|
||||||
|
});
|
||||||
|
mainWindow.loadFile('about:blank');
|
||||||
|
|
||||||
|
app.on('web-contents-created', () => {
|
||||||
|
throw new Error();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.quit();
|
||||||
|
});
|
Loading…
Reference in a new issue