From 4b3f1c31817b26385ec1a802dd4beffcf88c4caa Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Sat, 22 Jan 2011 21:32:50 +0000 Subject: [PATCH] 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 --- compiler/cpp/src/generate/t_js_generator.cc | 2 +- lib/js/thrift.js | 9 +++++++++ lib/nodejs/lib/thrift/thrift.js | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc index 4aa68116..bbf436dc 100644 --- a/compiler/cpp/src/generate/t_js_generator.cc +++ b/compiler/cpp/src/generate/t_js_generator.cc @@ -1478,7 +1478,7 @@ void t_js_generator::generate_serialize_container(ofstream &out, "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 9b92658d..fbdc809a 100644 --- a/lib/js/thrift.js +++ b/lib/js/thrift.js @@ -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; +} diff --git a/lib/nodejs/lib/thrift/thrift.js b/lib/nodejs/lib/thrift/thrift.js index 73f772b2..aee5a544 100644 --- a/lib/nodejs/lib/thrift/thrift.js +++ b/lib/nodejs/lib/thrift/thrift.js @@ -128,3 +128,7 @@ TApplicationException.prototype.write = function(output){ output.writeFieldStop() output.writeStructEnd() } + +exports.objectLength = function(obj) { + return Object.keys(obj).length; +} -- 2.17.1