THRIFT-1043 Fix how the length of a map is calculated
Patch: Wade Simmons


git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1062278 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc
index 4aa6811..bbf436d 100644
--- a/compiler/cpp/src/generate/t_js_generator.cc
+++ b/compiler/cpp/src/generate/t_js_generator.cc
@@ -1478,7 +1478,7 @@
         "output.writeMapBegin(" <<
         type_to_enum(((t_map*)ttype)->get_key_type()) << ", " <<
         type_to_enum(((t_map*)ttype)->get_val_type()) << ", " <<
-        prefix << ".length)" << endl;
+        "Thrift.objectLength(" << prefix << "))" << endl;
   } else if (ttype->is_set()) {
     indent(out) <<
       "output.writeSetBegin(" <<
diff --git a/lib/js/thrift.js b/lib/js/thrift.js
index 9b92658..fbdc809 100644
--- a/lib/js/thrift.js
+++ b/lib/js/thrift.js
@@ -713,5 +713,14 @@
    
 }
 
+Thrift.objectLength = function(obj) {
+  var length = 0;
+  for (k in obj) {
+    if (obj.hasOwnProperty(k)) {
+      length++;
+    }
+  }
+  return length;
+}
 
 
diff --git a/lib/nodejs/lib/thrift/thrift.js b/lib/nodejs/lib/thrift/thrift.js
index 73f772b..aee5a54 100644
--- a/lib/nodejs/lib/thrift/thrift.js
+++ b/lib/nodejs/lib/thrift/thrift.js
@@ -128,3 +128,7 @@
   output.writeFieldStop()
   output.writeStructEnd()
 }
+
+exports.objectLength = function(obj) {
+  return Object.keys(obj).length;
+}