diff --git a/lib/modules/firestore/index.js b/lib/modules/firestore/index.js index ffcdb3a5b2..d0e6d60ee8 100644 --- a/lib/modules/firestore/index.js +++ b/lib/modules/firestore/index.js @@ -15,7 +15,7 @@ import Path from './Path'; import WriteBatch from './WriteBatch'; import TransactionHandler from './TransactionHandler'; import Transaction from './Transaction'; -import { isBoolean, isObject, isString } from '../../utils'; +import { isBoolean, isObject, isString, hop } from '../../utils'; import { getNativeModule } from '../../utils/native'; import type DocumentSnapshot from './DocumentSnapshot'; @@ -164,22 +164,25 @@ export default class Firestore extends ModuleBase { return Promise.reject( new Error('Firestore.settings failed: settings must be an object.') ); - } else if (settings.host && !isString(settings.host)) { + } else if (hop(settings, 'host') && !isString(settings.host)) { return Promise.reject( new Error('Firestore.settings failed: settings.host must be a string.') ); - } else if (settings.persistence && !isBoolean(settings.persistence)) { + } else if ( + hop(settings, 'persistence') && + !isBoolean(settings.persistence) + ) { return Promise.reject( new Error( 'Firestore.settings failed: settings.persistence must be boolean.' ) ); - } else if (settings.ssl && !isBoolean(settings.ssl)) { + } else if (hop(settings, 'ssl') && !isBoolean(settings.ssl)) { return Promise.reject( new Error('Firestore.settings failed: settings.ssl must be boolean.') ); } else if ( - settings.timestampsInSnapshots && + hop(settings, 'timestampsInSnapshots') && !isBoolean(settings.timestampsInSnapshots) ) { return Promise.reject( diff --git a/lib/utils/index.js b/lib/utils/index.js index 00d439a10c..c82735f5c1 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -11,6 +11,15 @@ const AUTO_ID_CHARS = const { hasOwnProperty } = Object; // const DEFAULT_CHUNK_SIZE = 50; +/** + * Checks for property existence by name on the specified object + * @param object + * @param property + * @returns {*} + */ +export function hop(object: Object, property: string): boolean { + return hasOwnProperty.call(object, property); +} /** * Deep get a value from an object.