Commit afccedba authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Cédric Le Ninivin

jio.util.stringify: Add support for undefined values

`jIO.util.stringify` was raising if the value of an object was undefined, this changes fix it and provides the same behaviour as the standard `JSON.stringify`

/reviewed-on nexedi/jio!41
parent d177be73
...@@ -124,6 +124,9 @@ ...@@ -124,6 +124,9 @@
i, i,
value, value,
result_list; result_list;
if (obj === undefined) {
return undefined;
}
if (obj.constructor === Object) { if (obj.constructor === Object) {
key_list = Object.keys(obj).sort(); key_list = Object.keys(obj).sort();
result_list = []; result_list = [];
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
'"2006-01-02T15:04:05.000Z"'); '"2006-01-02T15:04:05.000Z"');
equal(str({ x: 5, y: 6, z: 7 }), '{"x":5,"y":6,"z":7}'); equal(str({ x: 5, y: 6, z: 7 }), '{"x":5,"y":6,"z":7}');
equal(str({ z: 7, y: 6, x: 5 }), '{"x":5,"y":6,"z":7}'); equal(str({ z: 7, y: 6, x: 5 }), '{"x":5,"y":6,"z":7}');
equal(str({ z: "", y: undefined, x: 5 }), '{"x":5,"z":""}');
equal(str(Object.create(null, { x: { value: 'x', enumerable: false }, equal(str(Object.create(null, { x: { value: 'x', enumerable: false },
y: { value: 'y', enumerable: true } })), y: { value: 'y', enumerable: true } })),
'{"y":"y"}'); '{"y":"y"}');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment