Handle circular references gracefully #26

Merged
merged 2 commits into from Aug 5, 2011

Projects

None yet

4 participants

Contributor
gilbert commented Jul 31, 2011

Addresses issue #25

@michaelficarra michaelficarra commented on the diff Jul 31, 2011
console.js
try {
type = ({}).toString.call(o);
} catch (e) { // only happens when typeof is protected (...randomly)
type = '[object Object]';
}
-
- if (type == '[object String]') {
+
+ // check for circular references
+ var isCircular = false;
+ for (var vi = 0; vi < visited.length; vi++) {
michaelficarra
michaelficarra Jul 31, 2011

cache the length here

@michaelficarra michaelficarra commented on an outdated diff Jul 31, 2011
try {
type = ({}).toString.call(o);
} catch (e) { // only happens when typeof is protected (...randomly)
type = '[object Object]';
}
-
- if (type == '[object String]') {
+
+ // check for circular references
+ var isCircular = false;
+ for (var vi = 0; vi < visited.length; vi++) {
+ isCircular = isCircular || o === visited[vi];
michaelficarra
michaelficarra Jul 31, 2011
if(isCircular |= o === visited[vi]) break;
michaelficarra
michaelficarra Jul 31, 2011

or:

if(o !== visited[vi]) continue;
isCircular = true;
break;

which is a little more readable and probably faster, since it avoids a bunch of assignments

@remy remy merged commit fd2f086 into remy:master Aug 5, 2011

Hi Rem, would it be hard to merge this into http://jsconsole.com/remote.js ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment