skeeto/resurrect-js

Running stringify() a second time after an error produces a strange result

Opened this issue · 2 comments

r = new Resurrect()
var O = {test : function(){console.log("cats")}}
r.stringify(O)
// => Uncaught ResurrectError {message: "Can't serialize functions."...
r.stringify(O)
// => "[]"

I'm just starting out with the library and came across this behavior while playing with it in the console. It's hard (at least at this point) for me to imagine why I'd end up calling this twice on the same object in real code, but this struck me as strange behavior.

Oops, that's definitely a bug. The problem is that Resurrect is leaving
its marker on the object. When there's an exception, it doesn't clean up
after itself, so next time around it sees the marker, assumes the object
has already been seen, and skips it, hence the empty array in the
result. The cleanup should moved into a finally block so that it happens
regardless.

That totally makes sense. Thanks for responding so quickly.