Author: roger
Date: Sat Jan 22 21:32:50 2011
New Revision: 1062278

URL: http://svn.apache.org/viewvc?rev=1062278&view=rev
Log:
THRIFT-1043 Fix how the length of a map is calculated
Patch: Wade Simmons

Modified:
    thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc
    thrift/trunk/lib/js/thrift.js
    thrift/trunk/lib/nodejs/lib/thrift/thrift.js

Modified: thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc
URL: 
http://svn.apache.org/viewvc/thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc?rev=1062278&r1=1062277&r2=1062278&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc Sat Jan 22 
21:32:50 2011
@@ -1478,7 +1478,7 @@ void t_js_generator::generate_serialize_
         "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(" <<

Modified: thrift/trunk/lib/js/thrift.js
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/js/thrift.js?rev=1062278&r1=1062277&r2=1062278&view=diff
==============================================================================
--- thrift/trunk/lib/js/thrift.js (original)
+++ thrift/trunk/lib/js/thrift.js Sat Jan 22 21:32:50 2011
@@ -713,5 +713,14 @@ Thrift.Protocol.prototype = {
    
 }
 
+Thrift.objectLength = function(obj) {
+  var length = 0;
+  for (k in obj) {
+    if (obj.hasOwnProperty(k)) {
+      length++;
+    }
+  }
+  return length;
+}
 
 

Modified: thrift/trunk/lib/nodejs/lib/thrift/thrift.js
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/nodejs/lib/thrift/thrift.js?rev=1062278&r1=1062277&r2=1062278&view=diff
==============================================================================
--- thrift/trunk/lib/nodejs/lib/thrift/thrift.js (original)
+++ thrift/trunk/lib/nodejs/lib/thrift/thrift.js Sat Jan 22 21:32:50 2011
@@ -128,3 +128,7 @@ TApplicationException.prototype.write = 
   output.writeFieldStop()
   output.writeStructEnd()
 }
+
+exports.objectLength = function(obj) {
+  return Object.keys(obj).length;
+}


Reply via email to