From 11cbc5a1c76539d34161a1d17728a92bca6f6f96 Mon Sep 17 00:00:00 2001 From: alokrajiv Date: Wed, 11 Oct 2017 20:26:17 +0530 Subject: [PATCH] gracefully continue if error function is missing --- www/mainHandle.js | 108 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/www/mainHandle.js b/www/mainHandle.js index 38ee142..bb88e59 100644 --- a/www/mainHandle.js +++ b/www/mainHandle.js @@ -45,6 +45,12 @@ function StorageHandle() { StorageHandle.prototype.set = function(reference, value, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("The reference can't be null"); return; @@ -91,6 +97,12 @@ StorageHandle.prototype.set = function(reference, value, success, error) { /* removing */ StorageHandle.prototype.remove = function(reference, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -110,6 +122,12 @@ StorageHandle.prototype.remove = function(reference, success, error) { /* clearing */ StorageHandle.prototype.clear = function(success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (inBrowser) { try { localStorage.clear(); @@ -125,6 +143,12 @@ StorageHandle.prototype.clear = function(success, error) { /* boolean storage */ StorageHandle.prototype.putBoolean = function(reference, aBoolean, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -156,6 +180,12 @@ StorageHandle.prototype.putBoolean = function(reference, aBoolean, success, erro StorageHandle.prototype.getBoolean = function(reference, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -177,6 +207,12 @@ StorageHandle.prototype.getBoolean = function(reference, success, error) { /* int storage */ StorageHandle.prototype.putInt = function(reference, anInt, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -185,6 +221,12 @@ StorageHandle.prototype.putInt = function(reference, anInt, success, error) { }; StorageHandle.prototype.getInt = function(reference, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -195,6 +237,12 @@ StorageHandle.prototype.getInt = function(reference, success, error) { /* float storage */ StorageHandle.prototype.putDouble = function(reference, aFloat, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -203,6 +251,12 @@ StorageHandle.prototype.putDouble = function(reference, aFloat, success, error) }; StorageHandle.prototype.getDouble = function(reference, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -218,6 +272,12 @@ StorageHandle.prototype.getDouble = function(reference, success, error) { /* string storage */ StorageHandle.prototype.putString = function(reference, s, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -226,6 +286,12 @@ StorageHandle.prototype.putString = function(reference, s, success, error) { }; StorageHandle.prototype.getString = function(reference, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error("Null reference isn't supported"); return; @@ -235,6 +301,12 @@ StorageHandle.prototype.getString = function(reference, success, error) { /* object storage COMPOSITE AND DOESNT CARE FOR BROWSER*/ StorageHandle.prototype.putObject = function(reference, obj, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + var objAsString = ""; try { objAsString = JSON.stringify(obj); @@ -253,6 +325,12 @@ StorageHandle.prototype.putObject = function(reference, obj, success, error) { }; StorageHandle.prototype.getObject = function(reference, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + this.getString(reference, function(data) { var obj = {}; try { @@ -266,6 +344,12 @@ StorageHandle.prototype.getObject = function(reference, success, error) { /* API >= 2 */ StorageHandle.prototype.setItem = function(reference, obj, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + var objAsString = ""; try { objAsString = JSON.stringify(obj); @@ -290,6 +374,12 @@ StorageHandle.prototype.setItem = function(reference, obj, success, error) { }; StorageHandle.prototype.getItem = function(reference, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error(new NativeStorageError(NativeStorageError.NULL_REFERENCE, "JS", "")); return; @@ -312,6 +402,12 @@ StorageHandle.prototype.getItem = function(reference, success, error) { /* API >= 2 */ StorageHandle.prototype.setSecretItem = function(reference, obj, encryptConfig, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + var objAsString = ""; try { objAsString = JSON.stringify(obj); @@ -354,6 +450,12 @@ StorageHandle.prototype.setSecretItem = function(reference, obj, encryptConfig, }; StorageHandle.prototype.getSecretItem = function(reference, encryptConfig, success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + if (reference === null) { error(new NativeStorageError(NativeStorageError.NULL_REFERENCE, "JS", "")); return; @@ -394,6 +496,12 @@ StorageHandle.prototype.getSecretItem = function(reference, encryptConfig, succe /* list keys */ StorageHandle.prototype.keys = function(success, error) { + + //if error is null then replace with empty function to silence warnings + if(!error){ + error = function(){}; + } + this.storageHandlerDelegate(success, error, "NativeStorage", "keys", []); };