From 49c694beee717abd7680e62df588d94530e1b3a3 Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Thu, 5 Jul 2018 10:45:05 +0200 Subject: [PATCH 1/2] Fixed `isWindow` helper for the Electron environment. --- src/dom/iswindow.js | 10 +++++++++- tests/dom/iswindow.js | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/dom/iswindow.js b/src/dom/iswindow.js index 5efec8a..fb0249d 100644 --- a/src/dom/iswindow.js +++ b/src/dom/iswindow.js @@ -14,5 +14,13 @@ * @returns {Boolean} */ export default function isWindow( obj ) { - return Object.prototype.toString.apply( obj ) == '[object Window]'; + const stringifiedObject = Object.prototype.toString.apply( obj ); + + return ( + // Returns `true` for the `window` object in browser environments. + stringifiedObject == '[object Window]' || + + // Returns `true` for the `window` object in the Electron environment. + stringifiedObject == '[object global]' + ); } diff --git a/tests/dom/iswindow.js b/tests/dom/iswindow.js index b43075b..fb44ea3 100644 --- a/tests/dom/iswindow.js +++ b/tests/dom/iswindow.js @@ -8,7 +8,7 @@ import isWindow from '../../src/dom/iswindow'; describe( 'isWindow()', () => { - it( 'detects DOM Window', () => { + it( 'detects DOM Window in browsers', () => { expect( isWindow( window ) ).to.be.true; expect( isWindow( {} ) ).to.be.false; expect( isWindow( null ) ).to.be.false; @@ -16,4 +16,14 @@ describe( 'isWindow()', () => { expect( isWindow( new Date() ) ).to.be.false; expect( isWindow( 42 ) ).to.be.false; } ); + + it( 'detects DOM Window in the Electron environment', () => { + const global = { + get [ Symbol.toStringTag ]() { + return 'global'; + } + }; + + expect( isWindow( global ) ).to.be.true; + } ); } ); From 4ced195ab4b97258131642349e0d78dc6f9fd215 Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Thu, 5 Jul 2018 11:27:01 +0200 Subject: [PATCH 2/2] Simplified code. --- src/dom/iswindow.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/dom/iswindow.js b/src/dom/iswindow.js index fb0249d..11f2845 100644 --- a/src/dom/iswindow.js +++ b/src/dom/iswindow.js @@ -16,11 +16,15 @@ export default function isWindow( obj ) { const stringifiedObject = Object.prototype.toString.apply( obj ); - return ( - // Returns `true` for the `window` object in browser environments. - stringifiedObject == '[object Window]' || + // Returns `true` for the `window` object in browser environments. + if ( stringifiedObject == '[object Window]' ) { + return true; + } - // Returns `true` for the `window` object in the Electron environment. - stringifiedObject == '[object global]' - ); + // Returns `true` for the `window` object in the Electron environment. + if ( stringifiedObject == '[object global]' ) { + return true; + } + + return false; }