Order the keys of Dict value to allow comparison with JSON.stringify

This will ensure that the JSON.stringify will dump the keys always in the same
order. Even if the key order is a implementation detail of the browser,
constructing a new Object using always the same order will guarantee a stable
stringification.

issue6045
review33631002
This commit is contained in:
Cédric Krier committed 2016-11-21 21:00:43 +01:00
1 parent eb95cbeeff
commit 1092e979ad
1 file changed
+17
+17
View File
@@ -2392,6 +2392,23 @@
Sao.field.Dict = Sao.class_(Sao.field.Field, {
_default: {},
set: function(record, value) {
if (value) {
// Order keys to allow comparison with stringify
var keys = [];
for (var key in value) {
keys.push(key);
}
keys.sort();
var new_value = {};
for (var index in keys) {
key = keys[index];
new_value[key] = value[key];
}
value = new_value;
}
Sao.field.Dict._super.set.call(this, record, value);
},
get: function(record) {
return (Sao.field.Dict._super.get.call(this, record) ||
this._default);