fix: set prototype names on gin::Constructible classes (#39006)

* fix: set prototype names on gin::Constructible classes

* test: add tests
This commit is contained in:
Shelley Vohr 2023-07-10 11:49:20 +02:00 committed by GitHub
parent 56b5c00312
commit c7bdd907d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 71 additions and 15 deletions

View file

@ -198,7 +198,7 @@ v8::Local<v8::Value> BrowserView::GetWebContents(v8::Isolate* isolate) {
// static
void BrowserView::FillObjectTemplate(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> templ) {
gin::ObjectTemplateBuilder(isolate, "BrowserView", templ)
gin::ObjectTemplateBuilder(isolate, GetClassName(), templ)
.SetMethod("setAutoResize", &BrowserView::SetAutoResize)
.SetMethod("setBounds", &BrowserView::SetBounds)
.SetMethod("getBounds", &BrowserView::GetBounds)
@ -207,6 +207,10 @@ void BrowserView::FillObjectTemplate(v8::Isolate* isolate,
.Build();
}
const char* BrowserView::GetTypeName() {
return GetClassName();
}
} // namespace electron::api
namespace {

View file

@ -45,9 +45,11 @@ class BrowserView : public gin::Wrappable<BrowserView>,
static gin::Handle<BrowserView> New(gin_helper::ErrorThrower thrower,
gin::Arguments* args);
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "BrowserView"; }
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
const char* GetTypeName() override;
WebContents* web_contents() const { return api_web_contents_; }
NativeBrowserView* view() const { return view_.get(); }

View file

@ -299,6 +299,10 @@ void Menu::FillObjectTemplate(v8::Isolate* isolate,
.Build();
}
const char* Menu::GetTypeName() {
return GetClassName();
}
} // namespace electron::api
namespace {

View file

@ -29,9 +29,11 @@ class Menu : public gin::Wrappable<Menu>,
// gin_helper::Constructible
static gin::Handle<Menu> New(gin::Arguments* args);
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "Menu"; }
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
const char* GetTypeName() override;
#if BUILDFLAG(IS_MAC)
// Set the global menubar.

View file

@ -256,7 +256,7 @@ bool Notification::IsSupported() {
void Notification::FillObjectTemplate(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> templ) {
gin::ObjectTemplateBuilder(isolate, "Notification", templ)
gin::ObjectTemplateBuilder(isolate, GetClassName(), templ)
.SetMethod("show", &Notification::Show)
.SetMethod("close", &Notification::Close)
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
@ -282,6 +282,10 @@ void Notification::FillObjectTemplate(v8::Isolate* isolate,
.Build();
}
const char* Notification::GetTypeName() {
return GetClassName();
}
} // namespace electron::api
namespace {

View file

@ -40,6 +40,7 @@ class Notification : public gin::Wrappable<Notification>,
static gin::Handle<Notification> New(gin_helper::ErrorThrower thrower,
gin::Arguments* args);
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "Notification"; }
// NotificationDelegate:
void NotificationAction(int index) override;
@ -52,6 +53,7 @@ class Notification : public gin::Wrappable<Notification>,
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
const char* GetTypeName() override;
// disable copy
Notification(const Notification&) = delete;

View file

@ -283,7 +283,7 @@ gin::Handle<Protocol> Protocol::New(gin_helper::ErrorThrower thrower) {
v8::Local<v8::ObjectTemplate> Protocol::FillObjectTemplate(
v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> tmpl) {
return gin::ObjectTemplateBuilder(isolate, "Protocol", tmpl)
return gin::ObjectTemplateBuilder(isolate, GetClassName(), tmpl)
.SetMethod("registerStringProtocol",
&Protocol::RegisterProtocolFor<ProtocolType::kString>)
.SetMethod("registerBufferProtocol",
@ -317,7 +317,7 @@ v8::Local<v8::ObjectTemplate> Protocol::FillObjectTemplate(
}
const char* Protocol::GetTypeName() {
return "Protocol";
return GetClassName();
}
} // namespace electron::api

View file

@ -45,13 +45,15 @@ class Protocol : public gin::Wrappable<Protocol>,
static gin::Handle<Protocol> Create(v8::Isolate* isolate,
ElectronBrowserContext* browser_context);
// gin_helper::Constructible
static gin::Handle<Protocol> New(gin_helper::ErrorThrower thrower);
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
static v8::Local<v8::ObjectTemplate> FillObjectTemplate(
v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> tmpl);
static const char* GetClassName() { return "Protocol"; }
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
const char* GetTypeName() override;
private:

View file

@ -1301,7 +1301,7 @@ gin::Handle<Session> Session::New() {
void Session::FillObjectTemplate(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> templ) {
gin::ObjectTemplateBuilder(isolate, "Session", templ)
gin::ObjectTemplateBuilder(isolate, GetClassName(), templ)
.SetMethod("resolveHost", &Session::ResolveHost)
.SetMethod("resolveProxy", &Session::ResolveProxy)
.SetMethod("getCacheSize", &Session::GetCacheSize)
@ -1379,7 +1379,7 @@ void Session::FillObjectTemplate(v8::Isolate* isolate,
}
const char* Session::GetTypeName() {
return "Session";
return GetClassName();
}
} // namespace electron::api

View file

@ -95,6 +95,7 @@ class Session : public gin::Wrappable<Session>,
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "Session"; }
const char* GetTypeName() override;
// Methods.

View file

@ -386,7 +386,7 @@ bool Tray::CheckAlive() {
// static
void Tray::FillObjectTemplate(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> templ) {
gin::ObjectTemplateBuilder(isolate, "Tray", templ)
gin::ObjectTemplateBuilder(isolate, GetClassName(), templ)
.SetMethod("destroy", &Tray::Destroy)
.SetMethod("isDestroyed", &Tray::IsDestroyed)
.SetMethod("setImage", &Tray::SetImage)
@ -408,6 +408,10 @@ void Tray::FillObjectTemplate(v8::Isolate* isolate,
.Build();
}
const char* Tray::GetTypeName() {
return GetClassName();
}
} // namespace electron::api
namespace {

View file

@ -45,10 +45,13 @@ class Tray : public gin::Wrappable<Tray>,
v8::Local<v8::Value> image,
absl::optional<UUID> guid,
gin::Arguments* args);
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "Tray"; }
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
const char* GetTypeName() override;
// disable copy
Tray(const Tray&) = delete;

View file

@ -4161,7 +4161,7 @@ void WebContents::FillObjectTemplate(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> templ) {
gin::InvokerOptions options;
options.holder_is_first_argument = true;
options.holder_type = "WebContents";
options.holder_type = GetClassName();
templ->Set(
gin::StringToSymbol(isolate, "isDestroyed"),
gin::CreateFunctionTemplate(
@ -4301,7 +4301,7 @@ void WebContents::FillObjectTemplate(v8::Isolate* isolate,
}
const char* WebContents::GetTypeName() {
return "WebContents";
return GetClassName();
}
ElectronBrowserContext* WebContents::GetBrowserContext() const {

View file

@ -147,9 +147,12 @@ class WebContents : public ExclusiveAccessContext,
v8::Isolate* isolate,
const gin_helper::Dictionary& web_preferences);
// gin_helper::Constructible
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "WebContents"; }
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
const char* GetTypeName() override;
void Destroy();

View file

@ -409,7 +409,7 @@ void WebFrameMain::FillObjectTemplate(v8::Isolate* isolate,
}
const char* WebFrameMain::GetTypeName() {
return "WebFrameMain";
return GetClassName();
}
} // namespace electron::api

View file

@ -52,9 +52,12 @@ class WebFrameMain : public gin::Wrappable<WebFrameMain>,
static WebFrameMain* FromRenderFrameHost(
content::RenderFrameHost* render_frame_host);
// gin_helper::Constructible
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "WebFrameMain"; }
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
const char* GetTypeName() override;
content::RenderFrameHost* render_frame_host() const { return render_frame_; }