-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw an error if config.storeName
isn't a String
#948
base: master
Are you sure you want to change the base?
Changes from 2 commits
2c8475b
a633011
1c85180
1798dc0
7f2a0f8
6622e72
b5e411a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,9 +51,9 @@ const DefaultConfig = { | |
}; | ||
|
||
function callWhenReady(localForageInstance, libraryMethod) { | ||
localForageInstance[libraryMethod] = function() { | ||
localForageInstance[libraryMethod] = function () { | ||
const _args = arguments; | ||
return localForageInstance.ready().then(function() { | ||
return localForageInstance.ready().then(function () { | ||
return localForageInstance[libraryMethod].apply( | ||
localForageInstance, | ||
_args | ||
|
@@ -107,7 +107,7 @@ class LocalForage { | |
this._dbInfo = null; | ||
|
||
this._wrapLibraryMethodsWithReady(); | ||
this.setDriver(this._config.driver).catch(() => {}); | ||
this.setDriver(this._config.driver).catch(() => { }); | ||
} | ||
|
||
// Set any config values for localForage; can be called anytime before | ||
|
@@ -118,50 +118,58 @@ class LocalForage { | |
// If the options argument is an object, we use it to set values. | ||
// Otherwise, we return either a specified config value or all | ||
// config values. | ||
if (typeof options === 'object') { | ||
// If localforage is ready and fully initialized, we can't set | ||
// any new configuration values. Instead, we return an error. | ||
if (this._ready) { | ||
return new Error( | ||
"Can't call config() after localforage " + 'has been used.' | ||
); | ||
} | ||
|
||
for (let i in options) { | ||
if (i === 'storeName') { | ||
options[i] = options[i].replace(/\W/g, '_'); | ||
try { | ||
if (typeof options === 'object') { | ||
// If localforage is ready and fully initialized, we can't set | ||
// any new configuration values. Instead, we return an error. | ||
if (this._ready) { | ||
return new Error( | ||
"Can't call config() after localforage " + 'has been used.' | ||
); | ||
} | ||
|
||
if (i === 'version' && typeof options[i] !== 'number') { | ||
return new Error('Database version must be a number.'); | ||
for (let i in options) { | ||
if (i === 'storeName' && typeof options[i] !== 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading this code it seems like this |
||
options[i] = options[i].replace(/\W/g, '_'); | ||
} else { | ||
return new Error('storeName must be a string'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a helpful touch, and I guess it isn't a breaking change since |
||
} | ||
|
||
if (i === 'version' && typeof options[i] !== 'number') { | ||
return new Error('Database version must be a number.'); | ||
} | ||
|
||
this._config[i] = options[i]; | ||
} | ||
|
||
this._config[i] = options[i]; | ||
} | ||
// after all config options are set and | ||
// the driver option is used, try setting it | ||
if ('driver' in options && options.driver) { | ||
return this.setDriver(this._config.driver); | ||
} | ||
|
||
// after all config options are set and | ||
// the driver option is used, try setting it | ||
if ('driver' in options && options.driver) { | ||
return this.setDriver(this._config.driver); | ||
return true; | ||
} else if (typeof options === 'string') { | ||
return this._config[options]; | ||
} else { | ||
return this._config; | ||
} | ||
|
||
return true; | ||
} else if (typeof options === 'string') { | ||
return this._config[options]; | ||
} else { | ||
return this._config; | ||
} catch (err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't catch any error here; instead this should throw as it did previously. |
||
return new Error(err); | ||
} | ||
} | ||
|
||
|
||
|
||
// Used to define a custom driver, shared across all instances of | ||
// localForage. | ||
defineDriver(driverObject, callback, errorCallback) { | ||
const promise = new Promise(function(resolve, reject) { | ||
const promise = new Promise(function (resolve, reject) { | ||
try { | ||
const driverName = driverObject._driver; | ||
const complianceError = new Error( | ||
'Custom driver not compliant; see ' + | ||
'https://mozilla.github.io/localForage/#definedriver' | ||
'https://mozilla.github.io/localForage/#definedriver' | ||
); | ||
|
||
// A driver name should be defined and not overlap with the | ||
|
@@ -190,9 +198,9 @@ class LocalForage { | |
} | ||
} | ||
|
||
const configureMissingMethods = function() { | ||
const methodNotImplementedFactory = function(methodName) { | ||
return function() { | ||
const configureMissingMethods = function () { | ||
const methodNotImplementedFactory = function (methodName) { | ||
return function () { | ||
const error = new Error( | ||
`Method ${methodName} is not implemented by the current driver` | ||
); | ||
|
@@ -223,7 +231,7 @@ class LocalForage { | |
|
||
configureMissingMethods(); | ||
|
||
const setDriverSupport = function(support) { | ||
const setDriverSupport = function (support) { | ||
if (DefinedDrivers[driverName]) { | ||
console.info( | ||
`Redefining LocalForage driver: ${driverName}` | ||
|
@@ -314,7 +322,7 @@ class LocalForage { | |
} | ||
|
||
function initDriver(supportedDrivers) { | ||
return function() { | ||
return function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why these code changes were made, but they're failing the linter; could you please revert these style/whitespace changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got this due to correcting the indentation by some extension. I'll revert it back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think test cases in the test folder needed to be more organized in categories for manging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with the changes and also added a test case in test/test.config.js regarding this issue fixing test. Can you check it again There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't get any update from you, sir. |
||
let currentDriverIndex = 0; | ||
|
||
function driverPromiseLoop() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this
try/catch
block here is helpful to add, as it will prevent unexpected errors from throwing.