Skip to content

Commit

Permalink
avoid infinite recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Jun 7, 2013
1 parent b027a59 commit a96158a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/index.js
Expand Up @@ -137,8 +137,12 @@ Cow.prototype.finish = function Cow_finish() {
* replace those references with an extra pass
*/
function replaceProxies(obj) {
if (typeof obj !== 'object')
if (!obj || typeof obj !== 'object')
return obj;
// avoid cycles
if (seen.has(obj))
return;
seen.add(obj);
var copied = proxyCopies.get(obj);
if (copied)
return copied;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"description": "copy on write deep, cyclic js objects",
"keywords": ["cow", "copy on write", "copy-on-write", "copy"],
"main": "./index",
"version": "0.2.0",
"version": "0.2.1",
"maintainers": [
"Arpad Borsos <arpad.borsos@googlemail.com> (http://swatinem.de)"
],
Expand Down
1 change: 1 addition & 0 deletions test/cow.js
Expand Up @@ -131,6 +131,7 @@ describe('Cow', function () {
var p = c.proxy;
p.child.new = p.child;
p.child.new2 = {child: p.child, child2: {}};
p.child.new2.child2.child2 = p.child.new2.child2;
var f = c.finish();
f.child.should.not.equal(o.child);
f.child.new.should.equal(f.child);
Expand Down

0 comments on commit a96158a

Please sign in to comment.