[Pkg-javascript-commits] [node-jsonstream] 20/214: fix for empty objects

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 12:58:33 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-jsonstream.

commit 5cf9c38d45d2efebb47e61e5df6b0aa3df7703da
Author: James Halliday <mail at substack.net>
Date:   Wed Feb 22 11:29:12 2012 -0800

    fix for empty objects
---
 index.js                 | 9 +++++----
 test/stringify_object.js | 5 +++--
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/index.js b/index.js
index 92144f3..96321ae 100644
--- a/index.js
+++ b/index.js
@@ -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')
diff --git a/test/stringify_object.js b/test/stringify_object.js
index cb727b0..9490115 100644
--- a/test/stringify_object.js
+++ b/test/stringify_object.js
@@ -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)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jsonstream.git



More information about the Pkg-javascript-commits mailing list