fix: segfault on webContents.fromId(xxx) (#26651)

Co-authored-by: Jeremy Rose <nornagon@nornagon.net>
This commit is contained in:
trop[bot]
2020-11-24 16:12:53 -05:00
committed by GitHub
parent 46441c1bd7
commit c9801ab5a5
3 changed files with 15 additions and 2 deletions

View File

@@ -3781,6 +3781,12 @@ namespace {
using electron::api::GetAllWebContents;
using electron::api::WebContents;
gin::Handle<WebContents> WebContentsFromID(v8::Isolate* isolate, int32_t id) {
WebContents* contents = WebContents::FromID(id);
return contents ? gin::CreateHandle(isolate, contents)
: gin::Handle<WebContents>();
}
std::vector<gin::Handle<WebContents>> GetAllWebContentsAsV8(
v8::Isolate* isolate) {
std::vector<gin::Handle<WebContents>> list;
@@ -3798,7 +3804,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Isolate* isolate = context->GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("WebContents", WebContents::GetConstructor(context));
dict.SetMethod("fromId", &WebContents::FromID);
dict.SetMethod("fromId", &WebContentsFromID);
dict.SetMethod("getAllWebContents", &GetAllWebContentsAsV8);
}