Permalink
Browse files

more work on support cyclic objects

  • Loading branch information...
1 parent f4e8797 commit f27afbf196117e448a0facf5d63fd34444467bcc @shakty shakty committed Jun 10, 2012
Showing with 11 additions and 24 deletions.
  1. +3 −15 external/cycle.js
  2. +8 −9 test/test.io.js
View
@@ -114,7 +114,7 @@ if (typeof JSON.retrocycle !== 'function') {
// var s = '[{"$ref":"$"}]';
// return JSON.retrocycle(JSON.parse(s));
// produces an array containing a single element which is the array itself.
-
+
var px =
/^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;
@@ -124,7 +124,7 @@ if (typeof JSON.retrocycle !== 'function') {
// properties. When it finds one that has a value that is a path, then it
// replaces the $ref object with a reference to the value that is found by
// the path.
-
+
var i, item, name, path;
if (value && typeof value === 'object') {
@@ -134,9 +134,6 @@ if (typeof JSON.retrocycle !== 'function') {
if (item && typeof item === 'object') {
path = item.$ref;
if (typeof path === 'string' && px.test(path)) {
-// console.log('IH: ' + path)
-// var o = console.log(eval(path));
-// console.log(o);
value[i] = eval(path);
} else {
rez(item);
@@ -145,20 +142,12 @@ if (typeof JSON.retrocycle !== 'function') {
}
} else {
for (name in value) {
-
-// console.log('name')
-// console.log(name);
if (typeof value[name] === 'object') {
item = value[name];
if (item) {
-// console.log('item')
-// console.log(item)
path = item.$ref;
if (typeof path === 'string' && px.test(path)) {
- //console.log('UH: ' + path)
-// console.log(path);
- var o = console.log(eval(path));
- value[name] = eval(path);//eval(path);
+ value[name] = eval(path);
} else {
rez(item);
}
@@ -167,7 +156,6 @@ if (typeof JSON.retrocycle !== 'function') {
}
}
}
-
}($));
return $;
};
View
@@ -87,15 +87,15 @@ var base_cycle = {
};
var c1 = base_cycle;
-var c2 = JSUS.clone(base_cycle);
+var c2 = base_cycle;
-c1.aa = base_cycle;
+// TODO: referencing the whole object does not work.
+//c1.aa = base_cycle;
c2.ac = base_cycle.c;
+c2.aa = base_cycle.b;
-var cycles = [c1];
+var cycles = [c1, c2];
-//console.log(cycles);
-//console.log(Object.prototype.toString.apply(c1.aa))
var nitems = hashable.length + not_hashable.length;
var testcase = null;
var tmp = null;
@@ -155,7 +155,6 @@ var testSaveLoad = function(items) {
});
};
-
describe('NDDB io operations.', function(){
describe('Cycle / Decycle.', function(){
@@ -172,9 +171,9 @@ describe('NDDB io operations.', function(){
// testSaveLoad(weirdos);
// });
-// describe('Cycles items', function(){
-// testSaveLoad(cycles);
-// });
+ describe('Cycles items', function(){
+ testSaveLoad(cycles);
+ });
});

0 comments on commit f27afbf

Please sign in to comment.