Permalink
Browse files

fix for empty objects

  • Loading branch information...
1 parent c3292a7 commit 5cf9c38d45d2efebb47e61e5df6b0aa3df7703da @substack committed Feb 22, 2012
Showing with 8 additions and 6 deletions.
  1. +5 −4 index.js
  2. +3 −2 test/stringify_object.js
View
@@ -135,17 +135,18 @@ exports.stringifyObject = function (op, sep, cl) {
var stream = new Stream ()
, first = true
, ended = false
+ , anyData = false
stream.write = function (data) {
var json = JSON.stringify(data[0]) + ':' + JSON.stringify(data[1])
if(first) { first = false ; stream.emit('data', op + json)}
else stream.emit('data', sep + json)
+ anyData = true
}
stream.end = function (data) {
- if(ended)
- return
+ if(ended) return
ended = true
- if(data)
- stream.write(data)
+ if(data) stream.write(data)
+ if(!anyData) stream.emit('data', op)
stream.emit('data', cl)
stream.emit('end')
@@ -29,7 +29,6 @@ for (var ix = 0; ix < pending; ix++) (function (count) {
stringify,
es.writeArray(function (err, lines) {
it(JSON.parse(lines.join(''))).deepEqual(expected)
-console.log(pending);
if (--pending === 0) {
console.error('PASSED')
}
@@ -42,5 +41,7 @@ console.log(pending);
stringify.write([ key, expected[key] ])
}
- stringify.end()
+ process.nextTick(function () {
+ stringify.end()
+ })
})(ix)

0 comments on commit 5cf9c38

Please sign in to comment.