From: Szymon Jastrzebski Date: Wed, 12 Apr 2017 12:24:31 +0000 (+0200) Subject: [Common] Replacing JS warnings + errors X-Git-Tag: submit/tizen/20170419.130254~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=50aee57f1ad223f95257b2c47c38ea517546f86e;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] Replacing JS warnings + errors [Verification] Related TCT result did not change Change-Id: I707c8ad25c517c92bc43060f62e762116f65233f Signed-off-by: Szymon Jastrzebski --- diff --git a/src/alarm/alarm_api.js b/src/alarm/alarm_api.js index e9abbd37..278719bb 100755 --- a/src/alarm/alarm_api.js +++ b/src/alarm/alarm_api.js @@ -389,7 +389,7 @@ tizen.AlarmAbsolute = function(date, second, internal) { if(!T.isNullOrUndefined(second)){ m_period = Converter.toLong(second); if(_warningLogs.enableLog){ - console.warn("This Constructor is deprecated since Tizen 4.0." + + privUtils_.warn("This Constructor is deprecated since Tizen 4.0." + " Please consider using other constructors or other type of an alarm."); } } diff --git a/src/application/application_api.js b/src/application/application_api.js index b0d5774d..b668dbbb 100755 --- a/src/application/application_api.js +++ b/src/application/application_api.js @@ -565,7 +565,7 @@ var APPLICATION_EVENT_LISTENER = 'ApplicationEventListener'; var applicationEventListener = new ListenerManager(native, APPLICATION_EVENT_LISTENER); ApplicationManager.prototype.addAppInfoEventListener = function() { - console.warn('DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. ' + privUtils_.warn('DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. ' + 'Use tizen.package.setPackageInfoEventListener() instead.'); var args = AV.validateMethod(arguments, [ @@ -580,7 +580,7 @@ ApplicationManager.prototype.addAppInfoEventListener = function() { }; ApplicationManager.prototype.removeAppInfoEventListener = function() { - console.warn('DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. ' + privUtils_.warn('DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. ' + 'Use tizen.package.unsetPackageInfoEventListener() instead.'); var args = AV.validateMethod(arguments, [ diff --git a/src/bluetooth/bluetooth_api.js b/src/bluetooth/bluetooth_api.js index 117ff30a..09979b31 100755 --- a/src/bluetooth/bluetooth_api.js +++ b/src/bluetooth/bluetooth_api.js @@ -2034,7 +2034,7 @@ BluetoothAdapter.prototype.setName = function() { BluetoothAdapter.prototype.setPowered = function() { privUtils_.log('Entered BluetoothAdapter.setPowered()'); - console.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. ' + privUtils_.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. ' + 'Let the user turn on/off Bluetooth through the Settings application instead.'); var args = AV.validateMethod(arguments, [ diff --git a/src/calendar/js/calendar_alarm.js b/src/calendar/js/calendar_alarm.js index 08c26386..6976ac5a 100755 --- a/src/calendar/js/calendar_alarm.js +++ b/src/calendar/js/calendar_alarm.js @@ -19,6 +19,8 @@ var AlarmMethod = { DISPLAY: 'DISPLAY' }; +var privUtils_ = xwalk.utils; + var CalendarAlarm = function(time, method, description) { validator_.isConstructorCall(this, CalendarAlarm); @@ -30,7 +32,7 @@ var CalendarAlarm = function(time, method, description) { try { _method = converter_.toEnum(method, Object.keys(AlarmMethod), false); } catch (e) { - console.warn('Failed to convert method: "' + method + '" to enum AlarmMethod.'); + privUtils_.warn('Failed to convert method: "' + method + '" to enum AlarmMethod.'); _method = method; } diff --git a/src/content/js/manager.js b/src/content/js/manager.js index 6498d596..db388dc6 100755 --- a/src/content/js/manager.js +++ b/src/content/js/manager.js @@ -15,6 +15,7 @@ */ var T_ = xwalk.utils.type; +var privUtils_ = xwalk.utils; var CONTENT_MANAGER_LISTENER_ID = 'ContentManagerChangeCallback'; @@ -335,7 +336,7 @@ ContentManager.prototype.removeChangeListener = function() { }; ContentManager.prototype.setChangeListener = function(changeCallback) { - console.warn('DEPRECATION WARNING: setChangeListener() is deprecated and will be removed ' + privUtils_.warn('DEPRECATION WARNING: setChangeListener() is deprecated and will be removed ' + 'from next release. Use addChangeListener() instead.'); var args = validator_.validateArgs(arguments, [{ @@ -370,7 +371,7 @@ ContentManager.prototype.setChangeListener = function(changeCallback) { }; ContentManager.prototype.unsetChangeListener = function() { - console.warn('DEPRECATION WARNING: unsetChangeListener() is deprecated and will be removed ' + privUtils_.warn('DEPRECATION WARNING: unsetChangeListener() is deprecated and will be removed ' + 'from next release. Use removeChangeListener() instead.'); var data = {}; diff --git a/src/humanactivitymonitor/humanactivitymonitor_api.js b/src/humanactivitymonitor/humanactivitymonitor_api.js index 6945eb51..7b3a8f7e 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_api.js +++ b/src/humanactivitymonitor/humanactivitymonitor_api.js @@ -109,7 +109,7 @@ function convertActivityData(type, data) { case HumanActivityType.SLEEP_MONITOR: return new HumanActivitySleepMonitorData(data); default: - console.error('Uknown human activity type: ' + type); + utils_.error('Uknown human activity type: ' + type); } } @@ -139,7 +139,7 @@ function convertActivityRecorderData(type, data) { func = HumanActivityRecorderPressureData; break; default: - console.error('Uknown human activity recorder type: ' + type); + utils_.error('Uknown human activity recorder type: ' + type); return; } @@ -572,7 +572,7 @@ GestureListenerManager.prototype.onListenerCalled = function(msg) { d = this.native.getErrorObject(msg); break; default: - console.log('Unknown mode: ' + msg.action); + utils_.log('Unknown mode: ' + msg.action); return; } diff --git a/src/nfc/nfc_api.js b/src/nfc/nfc_api.js index db3d0e31..8aa8b58d 100644 --- a/src/nfc/nfc_api.js +++ b/src/nfc/nfc_api.js @@ -272,7 +272,7 @@ function NFCAdapter() { } NFCAdapter.prototype.setPowered = function() { - console.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off ' + privUtils_.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off ' + 'through the Settings application instead.'); var args = validator_.validateArgs(arguments, [ diff --git a/src/power/power_api.js b/src/power/power_api.js index f7a711de..06453ebd 100755 --- a/src/power/power_api.js +++ b/src/power/power_api.js @@ -18,6 +18,7 @@ var JSON_ = xwalk.JSON; var validator_ = xwalk.utils.validator; var types_ = validator_.Types; var native_ = new xwalk.utils.NativeManager(extension); +var privUtils_ = xwalk.utils; function ListenerManager(native, listenerName) { this.listener; @@ -127,7 +128,7 @@ PowerManager.prototype.request = function(resource, state) { ]); if (args['state'] && args.state === PowerScreenState['SCREEN_BRIGHT']) { - console.warn('DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release.'); + privUtils_.warn('DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release.'); } var nativeParam = { @@ -278,7 +279,7 @@ PowerManager.prototype.restoreScreenBrightness = function() { * Turns on the screen. */ PowerManager.prototype.turnScreenOn = function() { - console.warn('DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. Use request() instead.'); + privUtils_.warn('DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. Use request() instead.'); var nativeParam = { }; @@ -295,7 +296,7 @@ PowerManager.prototype.turnScreenOn = function() { * Turns off the screen. */ PowerManager.prototype.turnScreenOff = function() { - console.warn('DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. Use release() instead.'); + privUtils_.warn('DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. Use release() instead.'); var nativeParam = { }; diff --git a/src/push/push_api.js b/src/push/push_api.js index 6e623a66..78d4113e 100644 --- a/src/push/push_api.js +++ b/src/push/push_api.js @@ -17,7 +17,7 @@ var native = new xwalk.utils.NativeManager(extension); var validator = xwalk.utils.validator; var validatorType = xwalk.utils.type; - +var privUtils_ = xwalk.utils; /** * @const @@ -59,7 +59,7 @@ function PushManager() { } PushManager.prototype.registerService = function() { - console.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.'); + privUtils_.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.'); var data = validator.validateArgs(arguments, [ { name: 'appControl', @@ -121,7 +121,7 @@ PushManager.prototype.register = function() { }; PushManager.prototype.unregisterService = function() { - console.warn('DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next release. Use unregister() instead.'); + privUtils_.warn('DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next release. Use unregister() instead.'); var data = validator.validateArgs(arguments, [ { name: 'successCallback', @@ -182,7 +182,7 @@ PushManager.prototype.unregister = function() { }; PushManager.prototype.connectService = function(notificationCallback) { - console.warn('DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. Use connect() instead.'); + privUtils_.warn('DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. Use connect() instead.'); var data = validator.validateArgs(arguments, [ { name: 'notificationCallback', @@ -246,7 +246,7 @@ PushManager.prototype.connect = function(notificationCallback) { }; PushManager.prototype.disconnectService = function() { - console.warn('DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next release. Use disconnect() instead.'); + privUtils_.warn('DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next release. Use disconnect() instead.'); var ret = native.callSync('Push_disconnectService', {}); if (native.isFailure(ret)) { throw native.getErrorObject(ret); diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js index ce4755b5..e09c977d 100644 --- a/src/systeminfo/systeminfo_api.js +++ b/src/systeminfo/systeminfo_api.js @@ -737,7 +737,7 @@ var SystemInfo = function() { }; SystemInfo.prototype.getCapabilities = function() { - console.warn('DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead.'); + privUtils_.warn('DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead.'); var result = native_.callSync('SystemInfo_getCapabilities', {}); if (native_.isFailure(result)) { diff --git a/src/time/time_api.js b/src/time/time_api.js index 95c9d6f7..ba31ab89 100644 --- a/src/time/time_api.js +++ b/src/time/time_api.js @@ -533,7 +533,7 @@ tizen.TZDate.prototype.toString = function() { tizen.TZDate.prototype.getTimezoneAbbreviation = function() { utils_.log('Entered TZDate.getTimezoneAbbreviation'); - console.warn('DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next release.'); + utils_.warn('DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next release.'); var result = native_.callSync('TZDate_getTimezoneAbbreviation', {timezone: String(this._timezoneName), diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js index ca617251..08cf6596 100644 --- a/src/utils/utils_api.js +++ b/src/utils/utils_api.js @@ -5,7 +5,7 @@ //Object xwalk.JSON - guaranteed to not being modified by the application programmer var JSON_ = {stringify: JSON.stringify, parse: JSON.parse}; -Object.freeze(JSON_) +Object.freeze(JSON_); exports.JSON = JSON_; var _enableJsLogs = false; @@ -146,11 +146,9 @@ function Utils() { }); } -Utils.prototype.log = function() { - if (_enableJsLogs) { - console.log.apply(console, arguments); - } -} +Utils.prototype.error = console.error.bind(console); +Utils.prototype.warn = console.warn.bind(console); +Utils.prototype.log = _enableJsLogs ? console.log.bind(console) : function(){}; Utils.prototype.repackFilter = function(filter) { if (filter instanceof tizen.AttributeFilter) { @@ -975,19 +973,19 @@ var NativeManager = function(extension) { // TODO: Remove mockup if WRT implements sendRuntimeMessage // This is temporary mockup! extension.sendRuntimeMessage = extension.sendRuntimeMessage || function() { - console.error('Runtime did not implement extension.sendRuntimeMessage!'); + _console.error('Runtime did not implement extension.sendRuntimeMessage!'); throw new WebAPIException(WebAPIException.UNKNOWN_ERR, 'Runtime did not implement extension.sendRuntimeMessage!'); }; extension.sendRuntimeAsyncMessage = extension.sendRuntimeAsyncMessage || function() { - console.error('Runtime did not implement extension.sendRuntimeAsyncMessage!'); + _console.error('Runtime did not implement extension.sendRuntimeAsyncMessage!'); throw new WebAPIException(WebAPIException.UNKNOWN_ERR, 'Runtime did not implement extension.sendRuntimeAsyncMessage!'); }; extension.sendRuntimeSyncMessage = extension.sendRuntimeSyncMessage || function() { - console.error('Runtime did not implement extension.sendRuntimeSyncMessage!'); + _console.error('Runtime did not implement extension.sendRuntimeSyncMessage!'); throw new WebAPIException(WebAPIException.UNKNOWN_ERR, 'Runtime did not implement extension.sendRuntimeSyncMessage!'); }; @@ -1028,7 +1026,7 @@ var NativeManager = function(extension) { delete msg[this.CALLBACK_ID_KEY]; if (!_type.isFunction(this.callbacks_[id])) { - console.error('Wrong callback identifier. Ignoring message.'); + _console.error('Wrong callback identifier. Ignoring message.'); return; } @@ -1037,8 +1035,8 @@ var NativeManager = function(extension) { try { f(msg); } catch (e) { - console.error('########## exception'); - console.error(e); + _console.error('########## exception'); + _console.error(e); } }, 0); delete this.callbacks_[id]; @@ -1051,7 +1049,7 @@ var NativeManager = function(extension) { delete msg[this.LISTENER_ID_KEY]; if (!_type.isFunction(this.listeners_[id])) { - console.error('Wrong listener identifier. Ignoring message.'); + _console.error('Wrong listener identifier. Ignoring message.'); return; } @@ -1060,15 +1058,15 @@ var NativeManager = function(extension) { try { f(msg); } catch (e) { - console.error('########## exception'); - console.error(e); + _console.error('########## exception'); + _console.error(e); } }, 0); return; } - console.error('Missing callback or listener identifier. Ignoring message.'); + _console.error('Missing callback or listener identifier. Ignoring message.'); }.bind(this)); }; @@ -1174,7 +1172,7 @@ NativeManager.prototype.callIfPossible = function(callback) { * age: 28 * } * }); - * console.log(result); + * _console.log(result); * * To send async method and handle response: * bridge.async({ @@ -1229,7 +1227,7 @@ var NativeBridge = (function (extension, debug) { CallbackManager.prototype = { add: function (/*callbacks, cid?*/) { - if (debug) console.log('bridge.CallbackManager.add'); + if (debug) _console.log('bridge.CallbackManager.add'); var args = Array.prototype.slice.call(arguments); var c = args.shift(); var cid = args.pop(); @@ -1246,11 +1244,11 @@ var NativeBridge = (function (extension, debug) { return cid; }, remove: function (cid) { - if (debug) console.log('bridge.CallbackManager.remove, cid: ' + cid); + if (debug) _console.log('bridge.CallbackManager.remove, cid: ' + cid); if (_collection[cid]) delete _collection[cid]; }, call: function (cid, key, args, keep) { - if (debug) console.log('bridge.CallbackManager.call, cid: '+ cid + ', key: ' + key); + if (debug) _console.log('bridge.CallbackManager.call, cid: '+ cid + ', key: ' + key); var callbacks = _collection[cid]; keep = !!keep; if (callbacks) { @@ -1282,13 +1280,13 @@ var NativeBridge = (function (extension, debug) { ListenerManager.prototype = { add: function (l) { - if (debug) console.log('bridge.ListenerManager.add'); + if (debug) _console.log('bridge.ListenerManager.add'); var id = _next(); _listeners[id] = l; return id; }, resolve: function (id, action, data, keep) { - if (debug) console.log('bridge.ListenerManager.resolve, id: ' + id + ', action: ' + action); + if (debug) _console.log('bridge.ListenerManager.resolve, id: ' + id + ', action: ' + action); keep = !!keep; var l = _listeners[id]; if (l) { @@ -1298,7 +1296,7 @@ var NativeBridge = (function (extension, debug) { return l; }, remove: function (id) { - if (debug) console.log('bridge.ListenerManager.remove, id: ' + id); + if (debug) _console.log('bridge.ListenerManager.remove, id: ' + id); var l = _listeners[id]; if (l) { var cm = Callbacks.getInstance(); @@ -1333,12 +1331,12 @@ var NativeBridge = (function (extension, debug) { })(); var Listener = function () { - if (debug) console.log('bridge: Listener constructor'); + if (debug) _console.log('bridge: Listener constructor'); this.cid = null; }; Listener.prototype = { then: function (c) { - if (debug) console.log('bridge.Listener.then'); + if (debug) _console.log('bridge.Listener.then'); var cm = Callbacks.getInstance(); this.cid = cm.add(c, this.cid); return this; @@ -1352,7 +1350,7 @@ var NativeBridge = (function (extension, debug) { cmd: data.cmd, args: data }); - if (debug) console.log('bridge.sync, json: ' + json); + if (debug) _console.log('bridge.sync, json: ' + json); var result = extension.internal.sendSyncMessage(json); var obj = JSON_.parse(result); if (obj.error) @@ -1366,7 +1364,7 @@ var NativeBridge = (function (extension, debug) { cmd: data.cmd, args: data }); - if (debug) console.log('bridge.async, json: ' + json); + if (debug) _console.log('bridge.async, json: ' + json); setTimeout(function () { extension.postMessage(json); }); @@ -1399,7 +1397,7 @@ var NativeBridge = (function (extension, debug) { *} */ - if (debug) console.log('bridge.setMessageListener, json: ' + json); + if (debug) _console.log('bridge.setMessageListener, json: ' + json); var data = JSON_.parse(json); if (data.cid && data.action) { setTimeout(function() {