diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index c1881db488ef..68c1f37ade32 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -340,7 +340,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) // Obtain the session. std::string partition; mate::Handle session; - if (options.Get("session", &session)) { + if (options.Get("session", &session) && !session.IsEmpty()) { } else if (options.Get("partition", &partition)) { session = Session::FromPartition(isolate, partition); } else { diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index e3ecb43acf17..993f9680ccb4 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -101,7 +101,7 @@ Window::Window(v8::Isolate* isolate, v8::Local wrapper, } #endif - if (options.Get("webContents", &web_contents)) { + if (options.Get("webContents", &web_contents) && !web_contents.IsEmpty()) { // Set webPreferences from options if using an existing webContents. // These preferences will be used when the webContent launches new // render processes. @@ -135,7 +135,7 @@ void Window::Init(v8::Isolate* isolate, // The parent window. mate::Handle parent; - if (options.Get("parent", &parent)) + if (options.Get("parent", &parent) && !parent.IsEmpty()) parent_window_.Reset(isolate, parent.ToV8()); // Creates BrowserWindow. @@ -149,7 +149,7 @@ void Window::Init(v8::Isolate* isolate, #if defined(TOOLKIT_VIEWS) // Sets the window icon. mate::Handle icon; - if (options.Get(options::kIcon, &icon)) + if (options.Get(options::kIcon, &icon) && !icon.IsEmpty()) SetIcon(icon); #endif @@ -184,7 +184,7 @@ void Window::WillDestroyNativeObject() { v8::HandleScope handle_scope(isolate()); for (v8::Local value : child_windows_.Values(isolate())) { mate::Handle child; - if (mate::ConvertFromV8(isolate(), value, &child)) + if (mate::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty()) child->window_->CloseImmediately(); } } @@ -731,7 +731,7 @@ void Window::SetMenu(v8::Isolate* isolate, v8::Local value) { mate::Handle menu; if (value->IsObject() && mate::V8ToString(value->ToObject()->GetConstructorName()) == "Menu" && - mate::ConvertFromV8(isolate, value, &menu)) { + mate::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) { menu_.Reset(isolate, menu.ToV8()); window_->SetMenu(menu->model()); } else if (value->IsNull()) { @@ -851,7 +851,7 @@ void Window::SetParentWindow(v8::Local value, } mate::Handle parent; - if (value->IsNull()) { + if (value->IsNull() || value->IsUndefined()) { RemoveFromParentChildWindows(); parent_window_.Reset(); window_->SetParentWindow(nullptr); @@ -887,7 +887,7 @@ void Window::SetBrowserView(v8::Local value) { ResetBrowserView(); mate::Handle browser_view; - if (value->IsNull()) { + if (value->IsNull() || value->IsUndefined()) { window_->SetBrowserView(nullptr); } else if (mate::ConvertFromV8(isolate(), value, &browser_view)) { window_->SetBrowserView(browser_view->view()); @@ -902,7 +902,8 @@ void Window::ResetBrowserView() { } mate::Handle browser_view; - if (mate::ConvertFromV8(isolate(), GetBrowserView(), &browser_view)) { + if (mate::ConvertFromV8(isolate(), GetBrowserView(), &browser_view) + && !browser_view.IsEmpty()) { browser_view->web_contents()->SetOwnerWindow(nullptr); } @@ -991,8 +992,10 @@ void Window::RemoveFromParentChildWindows() { return; mate::Handle parent; - if (!mate::ConvertFromV8(isolate(), GetParentWindow(), &parent)) + if (!mate::ConvertFromV8(isolate(), GetParentWindow(), &parent) + || parent.IsEmpty()) { return; + } parent->child_windows_.Remove(ID()); } diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index aba41027e9c7..2b5488d208ff 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -86,6 +86,16 @@ describe('BrowserWindow module', () => { return closeWindow(w).then(() => { w = null }) }) + describe('BrowserWindow constructor', () => { + it('allows passing void 0 as the webContents', () => { + w.close() + w = null + w = new BrowserWindow({ + webContents: void 0 + }) + }) + }) + describe('BrowserWindow.close()', () => { let server