refactor: use gin_helper::Dictionary::CreateEmpty() helper (#40140)

This commit is contained in:
Milan Burda 2023-10-10 12:45:44 +02:00 committed by GitHub
parent 47beca1d2a
commit 563c370d51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 30 additions and 42 deletions

View file

@ -1180,8 +1180,7 @@ void BaseWindow::RemoveFromParentChildWindows() {
// static
gin_helper::WrappableBase* BaseWindow::New(gin_helper::Arguments* args) {
gin_helper::Dictionary options =
gin::Dictionary::CreateEmpty(args->isolate());
auto options = gin_helper::Dictionary::CreateEmpty(args->isolate());
args->GetNext(&options);
return new BaseWindow(args, options);

View file

@ -74,8 +74,7 @@ gin::WrapperInfo BrowserView::kWrapperInfo = {gin::kEmbedderNativeGin};
BrowserView::BrowserView(gin::Arguments* args,
const gin_helper::Dictionary& options)
: id_(GetNextId()) {
gin_helper::Dictionary web_preferences =
gin::Dictionary::CreateEmpty(args->isolate());
auto web_preferences = gin_helper::Dictionary::CreateEmpty(args->isolate());
options.Get(options::kWebPreferences, &web_preferences);
web_preferences.Set("type", "browserView");
@ -143,7 +142,7 @@ gin::Handle<BrowserView> BrowserView::New(gin_helper::ErrorThrower thrower,
return gin::Handle<BrowserView>();
}
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
auto options = gin::Dictionary::CreateEmpty(args->isolate());
args->GetNext(&options);
auto handle =

View file

@ -152,7 +152,7 @@ void OnTraceBufferUsageAvailable(
gin_helper::Promise<gin_helper::Dictionary> promise,
float percent_full,
size_t approximate_count) {
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
auto dict = gin_helper::Dictionary::CreateEmpty(promise.isolate());
dict.Set("percentage", percent_full);
dict.Set("value", approximate_count);

View file

@ -448,8 +448,8 @@ v8::Local<v8::Promise> Session::ResolveHost(
DCHECK(addrs.has_value() && !addrs->empty());
v8::HandleScope handle_scope(promise.isolate());
gin_helper::Dictionary dict =
gin::Dictionary::CreateEmpty(promise.isolate());
auto dict =
gin_helper::Dictionary::CreateEmpty(promise.isolate());
dict.Set("endpoints", addrs->endpoints());
promise.Resolve(dict);
}

View file

@ -1658,8 +1658,7 @@ void WebContents::RenderFrameCreated(
if (lifecycle_state == content::RenderFrameHost::LifecycleState::kActive) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
gin_helper::Dictionary details =
gin_helper::Dictionary::CreateEmpty(isolate);
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
details.SetGetter("frame", render_frame_host);
Emit("frame-created", details);
}
@ -1731,7 +1730,7 @@ void WebContents::PrimaryMainFrameRenderProcessGone(
base::TerminationStatus status) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate);
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
details.Set("reason", status);
details.Set("exitCode", web_contents()->GetCrashedErrorCode());
Emit("render-process-gone", details);
@ -2529,7 +2528,7 @@ v8::Local<v8::Value> WebContents::GetWebRTCUDPPortRange(
v8::Isolate* isolate) const {
auto* prefs = web_contents()->GetMutableRendererPrefs();
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
dict.Set("min", static_cast<uint32_t>(prefs->webrtc_udp_min_port));
dict.Set("max", static_cast<uint32_t>(prefs->webrtc_udp_max_port));
return dict.GetHandle();
@ -2907,8 +2906,7 @@ void WebContents::OnGetDeviceNameToUse(
}
void WebContents::Print(gin::Arguments* args) {
gin_helper::Dictionary options =
gin::Dictionary::CreateEmpty(args->isolate());
auto options = gin_helper::Dictionary::CreateEmpty(args->isolate());
base::Value::Dict settings;
if (args->Length() >= 1 && !args->GetNext(&options)) {
@ -2933,8 +2931,7 @@ void WebContents::Print(gin::Arguments* args) {
settings.Set(printing::kSettingShouldPrintBackgrounds, print_background);
// Set custom margin settings
gin_helper::Dictionary margins =
gin::Dictionary::CreateEmpty(args->isolate());
auto margins = gin_helper::Dictionary::CreateEmpty(args->isolate());
if (options.Get("margins", &margins)) {
printing::mojom::MarginType margin_type =
printing::mojom::MarginType::kDefaultMargins;

View file

@ -169,8 +169,7 @@ void ElectronBluetoothDelegate::ShowDevicePairPrompt(
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
gin_helper::Dictionary details =
gin_helper::Dictionary::CreateEmpty(isolate);
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
details.Set("deviceId", device_identifier);
details.Set("pairingKind", pairing_kind);
details.SetGetter("frame", frame);

View file

@ -119,8 +119,7 @@ void HidChooserContext::RevokeDevicePermission(
if (session) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
gin_helper::Dictionary details =
gin_helper::Dictionary::CreateEmpty(isolate);
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
details.Set("device", device.Clone());
details.Set("origin", origin.Serialize());
session->Emit("hid-device-revoked", details);

View file

@ -114,8 +114,8 @@ NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
} else if (titlebar_overlay->IsObject()) {
titlebar_overlay_ = true;
gin_helper::Dictionary titlebar_overlay_dict =
gin::Dictionary::CreateEmpty(options.isolate());
auto titlebar_overlay_dict =
gin_helper::Dictionary::CreateEmpty(options.isolate());
options.Get(options::ktitleBarOverlay, &titlebar_overlay_dict);
int height;
if (titlebar_overlay_dict.Get(options::kOverlayHeight, &height))

View file

@ -231,8 +231,8 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
v8::Local<v8::Value> titlebar_overlay;
if (options.Get(options::ktitleBarOverlay, &titlebar_overlay) &&
titlebar_overlay->IsObject()) {
gin_helper::Dictionary titlebar_overlay_obj =
gin::Dictionary::CreateEmpty(options.isolate());
auto titlebar_overlay_obj =
gin_helper::Dictionary::CreateEmpty(options.isolate());
options.Get(options::ktitleBarOverlay, &titlebar_overlay_obj);
std::string overlay_color_string;

View file

@ -158,8 +158,7 @@ void SerialChooserContext::RevokePortPermissionWebInitiated(
if (session) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
gin_helper::Dictionary details =
gin_helper::Dictionary::CreateEmpty(isolate);
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
details.Set("port", it->second);
details.SetGetter("frame", render_frame_host);
details.Set("origin", origin.Serialize());

View file

@ -246,8 +246,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
if (save_promise_) {
gin_helper::Dictionary dict =
gin::Dictionary::CreateEmpty(save_promise_->isolate());
auto dict = gin_helper::Dictionary::CreateEmpty(save_promise_->isolate());
if (response == GTK_RESPONSE_ACCEPT) {
dict.Set("canceled", false);
dict.Set("filePath", GetFileName());
@ -257,8 +256,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
}
save_promise_->Resolve(dict);
} else if (open_promise_) {
gin_helper::Dictionary dict =
gin::Dictionary::CreateEmpty(open_promise_->isolate());
auto dict = gin_helper::Dictionary::CreateEmpty(open_promise_->isolate());
if (response == GTK_RESPONSE_ACCEPT) {
dict.Set("canceled", false);
dict.Set("filePaths", GetFileNames());

View file

@ -353,7 +353,7 @@ void OpenDialogCompletion(int chosen,
bool security_scoped_bookmarks,
gin_helper::Promise<gin_helper::Dictionary> promise) {
v8::HandleScope scope(promise.isolate());
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
auto dict = gin_helper::Dictionary::CreateEmpty(promise.isolate());
if (chosen == NSModalResponseCancel) {
dict.Set("canceled", true);
dict.Set("filePaths", std::vector<base::FilePath>());
@ -431,7 +431,7 @@ void SaveDialogCompletion(int chosen,
bool security_scoped_bookmarks,
gin_helper::Promise<gin_helper::Dictionary> promise) {
v8::HandleScope scope(promise.isolate());
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
auto dict = gin_helper::Dictionary::CreateEmpty(promise.isolate());
if (chosen == NSModalResponseCancel) {
dict.Set("canceled", true);
dict.Set("filePath", base::FilePath());

View file

@ -220,7 +220,7 @@ void ShowOpenDialog(const DialogSettings& settings,
auto done = [](gin_helper::Promise<gin_helper::Dictionary> promise,
bool success, std::vector<base::FilePath> result) {
v8::HandleScope handle_scope(promise.isolate());
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
auto dict = gin::Dictionary::CreateEmpty(promise.isolate());
dict.Set("canceled", !success);
dict.Set("filePaths", result);
promise.Resolve(dict);
@ -269,7 +269,7 @@ void ShowSaveDialog(const DialogSettings& settings,
auto done = [](gin_helper::Promise<gin_helper::Dictionary> promise,
bool success, base::FilePath result) {
v8::HandleScope handle_scope(promise.isolate());
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
auto dict = gin::Dictionary::CreateEmpty(promise.isolate());
dict.Set("canceled", !success);
dict.Set("filePath", result);
promise.Resolve(dict);

View file

@ -203,8 +203,7 @@ void UsbChooserContext::RevokeObjectPermissionInternal(
if (session) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
gin_helper::Dictionary details =
gin_helper::Dictionary::CreateEmpty(isolate);
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
details.Set("device", object);
details.Set("origin", origin.Serialize());
session->Emit("usb-device-revoked", details);

View file

@ -204,8 +204,7 @@ void Clipboard::WriteHTML(const std::u16string& html,
v8::Local<v8::Value> Clipboard::ReadBookmark(gin_helper::Arguments* args) {
std::u16string title;
std::string url;
gin_helper::Dictionary dict =
gin_helper::Dictionary::CreateEmpty(args->isolate());
auto dict = gin_helper::Dictionary::CreateEmpty(args->isolate());
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
clipboard->ReadBookmark(/* data_dst = */ nullptr, &title, &url);
dict.Set("title", title);

View file

@ -111,7 +111,7 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path,
base::win::ShortcutOperation operation =
base::win::ShortcutOperation::kCreateAlways;
args->GetNext(&operation);
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
auto options = gin::Dictionary::CreateEmpty(args->isolate());
if (!args->GetNext(&options)) {
args->ThrowError();
return false;
@ -146,7 +146,7 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path,
v8::Local<v8::Value> ReadShortcutLink(gin_helper::ErrorThrower thrower,
const base::FilePath& path) {
using base::win::ShortcutProperties;
gin::Dictionary options = gin::Dictionary::CreateEmpty(thrower.isolate());
auto options = gin::Dictionary::CreateEmpty(thrower.isolate());
electron::ScopedAllowBlockingForElectron allow_blocking;
base::win::ScopedCOMInitializer com_initializer;
base::win::ShortcutProperties properties;

View file

@ -573,8 +573,8 @@ v8::MaybeLocal<v8::Object> CreateProxyForAPI(
{
v8::Context::Scope destination_context_scope(destination_context);
gin_helper::Dictionary proxy =
gin::Dictionary::CreateEmpty(destination_context->GetIsolate());
auto proxy =
gin_helper::Dictionary::CreateEmpty(destination_context->GetIsolate());
object_cache->CacheProxiedObject(api.GetHandle(), proxy.GetHandle());
auto maybe_keys = api.GetHandle()->GetOwnPropertyNames(
source_context, static_cast<v8::PropertyFilter>(v8::ONLY_ENUMERABLE));