diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc index 4aa68116b..bbf436dc3 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 9b92658d0..fbdc809a3 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 73f772b22..aee5a5442 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; +}