diff options
Diffstat (limited to 'addons/web/static/src/js/core')
| -rw-r--r-- | addons/web/static/src/js/core/abstract_storage_service.js | 11 | ||||
| -rw-r--r-- | addons/web/static/src/js/core/py_utils.js | 10 | ||||
| -rw-r--r-- | addons/web/static/src/js/core/utils.js | 12 |
3 files changed, 31 insertions, 2 deletions
diff --git a/addons/web/static/src/js/core/abstract_storage_service.js b/addons/web/static/src/js/core/abstract_storage_service.js index 34dd24b2be6..ef828b5dd5c 100644 --- a/addons/web/static/src/js/core/abstract_storage_service.js +++ b/addons/web/static/src/js/core/abstract_storage_service.js @@ -13,6 +13,17 @@ var AbstractStorageService = AbstractService.extend({ // this abstraction storage: null, + /** + * @override + */ + destroy: function () { + // storage can be permanent or transient, destroy transient ones + if ((this.storage || {}).destroy) { + this.storage.destroy(); + } + this._super.apply(this, arguments); + }, + //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- diff --git a/addons/web/static/src/js/core/py_utils.js b/addons/web/static/src/js/core/py_utils.js index 9bcd66864e5..296ab5c3089 100644 --- a/addons/web/static/src/js/core/py_utils.js +++ b/addons/web/static/src/js/core/py_utils.js @@ -415,7 +415,15 @@ function _formatAST(ast, lbp) { case "(number)": return String(ast.value); case "(string)": - return "'" + ast.value + "'"; + // ast.value is a string that may contain a mix of single and double quotes. + // But we need to return a string that represents the string ast.value. + // We use for that JSON.stringify. It will return a string with quotes correctly + // escaped. For instance, for x = `""` JSON.stringify(x) is `"\"\""`. + // But this means that if we pass several times here, escapes will be + // done again and again, leading to a profusion of backslashes that we don't want. + // For fun consider y = `\\` and y = JSON.stringify(y). + // This is why we first deescape particular characters in ast.value. + return JSON.stringify(ast.value.replace(/(\\(['"\\]))/g,"\$2")); case "(constant)": return ast.value; case "(name)": diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js index cf64de72eef..44e09933a25 100644 --- a/addons/web/static/src/js/core/utils.js +++ b/addons/web/static/src/js/core/utils.js @@ -303,7 +303,17 @@ var utils = { var d2 = Math.pow(10, decimals); var val = _t('kMGTPE'); var symbol = ''; - for (var i = val.length - 1 ; i > 0 ; i--) { + var numberMagnitude = number.toExponential().split('e')[1]; + // the case numberMagnitude >= 21 corresponds to a number + // better expressed in the scientific format. + if (numberMagnitude >= 21) { + // we do not use number.toExponential(decimals) because we want to + // avoid the possible useless O decimals: 1e.+24 prefered to 1.0e+24 + number = Math.round(number * Math.pow(10, decimals - numberMagnitude)) / d2; + // formatterCallback seems useless here. + return number + 'e' + numberMagnitude; + } + for (var i = val.length; i > 0 ; i--) { var s = Math.pow(10, i * 3); if (s <= number / Math.pow(10, minDigits - 1)) { number = Math.round(number * d2 / s) / d2; |
