[FIX] rollback default conversion of js Object to py.object (not py.dict) and add default toJSON to all py.object

* Accesses in contexts & domains are object derefs, so using dicts was
  dumb

* But objects still need to round-trip through in case of e.g. o2m
  commands in contexts, so py.object needs a toJSON (or a special
  object kind needs to be added, specifically for round-tripping
  objects through)

bzr revid: xmo@openerp.com-20121203122312-gc499mujf4l0nuz7
This commit is contained in:
Xavier Morel
2012-12-03 13:23:12 +01:00
parent 54ea7670d3
commit f9670e67a2
+15 -2
View File
@@ -393,7 +393,13 @@ var py = {};
switch(val.constructor) {
case Object:
return py.dict.fromJSON(val);
var out = py.PY_call(py.object);
for(var k in val) {
if (val.hasOwnProperty(k)) {
out[k] = val[k];
}
}
return out;
case Array:
return py.list.fromJSON(val);
}
@@ -756,7 +762,14 @@ var py = {};
// Conversion
toJSON: function () {
throw new Error(this.constructor.name + ' can not be converted to JSON');
var out = {};
for(var k in this) {
if (this.hasOwnProperty(k) && !/^__/.test(k)) {
var val = this[k];
out[k] = val.toJSON ? val.toJSON() : val;
}
}
return out;
}
});
var NoneType = py.type('NoneType', null, {