Explorar el Código

Merge pull request #247 from ckeditor/t/ckeditor5/879

Fix: The `isWindow` helper should work in the Electron environment. Closes ckeditor/ckeditor5#879.
Aleksander Nowodzinski hace 7 años
padre
commit
8fc3eeff7b

+ 13 - 1
packages/ckeditor5-utils/src/dom/iswindow.js

@@ -14,5 +14,17 @@
  * @returns {Boolean}
  */
 export default function isWindow( obj ) {
-	return Object.prototype.toString.apply( obj ) == '[object Window]';
+	const stringifiedObject = Object.prototype.toString.apply( obj );
+
+	// 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.
+	if ( stringifiedObject == '[object global]' ) {
+		return true;
+	}
+
+	return false;
 }

+ 11 - 1
packages/ckeditor5-utils/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;
+	} );
 } );